deeprelayDocs
CH·GGuides

Claude Code

Run Claude Code on DeepSeek and GLM models through the Anthropic Messages endpoint: one setup command, what works, what is rejected, how to undo it.

deeprelay serves the Anthropic Messages API (POST /v1/messages), so Claude Code can run on deeprelay models. Claude Code keeps working as usual: it reads and edits files, runs commands and calls tools. Every request goes to a deeprelay model you picked, and it is billed like any other deeprelay inference.

deeprelay does not serve Claude models. Setup points every model slot Claude Code uses at a deeprelay model, so a configured session never asks for one.

Quick start

deeprelay login                 # once: stores your key in the deeprelay credentials file
deeprelay setup claude-code     # points Claude Code at deeprelay (asks before writing)
claude                          # start Claude Code as usual

Setup checks your key and every chosen model before it writes anything. It then shows a diff of the settings file and the undo command, and asks you to confirm.

For a single session with nothing written to disk, use deeprelay launch claude-code instead:

deeprelay launch claude-code    # one session, no settings file touched

deeprelay setup claude-code is the persistent choice: every new shell picks it up until you undo it. deeprelay launch claude-code is the per-session choice: it configures the child process through environment variables, runs Claude Code, and prints a cost receipt when it exits. See One session at a time: deeprelay launch below.

What setup changes

deeprelay setup claude-code merges these keys into a Claude Code settings file.

KeyValue
env.ANTHROPIC_BASE_URLhttps://api.deeprelay.ai (no /v1: Claude Code adds /v1/messages itself)
env.ANTHROPIC_MODELthe main model (--model)
env.ANTHROPIC_DEFAULT_OPUS_MODELthe model behind the opus alias (--opus-model)
env.ANTHROPIC_DEFAULT_SONNET_MODELthe model behind the sonnet alias (--sonnet-model)
env.ANTHROPIC_DEFAULT_HAIKU_MODELthe model behind the haiku alias (--haiku-model)
env.ANTHROPIC_DEFAULT_FABLE_MODELthe model behind the fable alias (--fable-model)
env.ANTHROPIC_SMALL_FAST_MODELthe background-task model (same as --haiku-model)
apiKeyHelperthe absolute path of your deeprelay binary, followed by auth token

Setup also removes env.ANTHROPIC_AUTH_TOKEN and env.ANTHROPIC_API_KEY from the file if they are there, and turns off a cloud-provider mode (CLAUDE_CODE_USE_BEDROCK, _VERTEX or _FOUNDRY) that is switched on. Claude Code uses any of these in preference to apiKeyHelper, so a key left over from another gateway would be sent to deeprelay instead of yours. The diff shows each removal; a credential's value is hidden, while a cloud-mode flag shows its true/false value. --remove puts the old values back. Everything else in the file is left alone.

Your key is never written to the settings file. apiKeyHelper makes Claude Code run deeprelay auth token whenever it needs the key, so the key stays in the deeprelay credentials file. The binary is referenced by its absolute path. If you move or reinstall deeprelay, run setup again.

Where it writes

  • User scope (default): ~/.claude/settings.json, or $CLAUDE_CONFIG_DIR/settings.json if you set that variable. Every project on this machine uses deeprelay.
  • Project scope (--scope project): .claude/settings.local.json in the current directory. Only this project uses deeprelay. Setup warns if git does not ignore that file.

Backups and undo

Before each write, setup copies the current settings file into the backups/claude-code folder of the deeprelay config directory (~/.config/deeprelay, or $XDG_CONFIG_HOME/deeprelay). Backups are timestamped and never overwritten. Setup also records which keys it added, changed or removed, and their earlier values. Your deeprelay key is never in that record; a credential setup removed from the settings file is, so that --remove can restore it.

deeprelay setup claude-code --remove replays that record. Add --scope project to undo a project setup.

  • Keys setup added are deleted.
  • Keys setup changed get their earlier values back.
  • Keys setup removed (a conflicting credential) are put back.
  • Keys you edited yourself after setup are left alone, with a warning.

Warnings

These always print, even with --yes:

  • the settings file already points ANTHROPIC_BASE_URL somewhere else, so setup would redirect all Claude Code usage to deeprelay;
  • the settings file holds a credential or cloud-provider setting that outranks apiKeyHelper, which setup removes (see above);
  • with --scope project, your user settings file holds such a setting; setup does not edit that file, and Claude Code will not reach deeprelay until you remove it there;
  • ANTHROPIC_* variables are set in your shell, which override the settings file (only the names are shown);
  • Claude Code is logged in to a Claude subscription and you chose user scope, so every project routes to deeprelay instead. Consider --scope project.

deeprelay setup claude-code --print writes nothing. It prints export lines for the same variables, with ANTHROPIC_AUTH_TOKEN in place of apiKeyHelper. That output contains your key in plaintext. Don't paste it into a file you commit or a log you share. In CI, prefer a secret store that sets ANTHROPIC_AUTH_TOKEN for the job.

One session at a time: deeprelay launch

deeprelay launch claude-code runs a single Claude Code session on deeprelay without touching any settings file. The configuration, the base URL, your key as ANTHROPIC_AUTH_TOKEN, a deeprelay model in every slot Claude Code uses, and a session header for the receipt, rides entirely in the child process's environment and disappears when the session exits. Credentials for other providers (an Anthropic key, or a Bedrock, Vertex or Foundry mode) are stripped from the child environment first, so they cannot leak to deeprelay or outrank the session.

deeprelay launch claude-code

The model slots default to the same curated models deeprelay setup claude-code uses. Pick different ones per slot with --model, --opus-model, --sonnet-model, --haiku-model and --fable-model.

The receipt

On exit, deeprelay launch claude-code reads back the session's request log and prints what it actually cost: per-model requests, input, cached and output tokens, and the exact billed total. The last line compares that total with the same tokens priced at Claude's published Opus list rates, so you can see what the session saved. The same rows stay queryable afterwards by the session id the receipt prints:

deeprelay requests list --client-request-id <session id>

Requests from other tools or sessions on the same key are never counted, because they carry a different id. Use --no-receipt to skip the lookup, and -o json to get the receipt as JSON on stdout for scripts.

Settings-file precedence

Claude Code applies the env block of a settings file over the process environment. If ~/.claude/settings.json (or the project's .claude/settings.local.json) sets ANTHROPIC_* keys, those win over the launched session; deeprelay launch claude-code warns and names them. A settings file written by deeprelay setup claude-code already points at deeprelay, so the session still works, its model choices just take precedence over launch's flags.

Headless use

Everything after the tool name (or after --) is passed to Claude Code unchanged, so a non-interactive run works the same way it would outside deeprelay:

deeprelay launch claude-code -- -p "run the tests and fix failures" < /dev/null

The exit code is Claude Code's own.

Models

Setup's defaults are models that completed real Claude Code coding sessions (reading files, editing, running commands, thinking, and a follow-up turn with --continue):

SlotDefaultWhy
Main, Opus, Sonnet, Fable (--model, --opus-model, --sonnet-model, --fable-model)deeprelay/deepseek-v4-proThe strongest tested model with thinking and reliable tool calls
Haiku and small-fast (--haiku-model)deeprelay/deepseek-v4.1-flashCovered by the flat plan (a subscriber's background tasks stay inside it), the same family as the main model, and it can see images; used for background tasks such as titles and summaries

deeprelay/glm-5.3 also completed a full session and works as a main model:

deeprelay setup claude-code --model deeprelay/glm-5.3

deeprelay/gpt-oss-120b completed a full session as well. It is not covered by the flat plan, but it is a cheaper pay-as-you-go choice for the background slot: --haiku-model deeprelay/gpt-oss-120b.

Any other model works if it supports tool calling. Setup checks this and refuses a model without it. To see what is available right now:

deeprelay models list

The catalog is live, so a model can come and go. If a model stops being served, run setup again with another one.

Backup models

A model can go down. Backup models keep your sessions running when it does: if every provider for Claude Code's model fails before the first token, deeprelay retries the request on the next model in the key's backup list. A stream that has already started is never switched. See Backup models for the full rules.

After Claude Code is configured, setup asks whether to turn them on for the CLI's inference key. The default answer is no. On a subscription, setup suggests up to three other plan models, leaving out the ones already in the Claude Code model slots; on pay-as-you-go you type the list. In a script, pass the answer as a flag:

deeprelay setup claude-code --fallback-models deeprelay/glm-5.3,deeprelay/kimi-k3.1-pro
deeprelay setup claude-code --no-fallback
  • Setup edits the key, not Claude Code's config. It sets fallback_models on the key and writes no header or backup setting into Claude Code's files. A later change in Cloud → API Keys or with deeprelay api-keys update --fallback-model … reaches Claude Code straight away, without re-running setup.
  • The list is shared. Every tool that uses the same key gets the same backups. If the key already has a list, setup shows it and asks before replacing it.
  • Undo asks. deeprelay setup claude-code --remove asks whether to turn the key's backup models off too, and keeps them by default, since other tools may use the key. --remove --no-fallback turns them off without asking.
  • Billing stays the same. A plan-covered request only falls back to other plan models; a request billed to your balance can fall back to any chat model the key may call, at that model's price.

Why claude-* model names are rejected

A request for a Claude model ID (for example claude-sonnet-…) gets a 400 instead of being quietly mapped to some other model. deeprelay doesn't alias Claude names, so you always know which model answered, and you are billed for the model you chose. If you see this error, a model slot is not set: run deeprelay setup claude-code, or set the variables below.

Manual setup

If you'd rather not use deeprelay setup, set the same variables yourself, in your shell or in the env block of a Claude Code settings file:

export ANTHROPIC_BASE_URL=https://api.deeprelay.ai
export ANTHROPIC_AUTH_TOKEN=deeprelay_live_...
export ANTHROPIC_MODEL=deeprelay/deepseek-v4-pro
export ANTHROPIC_DEFAULT_OPUS_MODEL=deeprelay/deepseek-v4-pro
export ANTHROPIC_DEFAULT_SONNET_MODEL=deeprelay/deepseek-v4-pro
export ANTHROPIC_DEFAULT_FABLE_MODEL=deeprelay/deepseek-v4-pro
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deeprelay/deepseek-v4.1-flash
export ANTHROPIC_SMALL_FAST_MODEL=deeprelay/deepseek-v4.1-flash
  • ANTHROPIC_BASE_URL has no /v1. Claude Code appends /v1/messages itself, so https://api.deeprelay.ai/v1 would end up at /v1/v1/messages.
  • Set every model variable. A slot you leave unset falls back to a Claude model name, and that request is rejected.
  • Instead of ANTHROPIC_AUTH_TOKEN, you can put "apiKeyHelper": "/absolute/path/to/deeprelay auth token" in the settings file, so the key never sits in your shell or a file.
  • deeprelay accepts the key as x-api-key or as Authorization: Bearer, so ANTHROPIC_API_KEY works too.

What works and what doesn't

Works:

  • Tools. File reads and edits, shell commands, subagents and MCP servers you configure in Claude Code all run through normal tool calls.
  • Streaming, including keep-alive pings during long responses.
  • One tool call per turn, when asked. tool_choice with disable_parallel_tool_use: true is honoured. On a model that can't limit itself, deeprelay returns only the first tool call and the response carries x-deeprelay-ignored-params: parallel_tool_calls:enforced.
  • Thinking. Models that reason stream it as thinking blocks. deeprelay signs them, and handles them correctly when Claude Code sends them back on later turns.
  • Prompt caching. Caching happens automatically on models that support it. cache_control markers are accepted, and cached input shows up as cache_read_input_tokens in usage.
  • WebSearch. Claude Code's built-in WebSearch tool works: deeprelay runs the search and returns the result blocks Claude Code expects. See Web search below.
  • Tool search. Claude Code turns tool search on by default behind a custom base URL. deeprelay accepts the tool-search tool and its tool_reference results, and gives the model every tool's full definition upfront, so MCP tools stay callable without a retry.

Doesn't work:

  • Other server tools, such as code execution and web fetch, return a 400 that says so. Claude Code shows the error to the model, and the session carries on. WebFetch runs on your machine as an ordinary client tool, so it is not affected.
  • PDFs and documents. Document blocks are rejected with a 400.
  • Images, except on vision models. Five models can see images today: deeprelay/deepseek-v4.1-flash, deeprelay/glm-5.3-flash, deeprelay/kimi-k3, deeprelay/kimi-k3.1-pro and deeprelay/qwen3.5-9b. On those models, images you paste and images Claude Code's Read tool opens (a screenshot or a PNG in your repo) reach the model. On other models, images never break the session:
    • an image Read opens, or an image from an earlier turn, is replaced by a note telling the model that an image was there and it cannot see it, and the session carries on;
    • only an image you paste into your newest message returns a 400, which names the models that can see images. Remove the image or switch models (/model).

When deeprelay replaces or moves an image, the response carries the header x-deeprelay-ignored-params with image:omitted (replaced by a note) or image:moved (on a vision model, an image from a tool result is passed to the model right after the tool result, because most models accept tool results as text only). Forwarded images must be JPEG, PNG, GIF or WebP and at most 5 MiB each. There is no fixed limit on how many screenshots a session carries; images given by URL are capped at 32 per request. A few models accept fewer images per request, and a request over that limit returns a 400 naming it.

  • Exact token counts. POST /v1/messages/count_tokens returns an estimate, marked with the response header x-deeprelay-token-count: estimated. It tends to count high, which is safe for Claude Code's context budgeting. It is free.

Claude Code's WebSearch tool works on deeprelay. When the model calls it, Claude Code sends a short sub-request declaring Anthropic's web_search_20250305 server tool with max_uses: 8. deeprelay runs the searches, and Claude Code turns the results into the titles and links the main model reads.

  • The search model must support tool calling. Which model gets the search sub-request depends on the Claude Code version: 2.1.309 sent it to the haiku slot (ANTHROPIC_DEFAULT_HAIKU_MODEL / ANTHROPIC_SMALL_FAST_MODEL, --haiku-model), and 2.1.311 sends it to the main model. Keep both on models with tool calling. On a model without it the search fails with a 400 web_search_unsupported_model. The defaults, deeprelay/deepseek-v4-pro and deeprelay/deepseek-v4.1-flash, both support it. GET /v1/models shows "web_search": true on every model that can search.
  • Make WebSearch visible to the model. Recent Claude Code versions can hide WebSearch behind their ToolSearch tool, so the model has to look it up before it can search, and some models never do. To always offer it, set ENABLE_TOOL_SEARCH=false in your shell or in the env block of your Claude Code settings file:
{ "env": { "ENABLE_TOOL_SEARCH": "false" } }

deeprelay setup claude-code does not set this for you.

  • Allowance. On a subscription plan, searches come out of a monthly allowance: 100 searches a month on Base and 500 on Plus. Zero-result searches count. When it runs out, the model is told so, with the date it resets, and carries on without searching. An org admin can turn on paid overflow (deeprelay quota search-overflow on, or the Billing page); overflow searches are billed to your balance at cost (currently $1.00 per 1,000), and the tokens stay on the plan. deeprelay quota shows how many searches you have used.
  • Cost. Off a plan, searches are billed per search at the list price, see the API guide's Web search section (currently $2.00 per 1,000). Failed and duplicate searches are not billed. The result text the model reads is billed as ordinary input tokens.
  • Results are untrusted web content. A page can contain instructions aimed at the model, and Claude Code can run shell commands. Review the commands it proposes after a search, as you would after it reads any web page. See Prompt injection.
  • Data handling. The query the model writes is sent to a third-party search provider. See the data policy's web search exception.

Billing

  • A Claude Code request is billed exactly like a chat completion for the same model: the same per-token prices, and the same plan quota and credit.
  • Rejected requests are not billed. That includes a claude-* model name, an unsupported server tool and an unsupported image. Token counting is never billed.
  • Web searches are billed per search at the list price (currently $2.00 per 1,000), or come out of your plan's monthly search allowance. See Web search.
  • Usage and spend show the deeprelay model that answered. Check them with deeprelay usage or in the dashboard.
  • Claude Code's /cost does not show deeprelay prices. It computes cost from Anthropic's price list, which doesn't apply to deeprelay models. For what you actually spent, use deeprelay usage or the usage page in the deeprelay dashboard. For a live view in Claude Code's status line, use deeprelay quota --short, which prints one stable line with your plan usage and reset date (see Plan usage in the status line). deeprelay launch claude-code prints the real session cost on exit, with no /cost workaround needed.
  • Each response carries its own cost. The usage object gains two deeprelay fields, deeprelay_cost (USD charged for the call, 0 when your plan covers it) and deeprelay_cost_details (list price, plan-covered amount, charged amount, quota units and cache savings). A non-streaming response also sends the x-deeprelay-cost header. A streamed response carries the fields only in the final message_delta event, and sends no cost header. The figures are the ones your bill uses. Claude Code and the Anthropic SDKs ignore the extra fields.

Plan usage in the status line

Claude Code's status line can run a command and show its output. Point it at deeprelay quota --short to see your plan usage without opening the dashboard. Add this to ~/.claude/settings.json:

{
  "statusLine": {
    "type": "command",
    "command": "deeprelay quota --short"
  }
}

The line looks like this:

in:412.4M/500M out:48.1M/50M wk-in:101.0M/125M wk-out:9.2M/12.5M cap:$97.40/$100 search=37/100 resets=2026-10-03 wk-resets=2026-10-01T10:14Z

in and out are what is left of the monthly input and output allowance, wk-in and wk-out what is left under this week's caps, cap the usage backstop in dollars, search the web searches used this month, resets the UTC date the monthly meters start over, and wk-resets the UTC time both weekly caps reset (the same weekday and time every week). Without a plan it prints no subscription, so the status line never errors. The full grammar is in deeprelay quota.

Troubleshooting

Errors on /v1/messages use the Anthropic error format, so Claude Code shows them as readable messages. Each error also carries an X-Deeprelay-Error-Code header with the same code the rest of the API uses (see Errors).

"deeprelay doesn't serve Claude models"

deeprelay doesn't serve Claude models — run `deeprelay setup claude-code`, or set ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU,FABLE}_MODEL and ANTHROPIC_SMALL_FAST_MODEL to deeprelay model IDs (see deeprelay.ai/docs/claude-code).

Claude Code asked for a Claude model, so at least one model slot is not set (code claude_model_not_served). Run deeprelay setup claude-code again, or set every variable listed under Manual setup, including ANTHROPIC_DEFAULT_FABLE_MODEL and ANTHROPIC_SMALL_FAST_MODEL.

"apiKeyHelper is failing"

Claude Code couldn't get a key from the helper. Run the helper yourself to see why:

deeprelay auth token

Usually you are not logged in (run deeprelay login), or the deeprelay binary moved since setup ran (run setup again).

Settings seem to be ignored

  • Shell variables win. An ANTHROPIC_* variable exported in your shell overrides the settings file. Setup lists any it finds. Unset them, or use a clean shell.
  • Claude Code is still using your subscription. If you are logged in to a Claude subscription and ran setup at project scope, only that project uses deeprelay. Check which settings file setup wrote, and run /status in Claude Code to see the active base URL and model.

"prompt is too long"

The conversation no longer fits the model's context window (code context_length_exceeded). deeprelay returns Anthropic's own prompt is too long: N tokens > M maximum error, so Claude Code handles it as it would with Anthropic: it compacts the conversation, or asks you to run /compact. The token count is deeprelay's estimate, and M is the model's context window from deeprelay models get.

402 and 429

StatusX-Deeprelay-Error-CodeMeaning
401unauthorizedThe key is missing, invalid, revoked or expired
402insufficient_balanceOut of credit. Top up in the dashboard
402daily_limit_reached, spending_limit_reachedA spend limit on your account or key was hit
429subscription_quota_exhaustedYour plan's quota for this window is used up
429rate_limit_exceededToo many requests per second. Claude Code retries
429stream_limit_exceededToo many requests open at once on this key. Claude Code retries

Billing 402s and an exhausted plan quota tell Claude Code not to retry, so it reports them once instead of looping. Check where you stand with deeprelay billing subscription and deeprelay usage.

Still stuck? Email support@deeprelay.ai with your Claude Code version, the model ID and the exact error message.

← All docs