Model gateway
How the worker's built-in gateway lets every agent use add-on models — API translation, per-session tokens, fallback inside a turn, and what is lost.
Agents speak their own API: Claude Code the Anthropic Messages API, Codex the OpenAI Responses API, Gemini CLI the Gemini API, OpenCode and Aider OpenAI chat completions. Add-on providers offer OpenAI-compatible chat completions. The worker's model gateway sits in between.
How agents are pointed at it
| Agent | How |
|---|---|
| Claude Code | ANTHROPIC_BASE_URL |
| Codex | A custom model_provider (Responses API) |
| Gemini CLI | GOOGLE_GEMINI_BASE_URL, API-key auth, its own settings home |
| OpenCode | OPENCODE_CONFIG_CONTENT |
| Aider | OPENAI_API_BASE |
The agent's own tools, prompts and settings are unchanged.
Security
It listens on 127.0.0.1 only, on a random port, and each agent session gets its own token.
Translation
Requests and streamed answers are translated both ways, including tool calls and tool results. Codex's free-form
tools such as apply_patch become functions with one input argument.
Fallback inside a turn
A request goes to the first add-on model that answers. A limit (429), an outage (5xx, timeout, connection error) or
a refusal (4xx: unknown model, no tool support) moves it to the next model, as long as nothing has been streamed
yet. If every add-on model is limited, the agent gets a limit error in its own format with the soonest known
Retry-After.
Order
Providers are used in list order. List the models to use per provider (the first is preferred); without a list, every model the provider lists is used.
What is not available through it
Thinking/reasoning blocks are not sent upstream, prompt caching does not apply, and hosted server tools (web search) are not available. Azure OpenAI, Bedrock and Vertex are not served through the gateway; agents use them directly.
Verified
All five agents were run for real through the gateway (Claude Code 2.1.281, Codex 0.157.1, Gemini CLI 0.61.0, OpenCode 1.18.32, Aider 0.86.2) against a fake OpenAI-compatible model that asked each to create a file with its own tools.