Claude Code

Written for Claude Code 2.1.287 (npm latest), from its documentation. Claude Code speaks the Anthropic Messages API, and zdr.sh serves that API at its origin, so one settings block points the whole client at us.

Anthropic does not support routing Claude Code to non-Claude models through a gateway; the variables below are how the client treats an id it does not recognise.

Settings#

Put this in ~/.claude/settings.json, so the credential is never committed:

json
{  "env": {    "ANTHROPIC_BASE_URL": "https://api.zdr.sh",    "ANTHROPIC_AUTH_TOKEN": "duck-...",    "ANTHROPIC_MODEL": "glm-5.3",    "ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.3",    "ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.3",    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5.3-flash",    "CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-v4.1-flash",    "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1048576",    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"  }}
VariableWhy it is set
ANTHROPIC_BASE_URLThe origin only, no /v1: Claude Code appends the path
ANTHROPIC_AUTH_TOKENSent as a bearer token
ANTHROPIC_MODELThe main model; /model and --model override it per session
ANTHROPIC_DEFAULT_OPUS_MODELWhat the Opus alias resolves to
ANTHROPIC_DEFAULT_SONNET_MODELWhat the Sonnet alias resolves to
ANTHROPIC_DEFAULT_HAIKU_MODELWhat the Haiku alias resolves to; also the model for background tasks
CLAUDE_CODE_SUBAGENT_MODELThe model subagents run on
CLAUDE_CODE_MAX_CONTEXT_TOKENSThe window for an unknown id, which defaults to 200K
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICTurns off auto-updates, telemetry, error reporting and feature fetching

The mapping is an example: any zdr.sh id fits any alias. Models has the ids and their windows.

Things to know#

  • Credential. ANTHROPIC_AUTH_TOKEN is the reliable one. ANTHROPIC_API_KEY is sent as x-api-key and needs a one-time approval in interactive mode. zdr.sh accepts either header.
  • Claude model ids. A Messages request for a claude- id is served by the model the key maps that family to. The mapping is in the key's settings in the dashboard; with it off, the request is refused with a 404 that says so.
  • An existing claude.ai login is not replaced by the base URL alone. Always set a zdr.sh credential as well.
  • Context. An unresolved id is assumed to have a 200K window, so CLAUDE_CODE_MAX_CONTEXT_TOKENS=1048576 is what lets a long session use the full window.
  • Output. For an unresolved id the output cap defaults to 32,000 and is capped at 128,000; set CLAUDE_CODE_MAX_OUTPUT_TOKENS up to 128000 for the models that allow more.
  • Token counting. zdr.sh serves /v1/messages/count_tokens, so Claude Code uses real counts.
  • Thinking. Requests carry adaptive thinking and effort, and reasoning comes back as thinking blocks.
  • Rotating keys in fleets. apiKeyHelper can print a fresh key; its output is cached for five minutes and the helper re-runs on a 401 or 403.
  • /status shows the base URL and where the credential came from, which is the quickest way to confirm the setup.