Integration Guide

CodeRouter exposes an OpenAI-compatible endpoint (/v1/chat/completions), an OpenAI Responses endpoint (/v1/responses, for Codex CLI) and an Anthropic-compatible endpoint (/v1/messages). Every major coding agent talks one of these protocols — usually you only need to override one base-URL env var. Below is the per-agent recipe with the gotchas we've hit in production.

Claude Code

Anthropic's official CLI · Anthropic protocol

Claude Code v2.x speaks the Anthropic Messages API. Point it at https://www.coderouter.io (Claude Code adds /v1/messages itself) and use auto as the model.

One-line setup

$ in your shell
curl -fsSL https://www.coderouter.io/setup.sh | bash -s -- cr_YOUR_KEY_HERE
claude

The script adds the variables below to the env block of ~/.claude/settings.json and leaves your other settings alone. It backs up the old file first, checks the key with CodeRouter (no model call), prints exactly what it changed and warns if ANTHROPIC_API_KEY is set in your shell. It needs python3 or node (macOS and Linux). Undo with curl -fsSL https://www.coderouter.io/setup.sh | bash -s -- --uninstall. The API Keys page shows the command with your key filled in.

Put the key in ANTHROPIC_AUTH_TOKEN:Claude Code sends ANTHROPIC_AUTH_TOKEN as Authorization: Bearer and uses it ahead of ANTHROPIC_API_KEY and your Claude login, with no approval prompt. ANTHROPIC_API_KEY goes in the x-api-key header and, in interactive mode, is used only after you approve it once (a key you declined earlier is ignored without asking, which leaves you on your Claude subscription). If ANTHROPIC_API_KEY is also set, for example an Anthropic key in your shell profile, Claude Code can send it too; CodeRouter uses your cr_ key either way, but run unset ANTHROPIC_API_KEY to avoid confusion.

Or: env vars for one session

$ in your shell
export ANTHROPIC_BASE_URL=https://www.coderouter.io
export ANTHROPIC_AUTH_TOKEN=cr_YOUR_KEY_HERE
export ANTHROPIC_MODEL=auto
export ANTHROPIC_DEFAULT_OPUS_MODEL=auto
export ANTHROPIC_DEFAULT_SONNET_MODEL=auto
export ANTHROPIC_DEFAULT_HAIKU_MODEL=auto

# v2.x experimental beta features can break third-party gateways.
# This env disables them; harmless to leave on permanently.
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1

claude

Or by hand — ~/.claude/settings.json

~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://www.coderouter.io",
    "ANTHROPIC_AUTH_TOKEN": "cr_YOUR_KEY_HERE",
    "ANTHROPIC_MODEL": "auto",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "auto",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "auto",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "auto",
    "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
  }
}

Verify it's routing through us

After launch, the Claude Code header should show API Usage Billing — not Claude Max. If you still see Claude Max, your Claude login is the credential in use: run /status to see which one Claude Code picked, then log out and start again:

/logout               # inside Claude Code
claude auth logout    # or from your shell
# then start claude again (from a shell that has the variables, if you exported them)
Older versions (v2.1.x):If you can't add custom model names via /model command, pass --model auto on the command line: claude --model auto. Or upgrade with npm i -g @anthropic-ai/claude-code@latest.

Codex CLI

OpenAI's CLI · Responses API

Codex CLI speaks the OpenAI Responses API. CodeRouter serves it at https://www.coderouter.io/api/v1/responses: add CodeRouter as a model provider in Codex's config with wire_api = "responses" and use auto as the model.

~/.codex/config.toml

~/.codex/config.toml
model = "auto"
model_provider = "coderouter"

[model_providers.coderouter]
name = "CodeRouter"
base_url = "https://www.coderouter.io/api/v1"
env_key = "CODEROUTER_API_KEY"
wire_api = "responses"

Your key

export CODEROUTER_API_KEY=cr_YOUR_KEY_HERE   # add it to ~/.zshrc or ~/.bashrc to keep it
codex
How Codex sessions are routed:Codex calls tools in a loop, so its sessions are routed as coding-agent sessions. Every response carries X-CodeRouter-Model with the model that served it. In smart routing (the default) a model name in the config is treated as auto; in Direct mode, set model to a model ID from the models page to use that model.
What isn't supported yet:Requests are stateless: Codex's default (store = false, the full conversation in every request) works, previous_response_id is accepted but ignored, and retrieving or deleting stored responses returns 501. Function tools, such as Codex's shell and update_plan, are passed to the model; built-in tools (web search, file search) and custom freeform tools are not. If your Codex version sends apply_patch as a custom tool, the model doesn't see that tool and can only edit files through shell. If something doesn't work, email support@coderouter.io with your Codex version and the error.

Cursor

Cursor IDE · OpenAI-compatible protocol

Cursor whitelists model names by string — you must add auto as a custom model before it appears in the picker. Setup is UI-only, no env vars.

  1. Open Cursor, press Cmd+Shift+P (or Ctrl+Shift+P) → type "Cursor Settings"
  2. Click Models in the left sidebar
  3. Find the OpenAI API Key section, toggle "Override OpenAI Base URL" ON, paste:
    • URL: https://www.coderouter.io/api/v1
    • Key: cr_YOUR_KEY_HERE
  4. Click Verify — must show ✓ green
  5. Scroll up to Models, click + Add custom model, type auto
  6. Tick the auto checkbox to enable it
  7. In the chat model dropdown (top right of chat), pick auto
Composer + Cmd+K work too:Cursor uses the same model setting for chat, Composer, and inline edits. Once auto is enabled, every Cursor feature routes through us.
Verify failing with "invalid model"?Cursor tests with its default model first — that's fine, the check only confirms auth. After you add auto as a custom model, real requests work.

Aider

CLI · architect mode · OpenAI-compatible protocol

Aider has a hardcoded model whitelist. The openai/ prefix bypasses the validator and routes through whatever endpoint OPENAI_API_BASE points to.

Env vars + CLI

export OPENAI_API_BASE=https://www.coderouter.io/api/v1
export OPENAI_API_KEY=cr_YOUR_KEY_HERE

# Single-model mode
aider --model openai/auto

# Architect mode — the planning call and the edit call
# are each routed like any other request
aider --model openai/auto --architect

Persistent — ~/.aider.conf.yml

~/.aider.conf.yml
model: openai/auto
openai-api-base: https://www.coderouter.io/api/v1
openai-api-key: cr_YOUR_KEY_HERE
# Direct mode only: pin the editor model for architect mode
# (smart routing routes every request; explicit model names are ignored)
# editor-model: openai/deepseek-chat
How architect mode is routed:Aider in architect mode makes two calls per turn, one planning and one applying the edits. Each goes through routing like any other request: it starts on the cheapest model that can handle it (Claude Haiku 5.5, then Kimi K2.6, Claude Sonnet 5.5, Claude Opus 5.5) and moves up only when tests or errors show a failure.

Cline

VS Code agent extension · OpenAI-compatible protocol

Cline (formerly Claude Dev) supports custom OpenAI-compatible endpoints out of the box. Configure via the extension settings panel:

  1. VS Code → install Cline extension
  2. Open the Cline panel → click the Settings (gear) icon
  3. API Provider: OpenAI Compatible
  4. Base URL: https://www.coderouter.io/api/v1
  5. API Key: cr_YOUR_KEY_HERE
  6. Model ID: auto

Or via settings.json

{
  "cline.apiProvider": "openai",
  "cline.openAiBaseUrl": "https://www.coderouter.io/api/v1",
  "cline.openAiApiKey": "cr_YOUR_KEY_HERE",
  "cline.openAiModelId": "auto"
}

Continue.dev

VS Code + JetBrains extension · OpenAI-compatible protocol

Continue uses ~/.continue/config.json for provider config. Add two entries: one for chat (using auto) and one for tab autocomplete (pinned to a fast model).

~/.continue/config.json
{
  "models": [
    {
"title": "CodeRouter (auto)",
"provider": "openai",
"model": "auto",
"apiBase": "https://www.coderouter.io/api/v1",
"apiKey": "cr_YOUR_KEY_HERE"
    }
  ],
  "tabAutocompleteModel": {
    "title": "CodeRouter Tab",
    "provider": "openai",
    "model": "gpt-5-mini",
    "apiBase": "https://www.coderouter.io/api/v1",
    "apiKey": "cr_YOUR_KEY_HERE"
  }
}
Don't use auto for tab autocomplete:Tab autocomplete fires on every keystroke. Routing decisions add ~50ms of overhead — pin tab to gpt-5-mini directly for sub-100ms first token. Use auto only for chat / agent calls.

OpenClaw

Open-source CLI agent · OpenAI-compatible protocol

OpenClaw uses ~/.openclaw/openclaw.json for provider configuration. The fastest setup uses our script with --openclaw:

One-line setup script

curl -fsSL https://www.coderouter.io/setup.sh | bash -s -- --openclaw cr_YOUR_KEY_HERE

Manual — ~/.openclaw/openclaw.json

{
  "models": {
    "providers": {
"coderouter": {
  "baseUrl": "https://www.coderouter.io/api/v1",
  "apiKey": "cr_YOUR_KEY_HERE",
  "api": "openai-completions",
  "models": [{ "id": "auto", "name": "CodeRouter Auto" }]
}
    }
  },
  "agents": {
    "defaults": {
"model": { "primary": "coderouter/auto" }
    }
  }
}

GitHub Copilot

via LiteLLM gateway · indirect setup

GitHub Copilot doesn't support custom endpoints natively. The proven pattern is to run LiteLLM as a local proxy that translates Copilot's requests into our OpenAI-compatible format.

  1. Install LiteLLM: pip install "litellm[proxy]"
  2. Create a config pointing LiteLLM at CodeRouter (single openai-compatible model named auto)
  3. Run litellm --config config.yaml --port 4000
  4. Point Copilot at http://localhost:4000 via VSCode setting github.copilot.advanced.debug.overrideProxyUrl

Detailed walkthrough in our blog: Cut Copilot bills with CodeRouter.

OpenAI SDK (Python / Node / Go)

Drop-in replacement for any openai client

Just override base_url and api_key. Set model="auto" to enable phase routing.

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://www.coderouter.io/api/v1",
    api_key="cr_YOUR_KEY_HERE",
)
raw = client.chat.completions.with_raw_response.create(
    model="auto",
    messages=[{"role": "user", "content": "Refactor this function"}],
)
resp = raw.parse()  # the usual ChatCompletion
print(resp.choices[0].message.content)
# Which model answered and what it cost, from the response headers:
print(raw.headers.get("x-coderouter-model"))  # model that served it
print(raw.headers.get("x-coderouter-cost"))   # USD at list price

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://www.coderouter.io/api/v1",
  apiKey: process.env.CODEROUTER_KEY,
});

const resp = await client.chat.completions.create({
  model: "auto",
  messages: [{ role: "user", content: "Write a Python quicksort" }],
});
console.log(resp.choices[0].message.content);

Anthropic SDK

Native Anthropic Messages format

If your code is already using @anthropic-ai/sdk or anthropic (Python), you can point it at our endpoint and we'll route via the /v1/messages protocol.

Python

from anthropic import Anthropic

client = Anthropic(
    base_url="https://www.coderouter.io",
    auth_token="cr_YOUR_KEY_HERE",  # or api_key=...: CodeRouter reads either header
)
msg = client.messages.create(
    model="auto",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)

Verify your setup

Sanity checks that don't cost tokens

Use the X-Dry-Run: true header to get a routing decision back without actually invoking a model:

curl https://www.coderouter.io/api/v1/chat/completions \
  -H "Authorization: Bearer cr_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Dry-Run: true" \
  -d '{"model":"auto","messages":[{"role":"user","content":"Refactor this Python function"}]}'

Response should include the chosen model and a cost estimate:

{
  "dryRun": true,
  "routing": {
    "modelSelected": "kimi-k2.6",
    "strategy": "balanced",
    "estimatedCost": { "selected": "$0.0020", "ifOpus": "$0.0101", "savings": "80.0%" }
  }
}

For a real call (small request, real tokens):

curl https://www.coderouter.io/api/v1/chat/completions \
  -H "Authorization: Bearer cr_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"auto","messages":[{"role":"user","content":"Hello"}]}'

Response headers say which model answered and what it cost — X-CodeRouter-Model and X-CodeRouter-Cost — so you can confirm routing is active even from a black-box agent. X-CodeRouter-Cost-If-Opus is a same-token estimate: the same tokens at Opus list price. In a coding-agent session a stronger model takes a different number of steps, so it isn't what an all-Opus session would have cost, and agent-session requests (tools, tool results, earlier assistant turns, or a recognized agent such as Claude Code or Cursor) carry no X-CodeRouter-Savings. Single-turn requests still get it, as an estimate; the dry run's savings field follows the same rule.

X-CodeRouter-Cost is the request's cost at list price, which is what requests are billed at (no markup), cache reads and writes included. On streaming responses the headers are sent before the model has produced any usage, so the cost there is an estimate (input size + 500 output tokens) and the response also carries X-CodeRouter-Cost-Estimated: true. The amount logged and charged always uses the provider's real usage. Response bodies have the API's own shape only; CodeRouter's routing and cost information is in these headers.

Parameters CodeRouter changes

Some models refuse request parameters that coding agents commonly send. CodeRouter then sends a value the model accepts and says so in the response header X-CodeRouter-Adjusted: a comma-separated list of parameter=value sent, for example X-CodeRouter-Adjusted: tool_choice=auto. It is on streamed and non-streamed responses of all three APIs, and absent when nothing was changed.

  • tool_choice=auto: Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1 and Claude Fable 5.2 reject a forced tool choice ({"type":"any"} or {"type":"tool"}; in the OpenAI format "required" or a named function) with a 400 at every thinking setting, because these models always think. When one of them serves the request, whether you named it or routing picked it, CodeRouter sends auto instead, so the model may answer in text rather than call the tool. Other Claude models and other providers get the tool choice as you sent it.
  • max_tokens=N: a max_tokens above the output limit of the model that serves the request is lowered to that limit, on every provider: 128,000 on Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.2, Fable 5.1, Opus 5, Opus 4.8, Opus 4.7 and Sonnet 4.6; 64,000 on Claude Opus 4.5 and Haiku 4.5; 128,000 on GPT-6.1 Sol, GPT-6.1 Terra, GPT-6 Sol, GPT-6 Luna, GPT-5.5, GPT-5.4, GPT-5.2 and GPT-5 Mini; 65,536 on Gemini; 65,536 on DeepSeek, Kimi, GLM-5.2 and GLM-5.3 (on Kimi K2.6 agent turns, which run with thinking, 8,192); 4,096 on Qwen Plus, 8,192 on Qwen Max. When a fallback model answers, the value is the one sent to that model. A reply cut at that limit is reported as cut off: finish_reason: "length", stop_reason: "max_tokens" on /v1/messages, and on /v1/responses status: "incomplete" with incomplete_details.reason: "max_output_tokens" (streamed: response.incomplete). /v1/responses names it max_output_tokens=N. On /v1/messages, max_tokens: 0 (Anthropic's cache pre-warm) is sent to a non-Claude model as 1, since those APIs take at least 1: one output token is generated and billed. On the GPT-6 models (and GPT-5.5 / GPT-5.4 requests sent to OpenAI's Responses API for their reasoning effort, below) a value below 16 is sent as 16, the least that API takes (listed as max_tokens=16); a prepaid balance or trial credit is checked for those 16 tokens.
  • No max_tokens in the request (Codex CLI never sends max_output_tokens): Claude and Gemini get the serving model's output limit above, as OpenAI treats an unset limit (until November 2026 CodeRouter sent 4,096); GPT and the OpenAI-compatible providers get none and use their own default. This isn't listed in X-CodeRouter-Adjusted, since the request had no value to change. When the request is billed from a prepaid balance (Direct, Team, overage), max_tokens is lowered to what the balance covers, with or without a value in the request.
  • Free trial: CodeRouter pays the provider for trial requests, so a request's worst case has to fit the trial credit you have left — its estimated input (on Claude priced as a 1-hour cache write, 2× the input price; on the GPT-6 models as a cache write, 1.25×) plus max_tokens of output (the model's output limit when the request sets none), at list price, on the most expensive model the request may fall back to. When it doesn't fit, max_tokens is lowered to what the credit left covers (and to no more than the lowest output limit among those models), with or without a value in the request, and listed as max_tokens=N (max_output_tokens=N on /v1/responses). A value that fits is sent unchanged. When the credit left doesn't cover the input plus 1,024 output tokens (or plus the request's own max_tokens, if lower), the request gets HTTP 429 ("usage credit is used up for this request", with what it needs and what is left). Requests on your own provider keys aren't limited this way.
  • effort=low: Claude Fable 5.2 always thinks, at its default effort (high) it thinks before almost every reply, and thinking counts toward max_tokens. A small max_tokens can then be spent on thinking alone, and the reply has no text (cut off: finish_reason: "length"). When a request to Claude Fable 5.2 has a max_tokens of 1,024 or less (after any lowering above) and sets no effort itself, CodeRouter sends Anthropic's output_config.effort as low, so a short request gets a short answer. A request that sets output_config.effort on /v1/messages keeps it; OpenAI-format requests have no Anthropic effort field, so for them this applies whenever max_tokens is that small. Above 1,024, nothing changes: thinking can still use the whole max_tokens on a hard request.
  • reasoning_effort=… (reasoning.effort=… on /v1/responses, effort=… on /v1/messages), reasoning.mode=standard: in Direct mode the reasoning effort your request sets is sent to OpenAI's GPT models, at the nearest level the model takes. When that isn't the level you asked for, or CodeRouter translated it from Anthropic's thinking, the header names the level sent; pro mode isn't sent yet. temperature=removed, top_p=removed: GPT-5.5 and GPT-5.4 take them only at effort none, so they aren't sent with another effort you set. See Reasoning effort on GPT models.
  • speed=standard, inference_geo=removed: Anthropic's fast mode (speed: "fast" on /v1/messages) is sent to Claude Fable 5.2 and Opus 5.5. Claude Opus 5 and Opus 4.8 have fast mode in Anthropic's research preview; CodeRouter doesn't offer it on them for now, so those requests are sent at standard speed and billed at standard prices. US-only inference (inference_geo: "us") is sent to Claude 4.6 and later. When a model without them serves the request (another Claude, or another provider in a fallback; a US-only request never falls back to one, below), it is sent at standard speed or without inference_geo, billed at that model's own price. Fast mode and US-only inference are billed at Anthropic's list price for them, with no markup. Anthropic's server tools are billed the same way: web search at $10 per 1,000 searches; code execution, when the request has no web search or web fetch tool of version 20260209 or later, at $0.05 per container hour with Anthropic's 5-minute minimum, once per request that runs code; advisor calls at the advisor model's price.
  • inference_geo=us_only_pool: a request with inference_geo: "us" is only served by models that run it in the US, Claude 4.6 and later: smart routing chooses among them (this value), and a fallback goes only to one of them. When the model serving the request fails and none of them is left to try, you get that model's error (for example 429 or 502), not an answer from another provider. In Direct mode the model you name serves the request as before.
  • advisor=removed: Anthropic's advisor tool runs a second model inside the request, billed at its price, and every advisor model Anthropic accepts is an Opus-class model. Where the request can't use Opus-class models, it is sent without the advisor tool: on the free trial, on the Starter and Solo plans, on Pro past its included usage, while a team budget is in downgrade, with a key whose model list has no Opus-class model, and on pay as you go while carried-over trial credit pays at a $0 balance.
  • Free trial: the trial credit covers standard usage, so a trial request is sent without fast mode, US-only inference, the web search and advisor tools, code execution (unless a web fetch tool of version 20260209 or later makes it free) and server-side fallbacks, each listed in the header (speed=standard, inference_geo=removed, web_search=removed, code_execution=removed, advisor=removed, fallbacks=removed). Web fetch and your own tools are sent as usual.

Prompt caching on Claude for OpenAI-format requests: a /api/v1/chat/completions or /v1/responses request can't carry Anthropic's cache_control markers, so when a Claude model serves it CodeRouter places them: on the tool definitions, on the system prompt (when it is over 1,024 characters) and, for a conversation (an earlier assistant turn or tool definitions in the request), on the latest user message or tool result, so the next turn can read the earlier turns from the cache instead of paying full input price for them (Anthropic caches prompts of at least 512 to 4,096 tokens, depending on the model). Cache writes are billed at Anthropic's rates: 1.25× input for 5-minute entries (used when a session's turns usually come within 5 minutes of each other), 2× for 1-hour entries (otherwise); reads at the model's cache price. /v1/messages requests keep the markers the client placed.

System and developer messages on Claude, for OpenAI-format requests: the ones at the start of the conversation become Claude's system prompt, in order; one that comes later is sent at its position, as text in that user turn wrapped in <system-message>…</system-message>, so the earlier turns stay cached.

max_tokens must be an integer of at least 1 on /api/v1/chat/completions (max_completion_tokens too) and /v1/responses (max_output_tokens), and an integer of at least 0 on /v1/messages, as on OpenAI and Anthropic. Anything else gets a 400 invalid_request_error before any model is called, and nothing is billed.

Stop sequences on GLM-5.3: Zhipu's API applies stop to the model's hidden reasoning as well, so a stop string that came up while the model was thinking ended the reply with an empty answer. For GLM-5.3, CodeRouter doesn't send stop to Zhipu and cuts the visible answer at the first stop string itself (finish_reason: "stop"; on /v1/messages stop_reason: "stop_sequence" with the stop_sequence). The model keeps generating past the stop and those tokens are billed as Zhipu reports them; a streamed response sends its finish event at the stop and closes when Zhipu has finished.

OpenAI GPT-6 models

GPT-6.1 Sol, GPT-6.1 Terra, GPT-6 Sol and GPT-6 Luna are available by name in Direct mode; smart routing doesn't use them. CodeRouter sends their requests to OpenAI's Responses API on every route, because OpenAI's Chat Completions API takes tool definitions for these models only with reasoning turned off (GPT-6 Sol and Luna) or not at all (GPT-6.1 Sol and Terra). Requests run at OpenAI's default reasoning effort (medium) unless they set their own (below). temperature and top_p aren't sent (OpenAI accepts them only with reasoning off), nor presence_penalty / frequency_penalty (the Responses API has none). The Responses API has no stop either: CodeRouter cuts the visible answer at the first stop string itself, as for GLM-5.3 above, and the tokens generated past it are billed as OpenAI reports them. Tool definitions are sent non-strict, as on Chat Completions, unless a tool sets strict itself (function.strict, or strict on a /v1/responses or /v1/messages tool), which is sent as set. File parts ({"type": "file"}) are sent as the Responses API's input_file; a request with a part that API can't take, such as input_audio, gets a 400 invalid_request_error before any model is called. Reasoning isn't returned or replayed between turns.

OpenAI bills prompt-cache writes on these models: tokens written to the cache cost 1.25× the input price (the default 30-minute cache), cache reads 0.1× (0.05× on GPT-6.1 Sol and Terra). CodeRouter bills both at those prices, with no markup; prompts over 272K input tokens are priced at 2× input and cache rates and 1.5× output for the whole request, as at OpenAI. A response reports the writes in prompt_tokens_details.cache_write_tokens (chat completions), input_tokens_details.cache_write_tokens (/v1/responses) and cache_creation_input_tokens (/v1/messages).

Reasoning effort on GPT models

In Direct mode (the model you name answers), the reasoning effort your request sets is sent to OpenAI's GPT models: reasoning_effort on /api/v1/chat/completions, reasoning.effort on /v1/responses, and on /v1/messages Anthropic's output_config.effort (the level names are the same). A thinking setting on /v1/messages is translated: disabled → none; budget_tokens below 4,096 → low, below 16,384 → medium, below 32,768 → high, from 32,768 → xhigh. Adaptive thinking without an effort leaves the model at its default. The levels each model takes, from OpenAI's model pages:

  • GPT-6.1 Sol: low, medium (default), high, xhigh, max
  • GPT-6.1 Terra, GPT-6 Sol, GPT-6 Luna: none, low, medium (default), high, xhigh, max
  • GPT-5.5: none, low, medium (default), high, xhigh; GPT-5.4 and GPT-5.2: none (default), low, medium, high, xhigh
  • GPT-5 Mini: minimal, low, medium, high

A level the model doesn't take is sent as the nearest one it does (between two, the higher one, as OpenAI advises for minimal): for example none → low on GPT-6.1 Sol, max → xhigh on GPT-5.5, none → minimal on GPT-5 Mini. The level sent is listed in X-CodeRouter-Adjusted under your parameter's name (reasoning_effort=low, reasoning.effort=low, effort=low), and so is a level translated from thinking; a value that isn't a reasoning effort isn't sent (reasoning_effort=default). OpenAI's Chat Completions API takes tools on GPT-5.5 and GPT-5.4 only at effort none, so their requests with tools and another effort go to OpenAI's Responses API, like the GPT-6 models. They also take temperature and top_p only at effort none (another value is a 400), so with another effort those aren't sent (temperature=removed, top_p=removed). On such a request sent to the Responses API, presence_penalty / frequency_penalty (which that API doesn't have) aren't sent either (presence_penalty=removed, frequency_penalty=removed), streams get the longer limits of models that think before they write (no 60-second cut while the model reasons), and a request with content that API can't take (input_audio) stays on Chat Completions at effort none, as before (reasoning_effort=none). Reasoning tokens are billed as output tokens and count toward max_tokens, so a higher effort costs more but can't take a request past what your balance covers. Pro mode (reasoning.mode: "pro") isn't sent yet: OpenAI bills all the work it does, which in our tests went past max_output_tokens (up to three times) and the prompt's size, so a request's cost couldn't be held to your balance in advance. It runs in standard mode, listed as reasoning.mode=standard.

Smart routing is unchanged: it sets the reasoning depth for the coding phase on GPT and Gemini models (lower for small edits), and a request that sets its own effort runs at the routed model's default — except on Claude, which gets the effort and thinking of a /v1/messages request as sent.

Gemini 4 Carbon and Gemini 4 Argon are billed at Google's introductory price until it ends ($2 / $10 per 1M input / output tokens, cache reads $0.10, through November 30, 2026), then at $4 / $20 (cache reads $0.20) for requests from December 1, 2026, 00:00 Pacific Time. Both are available by name in Direct mode; smart routing doesn't use them.

Long conversations

If a conversation's estimated size passes 85% of the chosen model's context window, CodeRouter forwards a shortened history: it keeps every system message and the first two and last six other messages, drops the messages in between, and adds a one-line note telling the model how many were left out. This keeps very long agent sessions from failing with context-length errors. The response then carries X-CodeRouter-Compressed (messages dropped and estimated token counts). To always send the full history, add the request header X-CodeRouter-Auto-Compress: false.

Coding-agent sessions

A coding-agent session — the agent calls tools in a loop and sends back their results (Claude Code, Codex CLI, Cursor's agent, OpenHands and similar), or writes shell commands and gets their output back — stays on one model, so the prompt cache stays warm. It starts on the cheapest model that can handle the task and moves to a stronger one only when a code change fails its tests or the agent stops making progress. X-CodeRouter-Model on each response names the model that answered. We keep optimizing our routing strategies and algorithms; the benchmark page reports measured results.

Troubleshooting

Common errors and fixes

"There's an issue with the selected model (auto)"

Claude Code only. Three causes (in order of likelihood):

  1. Your cr_ key isn't the credential in use, so requests go to your Claude subscription instead (for example the key is in ANTHROPIC_API_KEY, which Claude Code uses only after you approve it, or the session started before setup). Put it in ANTHROPIC_AUTH_TOKEN, restart Claude Code, and check /status and that the badge reads API Usage Billing, not Claude Max.
  2. Old Claude Code v2.1.x with new beta features — add CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 to env.
  3. Wrong base URL shape causing double /v1 on requests. We accept both https://www.coderouter.io and https://www.coderouter.io/api/v1 via internal rewrites.

"Your free trial has ended" / "usage credit is used up" (HTTP 429)

The free trial is $1 of usage over 7 days with no card, raised to $5 when you add a card on your dashboard (it isn't charged; one trial per card). It ends 7 days after signup or when the credit is used up, whichever comes first; after that, requests return HTTP 429 with one of these messages. Add balance to keep going on pay as you go (see /pricing), or add your own provider keys at /dashboard/models to keep going on your own keys. Close to the end of the credit, a request whose input alone costs about as much as the credit left gets "usage credit is used up for this request", with what it needs and what is left; a shorter request can still go through (see Parameters CodeRouter changes).

"Rate limit exceeded" (HTTP 429)

Per-key + per-user rate limits. Defaults: Free trial 60, Pay as you go 1,000, Team 2,400 req/min; older plans keep their own limits. Check X-RateLimit-Reset response header for retry timing.

"Invalid max_tokens value" or "max_tokens is too large"

Should not happen — CodeRouter lowers max_tokens to the output limit of the model that serves the request before forwarding it (see Parameters CodeRouter changes). If you hit this, your client is sending a value the limit doesn't cover; report it via issues.

"Unable to download the file" from Anthropic

Sending an image as a data URL. Should be auto-converted to base64 by our Anthropic adapter; if you still hit this, the image MIME type is unrecognized (only image/png, image/jpeg, image/gif, image/webp are supported by Anthropic).

"<model> rejected the request" (HTTP 400) / "All models in fallback chain failed"

A request that fails on every model it can go to returns what those models said:

  • The routed model rejected the request itself (the provider answered 400, 404, 409, 413 or 422): you get that status (422 is sent as 400) and the provider's reason, starting with the model — for example claude-haiku-5.5 rejected the request: Anthropic API error 400: messages.3.content.1.image: …. Sending the same request again fails the same way: change what the message points to (an image, a tool result, the length of the conversation) first. If the request also went to fallback models, they are listed after (also tried: …).
  • Rate limits, provider outages, timeouts: the status stays 429 (with Retry-After when the provider sent one), 502 or 504, and the message names each model tried and what it returned, for example Anthropic API error 503: Overloaded (tried: kimi-k2.6 503 …; claude-sonnet-5.5 503 Overloaded). Retrying a little later is the right move.

On /v1/responses, a stream that already started and then gets a 400, 413 or 422 from the provider ends with a response.failed event with code invalid_prompt (other failures: upstream_error). Requests with images fall back only to models that take images, and requests with tools only to models that call tools; when none is left, the error is the routed model's own.

Anything else

Email support@coderouter.io with:

  • The exact error message + HTTP status code
  • Your agent name + version
  • The full curl reproduction (omit your cr_ key)