How it works
The proxy
How the /v1/* pass-through streams, logs, and transforms requests.
The proxy is the /v1/* pass-through that clients connect to. It forwards OpenAI and Anthropic calls to the selected backend (or a direct upstream) while logging every exchange.
Streaming and token counting
- Streaming is preserved. SSE chunks are written to the client as they arrive — never buffered and flushed at the end.
- Token counts are scraped in flight. A
tee'd scan reads the finalusagechunk (OpenAI flatprompt_tokens/completion_tokens, or Anthropic nestedinput_tokens/output_tokens) without consuming the body before forwarding. - One row per completed request. A
requestsrow represents a finished exchange, not an attempt. If the client disconnects mid-stream, the row is still enqueued with whatever usage was captured.
OpenAI and Anthropic compatibility
The proxy understands both request shapes:
- OpenAI —
/v1/chat/completions, flatusage. - Anthropic —
/v1/messages,/v1/messages/count_tokens, nestedmessage.usage,message_stopstream terminator.
Cost estimates
Request cost is estimated from upstream usage counters using a startup-cached models.dev pricing catalog. Unknown or unavailable pricing yields a null cost rather than a guessed value.
Transform pipeline
POST /v1/* requests pass through an ordered transform pipeline between auth and forwarding. The body is parsed once when needed and re-serialized only if mutated:
- API key allow-list check
- Routing rule evaluation
- Model alias resolution
- System-prompt injection
- Request size limits
Routing rules are ordered and first-match-wins. See Request logging for what is captured afterwards.
Last updated on