# Claude Code Router: Use GPT, DeepSeek and GLM

> Claude Code Router v3 setup: install CCR, add an OpenAI-compatible provider, route Claude Code to GPT, DeepSeek or GLM, or skip the proxy with one env var.

Source: https://goiapi.com/en/blog/claude-code-router
Updated: 2026-12-05

Author: GoiAPI, December 5, 2026

Claude Code Router (CCR) is an open-source proxy that runs on your machine: Claude Code sends its requests to CCR, and CCR forwards each one to the model you pick, including GPT, DeepSeek and GLM models. To run all three on one API key, you add GoiAPI as a provider in CCR, choose a default model, and launch Claude Code from a CCR profile. If you only need one non-Claude model and no routing rules, you can skip CCR entirely and set `ANTHROPIC_MODEL`, because GoiAPI accepts GLM, DeepSeek and GPT models in the Anthropic Messages format that Claude Code speaks.

This guide covers both routes: the current CCR v3 setup (most tutorials online still describe the old `config.json` version), its routing rules and fallback modes, and a measured test of Claude Code running [`glm-5.3`](https://goiapi.com/en/models/glm-5.3), [`deepseek-v4-pro-0813`](https://goiapi.com/en/models/deepseek-v4-pro-0813) and [`gpt-6.1-sol`](https://goiapi.com/en/models/gpt-6.1-sol) directly, with token counts and USD cost per turn.

One thing to know first: Anthropic's documentation says it "doesn't support routing Claude Code to non-Claude models through any gateway" ([Claude Code LLM gateway docs](https://code.claude.com/docs/en/llm-gateway), checked on December 5, 2026). Everything below works through third-party tools, and Anthropic will not help if something breaks.

Disclosure: GoiAPI sells API access to the models discussed in this article.

## What is Claude Code Router?

Claude Code talks to models in the Anthropic Messages format, by sending requests to the `/v1/messages` endpoint. The `ANTHROPIC_BASE_URL` environment variable changes where those requests go, but not the format. CCR sits in the middle and redirects them.

The project lives at [musistudio/claude-code-router on GitHub](https://github.com/musistudio/claude-code-router). It is MIT-licensed, and the README showed version v3.1.6 when we checked on December 5, 2026. CCR v3 has three moving parts:

- **Gateway.** A local endpoint at `http://127.0.0.1:3456` that receives requests from Claude Code (and from other agents such as Codex).
- **Providers.** Each provider is an endpoint plus an API key plus a protocol. The README lists OpenAI Chat, OpenAI Responses, Anthropic Messages, Gemini Generate Content and Gemini Interactions.
- **Routing.** Rules that decide which model gets each request, plus retries and backup models when a request fails.

You manage all of it in a web UI at `http://127.0.0.1:3458`.

![Claude Code Router flow: Claude Code sends requests to CCR on 127.0.0.1:3456, CCR rules pick a model, and the request goes to api.goiapi.com](https://media.goiapi.com/blog/claude-code-router-request-flow-nh7rvinuhq/1600.webp)

## Most Claude Code Router tutorials are out of date

Search for "claude code router" and many guides still tell you to edit `~/.claude-code-router/config.json` with `Providers` and `Router` blocks, set `background`, `think` and `longContext` routes, then run `ccr code`. The current CCR documentation (ccrdesk.top) describes none of that.

In v3, the configuration lives in a SQLite database, `config.sqlite`, and you change it through the web UI. The folder is:

- macOS / Linux: `~/.claude-code-router`
- Windows: `%APPDATA%\claude-code-router`

Claude Code is launched through a named profile (`ccr <profile> cli`), not `ccr code`. If a tutorial shows a JSON config file, it was written for an older release.

## How to install Claude Code Router

You need Node.js 22 or newer. Install the CLI from npm (command from the project README, checked on December 5, 2026):

```bash
npm install -g @musistudio/claude-code-router@latest
```

There is also a desktop app for Windows, macOS and Linux, and a Docker setup built from the repository. Once installed, these are the commands you will use, per the [CCR CLI reference](https://ccrdesk.top/en/guides/cli/):

| Command | What it does |
|---|---|
| `ccr ui` | Starts (or reuses) the background service and gateway, then opens the management UI in your browser |
| `ccr ui --no-open` | Same, without opening a browser (for SSH or headless machines) |
| `ccr start` | Starts the background service and prints the management URL |
| `ccr stop` | Stops the background service started by `start` or `ui` |
| `ccr serve` | Runs in the foreground of the current terminal, handy for reading startup errors |
| `ccr <profile> cli` | Launches Claude Code (or another agent) through an Agent Config profile |

The management URL printed by `ccr start` contains a `ccr_web_token` parameter. Treat that full URL like a password: do not paste it into tickets, chats or screenshots.

If Claude Code itself is not installed yet, follow our [Claude Code API key setup guide for Windows, macOS and VS Code](https://goiapi.com/en/blog/claude-code-api-key) first.

## Add GoiAPI as a provider in CCR

You need a GoiAPI API key (it starts with `sk-...`). Create one under **API Keys** in the dashboard; the full key is shown only once, so copy it right away. The steps below follow the [CCR provider guide](https://ccrdesk.top/en/guides/provider/), checked on December 5, 2026. We have not run this exact flow with GoiAPI inside CCR, and button labels may differ slightly in your version.

1. Run `ccr ui`, open **Providers** and click **Add Provider**.
2. GoiAPI is not a built-in preset, so choose **Other / custom API endpoint**.
3. Enter a **Name** (for example `goiapi`) and the **API endpoint**.
4. In the **Add credentials** step, paste your GoiAPI key.
5. CCR auto-detects the protocols and models the endpoint supports. Select only the models you plan to use: the connection check sends real requests, and the CCR docs warn it may consume a few tokens.
6. Click **Check Connection**, then save the provider once the check passes.

### Which endpoint URL to use

Start with `https://api.goiapi.com/v1` and the OpenAI Chat protocol. GoiAPI accepts:

- the OpenAI format at `https://api.goiapi.com/v1` (`POST /v1/chat/completions`, documented in the [OpenAI-compatible API reference](https://goiapi.com/en/docs/openai-chat-completions)),
- the Anthropic format at `https://api.goiapi.com` with no `/v1` (`POST /v1/messages`, see the [Anthropic Messages reference](https://goiapi.com/en/docs/anthropic-messages)).

The CCR docs do not say whether the endpoint field should end in `/v1`. If auto-detection picks the wrong protocol, turn it off under **Advanced settings** and choose the protocol by hand.

Per the GoiAPI docs, some models are only available through one format, and calling a model through a format it does not support returns a `503` error. In our own test on December 3, 2026, all 9 models returned HTTP 200 through `/v1/chat/completions`, and the 8 models we tried through `/v1/messages` (both Claude models, `glm-5.3`, `glm-5.3-flash`, `deepseek-v4-pro-0813`, `deepseek-v4.1-flash`, `gpt-6-luna` and `gpt-6.1-sol`) also returned 200. That was true on the test date and can change.

GoiAPI also supports the OpenAI Responses format (`POST /v1/responses` under the same `/v1` base URL), but without `previous_response_id`, OpenAI's built-in tools or `file_id` inputs ([Responses API docs](https://goiapi.com/en/docs/openai-responses)). If CCR detects the Responses protocol and requests fail, switch the provider to OpenAI Chat manually. Our [OpenAI-compatible API explainer](https://goiapi.com/en/blog/openai-compatible-api) covers the differences between these formats.

## Connect Claude Code to CCR with an Agent Config profile

CCR calls this part **Agent Config**. A profile is a named bundle of settings that tells CCR which agent to launch and which model it should use. These steps follow the [CCR Agent Config guide](https://ccrdesk.top/en/guides/agent-profile/), checked on December 5, 2026; we have not run Claude Code through a CCR profile against GoiAPI.

1. Open **API Keys** in CCR and create a client key. This key lets tools call the CCR gateway and is separate from your GoiAPI key; the CCR docs say the gateway requires one.
2. Click **Add Profile** and choose **Claude Code**. Enter a **Profile name**, for example `goiapi-glm`.
3. Pick an **Entry mode**: "CLI & APP", "CLI only" or "App only". For the terminal, pick one that includes CLI.
4. Leave **Scope** at the default "Only opened from CCR" while you test, so Claude Code only goes through CCR when you start it from CCR. Switch to "System default" once everything works.
5. Under **Model**, choose the default model, for example `glm-5.3` from the `goiapi` provider. Leaving it blank keeps Claude Code's own default.
6. Click **Save**, then start Claude Code with the terminal button or `ccr goiapi-glm cli`.
7. Send a test message, then open **Request logs** in CCR to confirm the request went through the gateway.
8. Inside Claude Code, run `/model` to list and switch between the models CCR exposes.

The CCR docs do not say which environment variables a profile sets for Claude Code, or whether it edits `~/.claude/settings.json`. They do say CCR keeps generated launch wrappers in a `bin/` folder and per-profile files in `profiles/`.

## Claude Code Router routing rules: which model handles what

The [CCR routing docs](https://ccrdesk.top/en/routing/) (checked on December 5, 2026) describe four mechanisms worth knowing.

### The built-in Claude Code route

For Claude Code's main requests, if Claude Code asks for a model CCR recognizes, CCR uses it. The model set in your Agent Config profile applies only when the requested model is missing or unrecognized; if the profile has no model, this built-in route stays inactive. Your own rules can still rewrite the model afterwards.

### Custom rules

Rules are checked in list order, and the first enabled rule that matches wins. A condition reads a field from `request.header` or `request.body` (dot paths such as `messages.0.role` work) and compares it with operators including `==`, `!=`, `starts with`, `contains` and `contains deep`, which searches nested objects and arrays such as `messages` and `tools`. To switch models, the rule sets `request.body.model` to a `provider/model` value.

The example in the CCR docs: if `request.body` field `messages` `contains deep` the value `image`, set `request.body.model` to a vision-capable model.

### A separate model for subagents

Subagents are helper agents that Claude Code spawns for side tasks. To send one to its own model, start its prompt with this tag:

```text
<CCR-SUBAGENT-MODEL>goiapi/glm-5.3</CCR-SUBAGENT-MODEL>
```

CCR only looks for the tag in the system prompt or the first two user messages, removes it before forwarding, and routes the request to that model. The docs add that at least one model needs a Description configured for this to work.

### Retry and fallback

Each request can use one of three failure modes:

- **Off**: send the request once to the selected model.
- **Retry**: retry the same model on 408, 409, 429, 5xx or network errors. CCR waits between attempts, honoring a positive `Retry-After` header if one comes back, otherwise backing off from 1 second up to 30 seconds per attempt.
- **Fallback targets**: try the selected model, then each backup model in order, on any 4xx, 5xx or network error.

A matching rule's **On failure** setting overrides the global default for that request.

### What about background, think and longContext?

Older guides route `background`, `think` and `longContext` requests to different models. The CCR v3 routing docs do not describe these routes; the only built-in routes are for Claude Code and Codex. If you want that behavior, write your own rules.

### A sensible default setup

One reasonable split: a lower-priced model as the default, and [Claude Opus 5.5](https://goiapi.com/en/models/claude-opus-5-5) as the fallback target when the default fails. For example (not tested inside CCR): default `glm-5.3`, fallback `claude-opus-5-5`. The GoiAPI docs recommend calling Claude models in the Anthropic format, but in our direct test on December 3, 2026, `claude-opus-5-5` returned 200 through both `/v1/chat/completions` and `/v1/messages`, so a single `goiapi` provider set to OpenAI Chat at `/v1` was not blocked on that date. If Claude models ever require the Anthropic format there, add a second provider pointing at `https://api.goiapi.com` with the Anthropic Messages protocol.

Remember that a fallback target is a different model, not a retry of the same one. If you mainly fight overload errors on one model, our [Claude 529 overloaded error guide](https://goiapi.com/en/blog/claude-529-overloaded-error) covers the other options.

## Use GPT, DeepSeek or GLM in Claude Code without CCR

You can, at least as of our test. Claude Code picks its model from the `ANTHROPIC_MODEL` environment variable, and GoiAPI accepted GLM, DeepSeek and GPT models in the Anthropic format (`/v1/messages`), so no proxy is needed. On macOS or Linux:

```bash
export ANTHROPIC_BASE_URL="https://api.goiapi.com"
export ANTHROPIC_AUTH_TOKEN="sk-..."
export ANTHROPIC_MODEL="glm-5.3"
claude
```

On Windows, in PowerShell:

```powershell
$env:ANTHROPIC_BASE_URL = "https://api.goiapi.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-..."
$env:ANTHROPIC_MODEL = "glm-5.3"
claude
```

Swap `glm-5.3` for `deepseek-v4-pro-0813`, `gpt-6.1-sol` or any model name from the [GoiAPI model list](https://goiapi.com/en/models). These are the same variables as in the [Claude Code integration docs](https://goiapi.com/en/docs/integrations/claude-code), which use a Claude model in the example.

Claude Code also documents two related variables, which we have not tested with non-Claude models:

- `ANTHROPIC_DEFAULT_HAIKU_MODEL`: the model the `haiku` alias resolves to, also used for background functionality.
- `CLAUDE_CODE_SUBAGENT_MODEL`: the default model for subagents that are not assigned a model another way.

Together they give you a rough version of CCR's per-task routing without a proxy: for example, Claude Opus 5.5 for the main session and a lower-priced model for subagents.

### Test results: Claude Code on GLM, DeepSeek and GPT

We ran Claude Code CLI 2.1.325 on Windows 10 on December 3, 2026, in non-interactive mode (`-p`) in an empty folder, with `ANTHROPIC_API_KEY` unset so no other key could interfere. The prompt was a one-line arithmetic question, sent like this:

```bash
ANTHROPIC_BASE_URL=https://api.goiapi.com \
ANTHROPIC_AUTH_TOKEN=sk-... \
ANTHROPIC_MODEL=glm-5.3 \
claude -p "<one-line question>" --output-format json
```

| `ANTHROPIC_MODEL` | Result | Time to first token | Total time | Input / cache write / cache read tokens | Cost at GoiAPI prices |
|---|---|---|---|---|---|
| `claude-haiku-5-5` | correct answer | 2,252 ms | 3,804 ms | 10,679 / 15,574 / 0 | about $0.0009 |
| `glm-5.3` | correct answer | 3,762 ms | 5,423 ms | 14,730 / 0 / 1,536 | about $0.0022 |
| `deepseek-v4-pro-0813` | correct answer | 6,300 ms | 9,076 ms | 16,507 / 0 / 128 | about $0.0024 |
| `gpt-6.1-sol` | correct answer | 2,520 ms | 3,480 ms | 14,684 / 0 / 0 | about $0.0019 |

Each cell is a single run, so treat it as a rough reference. Costs are our own calculation from the token counts Claude Code reported and GoiAPI prices checked on December 5, 2026 (output was a few dozen tokens at most and barely moves the total). Ignore the `total_cost_usd` figure Claude Code prints: it is an estimate based on Claude Code's own price list, not what GoiAPI charges.

What we saw:

- **All three non-Claude models worked, with no `503`.** Direct calls to `/v1/messages` on the same day also returned 200 for `glm-5.3`, `deepseek-v4-pro-0813` and `gpt-6.1-sol`.
- **Claude Code prints a warning but keeps going**, for example `[claude-code:unrecognized_model] {"model":"glm-5.3","query_source":"sdk"}`, and the same for the DeepSeek and GPT models. That matches Anthropic's position that non-Claude models are unsupported.
- **`ANTHROPIC_MODEL` alone was enough.** The `modelUsage` block of each run listed only the model we set, with no background calls to other model names and no 404s.
- **The base URL must not end in `/v1`.** With `ANTHROPIC_BASE_URL=https://api.goiapi.com/v1`, Claude Code requests `/v1/v1/messages`, gets a 404, and reports `There's an issue with the selected model (claude-haiku-5-5). It may not exist or you may not have access to it. Run --model to pick a different model.` The message blames the model, not the URL, so it is easy to misread. Our [Claude Code API error guide](https://goiapi.com/en/blog/claude-code-api-error) lists the other codes.

Two limits of this test: it was a short question, not a long task where Claude Code reads files, edits code and runs commands over many turns; and it ran in `-p` mode, not an interactive session. Tool calling on non-Claude models is where problems usually show up, so try a real task on a throwaway branch before you rely on it. If a model later becomes available only in the OpenAI format, Claude Code will get a `503`, and that is when CCR with an OpenAI Chat provider becomes the way to go.

### CCR or ANTHROPIC_MODEL: which should you use?

| You want to... | Use |
|---|---|
| Run Claude Code on one non-Claude model | `ANTHROPIC_MODEL`, no proxy |
| Switch models between sessions | `ANTHROPIC_MODEL` or `/model` |
| Send images, subagents or matching requests to different models automatically | CCR routing rules |
| Retry or fail over to a backup model on errors | CCR fallback targets |
| Reach a model that only speaks the OpenAI format | CCR with an OpenAI Chat provider |

## Why your Claude Code session costs more than a plain API call

The price per token is only half the story. Claude Code is an agent: one request can trigger dozens of model calls, and each call resends the conversation context. In the test above, even a one-line question used 10,679 to 16,507 input tokens per turn, mostly Claude Code's system prompt and tool definitions. That is why a single trivial turn cost about $0.0009 to $0.0024, far more than the same question sent straight to the API.

It also means a lower price per token does not guarantee a lower bill. If a weaker model calls tools incorrectly and has to redo work over several rounds, the total can end up higher than with a stronger, pricier model.

GoiAPI prices per 1M tokens in USD, checked on December 5, 2026 (full table on the [GoiAPI pricing page](https://goiapi.com/en/pricing)):

| Model | Model name | Input | Output | Cache read |
|---|---|---|---|---|
| Claude Opus 5.5 | `claude-opus-5-5` | $0.442 | $2.21 | $0.0221 |
| GLM 5.3 | `glm-5.3` | $0.144144 | $0.432432 | $0.014495 |
| DeepSeek V4 Pro | `deepseek-v4-pro-0813` | $0.144144 | $0.432432 | $0.014495 |
| GPT-6.1 Sol | `gpt-6.1-sol` | $0.13 | $0.78 | $0.013026 |
| [GPT-6.2 Sol](https://goiapi.com/en/models/gpt-6.2-sol) | `gpt-6.2-sol` | $0.13 | $0.78 | $0.013026 |
| [GLM 5.3 Flash](https://goiapi.com/en/models/glm-5.3-flash) | `glm-5.3-flash` | $0.0408408 | $0.1225224 | $0.0040664 |
| [DeepSeek V4.1 Flash](https://goiapi.com/en/models/deepseek-v4.1-flash) | `deepseek-v4.1-flash` | $0.0408408 | $0.1225224 | $0.0040664 |
| [Claude Haiku 5.5](https://goiapi.com/en/models/claude-haiku-5-5) | `claude-haiku-5-5` | $0.0221 | $0.1105 | $0.00221 |
| GPT-6 Luna | `gpt-6-luna` | $0.0208 | $0.1248 | $0.002106 |

How to read this for Claude Code:

- **Try Claude Haiku 5.5 before switching makers.** It has one of the lowest output prices in the table, it was the lowest-cost run in our test, and as a Claude model it avoids Anthropic's non-Claude warning altogether. Set `ANTHROPIC_MODEL=claude-haiku-5-5`; no CCR needed.
- **Hand lower-priced models the routine work:** reading and summarizing code, writing tests, bulk renames, generating docs, and subagent side tasks.
- **Keep Claude Opus 5.5 for multi-file edits** and tasks that need long planning.

For per-model detail, see [GLM 5.3 API pricing](https://goiapi.com/en/blog/glm-5-3-api-pricing), [DeepSeek V4 API pricing](https://goiapi.com/en/blog/deepseek-v4-api-pricing), and the [GPT-6.1 Sol model page](https://goiapi.com/en/models/gpt-6.1-sol). If you are deciding between a Claude plan and paying per token, read [Claude Code Max vs API cost](https://goiapi.com/en/blog/claude-code-max-vs-api-cost).

## When not to use Claude Code Router

- **You need vendor support.** Anthropic does not support Claude Code on non-Claude models. A Claude plan or the Claude API directly is the safer path.
- **You want your plan's usage limits and claude.ai account features.** While a gateway credential is active, requests are billed per token and your subscription limits do not apply. Since Claude Code v2.1.196, Remote Control is disabled when `ANTHROPIC_BASE_URL` points anywhere other than `api.anthropic.com` ([Claude Code environment variable docs](https://code.claude.com/docs/en/env-vars), checked on December 5, 2026).
- **You need a much larger model catalog.** GoiAPI currently offers 9 models and does not include Claude Sonnet or Gemini. Services such as OpenRouter list far more.
- **You need a data processing agreement signed directly with the model maker.** Use that company's own API.

## FAQ

### How much does Claude Code Router cost?

Nothing for the software itself: Claude Code Router is open source under the MIT license. You still pay for the model calls it forwards, at the price of whichever API you connect.

### Does Claude Code Router still use config.json?

Not in v3. Configuration is stored in `config.sqlite` (`~/.claude-code-router` on macOS and Linux, `%APPDATA%\claude-code-router` on Windows) and edited in the web UI opened by `ccr ui`. Guides that show `config.json` and `ccr code` describe older releases.

### What port does Claude Code Router use?

The model gateway listens on `http://127.0.0.1:3456`, and the management UI runs on `http://127.0.0.1:3458`.

### Can I use GPT models in Claude Code?

Yes, with a caveat. In our December 3, 2026 test, Claude Code ran `gpt-6.1-sol` through GoiAPI by setting `ANTHROPIC_MODEL`, with no CCR and no OpenRouter, because GoiAPI accepted the model in the Anthropic format. Anthropic does not support this setup, and Claude Code prints an `unrecognized_model` warning.

### How do I use DeepSeek or GLM with Claude Code?

Set `ANTHROPIC_BASE_URL` to `https://api.goiapi.com`, `ANTHROPIC_AUTH_TOKEN` to your key, and `ANTHROPIC_MODEL` to `deepseek-v4-pro-0813` or `glm-5.3`, then run `claude`. Use CCR instead if you want rules that send different requests to different models.

### Why does Claude Code say the model may not exist when the name is right?

Usually the base URL ends in `/v1`. Claude Code then calls `/v1/v1/messages`, gets a 404, and blames the model. Use `https://api.goiapi.com` with no `/v1` for Claude Code.

### Does switching models break tool use in Claude Code?

It can. Our test only covered a short question. Agentic tasks with many tool calls are where non-Claude models are most likely to misbehave, so test on a real task first and keep a Claude model as a fallback.

### Can I switch models in the middle of a session?

Yes. Run `/model` inside Claude Code. With CCR, `/model` lists the models CCR exposes; without CCR, you can type a model name.

## Get started with GoiAPI

1. [Create an account](https://goiapi.com/en/signup) and generate an API key in the dashboard.
2. Top up with USDT (TRC20 or BEP20) or Binance Pay. No credit card and no monthly fee. Top-ups are final and non-refundable, so only add what you plan to use.
3. Set the base URL: `https://api.goiapi.com` for Claude Code (Anthropic format), or `https://api.goiapi.com/v1` for a CCR provider using OpenAI Chat. The [quickstart](https://goiapi.com/en/docs/quickstart) walks through your first request, and the **Request history** page in the dashboard shows the token count and cost of every call.
