server

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package server wires the HTTP layer: routes, auth, upstream proxying with streaming, and request logging. The panel API lives in package api.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyFromContext added in v1.1.0

func APIKeyFromContext(ctx context.Context) *store.APIKey

APIKeyFromContext returns the authenticated API key placed by clientAuth, or nil if the request was allowed through without a key (RequireAPIKey=false).

func InvalidateKeyCache added in v1.1.0

func InvalidateKeyCache()

InvalidateKeyCache drops all cached entries (call after create/update/delete).

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the top-level HTTP server. It owns the config, store, and the underlying *http.Server so it can be shut down cleanly.

func New

func New(cfg *config.Config, st *store.Store) *Server

New constructs a Server. The store may be nil if request logging is disabled.

func (*Server) CountTokens

func (s *Server) CountTokens() http.HandlerFunc

CountTokens handles POST /v1/messages/count_tokens with a rough estimate (~4 chars/token), which is all Claude Code uses it for.

func (*Server) Handler

func (s *Server) Handler(panelAssets http.FileSystem, panelMux http.Handler) http.Handler

Handler returns the root http.Handler wiring all routes. panelAssets serves the embedded SPA (nil = no embedded assets, e.g. dev mode).

func (*Server) OpenAIProxy added in v1.1.1

func (s *Server) OpenAIProxy() http.HandlerFunc

OpenAIProxy handles POST /v1/chat/completions. Unlike Proxy, this endpoint accepts and returns OpenAI wire format, so OpenAI-compatible SDKs can point their base URL at opencode-cc directly.

func (*Server) Proxy

func (s *Server) Proxy() http.HandlerFunc

Proxy handles POST /v1/messages. Native Anthropic-capable target models go straight to the upstream Messages API; all other models are translated to OpenAI Chat Completions and converted back.

func (*Server) ResponsesProxy added in v1.2.0

func (s *Server) ResponsesProxy() http.HandlerFunc

ResponsesProxy handles POST /v1/responses for Codex and other Responses API clients. Anthropic-native target models are translated through the upstream Messages API; other models use OpenAI Chat Completions translation.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully stops the server.

func (*Server) Start

func (s *Server) Start(handler http.Handler) error

Start begins serving. It blocks until Shutdown is called.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL