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, and OpenCode, Aider, Copilot CLI, Qwen Code, Kilo Code, Pi, Crush and Trae Agent 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). Also for OpenAI-compatible providers, Ollama and OpenRouter |
| Gemini CLI | GOOGLE_GEMINI_BASE_URL, API-key auth, its own settings home |
| OpenCode | OPENCODE_CONFIG_CONTENT. Also for OpenAI-compatible providers and Ollama |
| Aider | OPENAI_API_BASE |
| GitHub Copilot CLI | COPILOT_PROVIDER_BASE_URL (its custom-provider mode; no GitHub login needed) |
| Qwen Code | --auth-type openai with OPENAI_BASE_URL |
| Kilo Code | KILO_CONFIG_CONTENT |
| Pi | A models.json in an agent folder of its own (PI_CODING_AGENT_DIR) |
| Crush | A crush.json of its own (CRUSH_GLOBAL_CONFIG) |
| Trae Agent | A configuration file with its openrouter provider and a base URL |
The agent's own tools, prompts and settings are unchanged.
Cursor Agent, Kiro CLI, Kimi Code, Grok CLI, Amp, Factory Droid, Auggie, Cline, Continue CLI, Qoder CLI, CodeBuddy Code and Mistral Vibe only talk to their vendor's service and cannot use the gateway. When one of them reaches its limit, the task moves to another agent.
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
Eleven 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, Copilot CLI 1.0.92, Qwen Code 0.25.0, Kilo Code 7.8.3, Pi 0.73.1, Crush 0.97.1, Trae Agent 0.1.0) against a fake OpenAI-compatible model that asked each to create a file with its own tools.