Documentation
¶
Index ¶
- func DefaultProxyTransport() *http.Transport
- func NewAnthropicProxyHandler(upstream *url.URL, transport http.RoundTripper) http.Handler
- func NewAuthSwapTransport(next http.RoundTripper, token string) http.RoundTripper
- func NewHealthzHandler() http.Handler
- func NewLoggingHandler(next http.Handler) http.Handler
- func NewModelRouter(routes []ModelRoute, defaultHandler http.Handler) http.Handler
- func NewSetLoglevelHandler() http.Handler
- type ModelRoute
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultProxyTransport ¶ added in v0.3.0
DefaultProxyTransport returns an http.Transport with explicit timeouts suitable for upstream LLM API calls. Long ResponseHeaderTimeout because LLM completions can take 30s+ for the first byte (SSE); short Dial because connections are local-network or quick HTTPS to api.anthropic.com.
func NewAnthropicProxyHandler ¶ added in v0.3.0
NewAnthropicProxyHandler returns an HTTP handler that reverse-proxies every incoming request to upstream (typically https://api.anthropic.com).
The Authorization header passes through unchanged — this is what lets Claude Code's subscription OAuth bearer travel through the router to Anthropic without the router ever holding it. No body parsing, no model-based routing: that's task 3. v1 of task 2 = single upstream, verbatim forward.
Upstream errors (connection refused, 5xx before body, etc.) are logged server-side with the full error string for debugging, but the client sees only a generic "502 Bad Gateway / upstream unavailable" — the internal error details (IPs, TLS handshake failures, connection strings) are not leaked.
If transport is nil, DefaultProxyTransport is used.
func NewAuthSwapTransport ¶ added in v0.4.0
func NewAuthSwapTransport(next http.RoundTripper, token string) http.RoundTripper
NewAuthSwapTransport wraps next so each outbound request has its Authorization header replaced with `Bearer <token>`. Used by the model router to swap the client's subscription OAuth bearer for a per-provider API token (MiniMax, Ollama, vLLM) before forwarding.
If token is empty, the wrapper is a no-op and returns next.
func NewHealthzHandler ¶
NewHealthzHandler returns a handler that responds 200 with body "OK".
func NewLoggingHandler ¶ added in v0.2.0
NewLoggingHandler wraps next and emits one glog line per request: `[req] METHOD path -> STATUS` at V(1). Used to make router activity visible during local testing without depending on the upstream provider's own logging.
func NewModelRouter ¶ added in v0.4.0
func NewModelRouter(routes []ModelRoute, defaultHandler http.Handler) http.Handler
NewModelRouter returns an HTTP handler that body-parses each request's JSON `model` field and dispatches to the first matching ModelRoute. Unmatched models (and non-JSON / no-model requests) fall through to defaultHandler. The body is fully read and replayed for the downstream handler — fine for /v1/messages JSON payloads (typically <100 KB); not suitable for unbounded upload bodies.
func NewSetLoglevelHandler ¶
NewSetLoglevelHandler returns a no-op handler for /setloglevel/{level}.
v1 skeleton: slog level is static; nothing to switch at runtime. The endpoint exists so the canonical-admin-endpoints check passes and so future runtime log-level wiring has a known URL. Returns 200 with body "noop" so callers can distinguish from "endpoint missing".
Types ¶
type ModelRoute ¶ added in v0.4.0
ModelRoute pairs a glob pattern (filepath.Match syntax) with the handler to invoke when an incoming request's `model` field matches.