How to Use Claude Code with GLM-5.2, DeepSeek & Qwen
Claude Code is a superb coding agent, but running it on Claude Opus is expensive — and on routine coding tasks, our own tests show cheaper models match it. The good news: Claude Code speaks the Anthropic Messages API and reads one environment variable, so you can point it at GLM-5.2, DeepSeek, Qwen, or your own gateway in under a minute. Below is verified, copy-paste config for each path (checked against the official docs, June 2026), the gotchas that actually trip people up, and what you really save.
Why run Claude Code on a cheaper model
Claude Code is a first-class coding agent — but it's token-hungry, and on Claude Opus those tokens add up fast. The case for swapping the model is simple: on routine coding, cheaper models keep up. In our executed coding benchmark, GLM-5.2 and Qwen3 Coder Next both matched Claude Opus 4.7's perfect score — at a fraction of the price. So for day-to-day work you can keep the Claude Code experience and change what's behind it.
How it works
Claude Code is hardwired to speak the Anthropic Messages API (POST /v1/messages) and to read one environment variable for where to send requests:
ANTHROPIC_BASE_URL— the server's root URL. Set the root only, with no trailing/v1— Claude Code appends/v1/messagesitself, so adding/v1produces a broken/v1/v1/messages.- A credential — either
ANTHROPIC_AUTH_TOKEN(sent asAuthorization: Bearer) orANTHROPIC_API_KEY(sent asx-api-key). If you weren't told which, tryANTHROPIC_AUTH_TOKENfirst; a401means switch to the other.
Point those at any endpoint that serves the Anthropic wire format and Claude Code runs on that model. GLM, DeepSeek, and Qwen all publish official endpoints for exactly this.
Path 1: GLM-5.2 (Z.ai)
Z.ai exposes an official Anthropic-compatible endpoint for the GLM line. Get a key at z.ai/model-api, then:
export ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic
export ANTHROPIC_AUTH_TOKEN=YOUR_ZAI_API_KEY
export API_TIMEOUT_MS=3000000
# optional — pin GLM behind Claude Code's tiers (server-side mapping is on by default)
export ANTHROPIC_DEFAULT_OPUS_MODEL=glm-5.2[1m]
export ANTHROPIC_DEFAULT_SONNET_MODEL=glm-5.2[1m]
export ANTHROPIC_DEFAULT_HAIKU_MODEL=glm-4.5-air
claude
That's it — claude now runs on GLM-5.2. Notes: the [1m] suffix selects the 1M-context variant (add CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000 to use it fully). Use the /api/anthropic path — not the OpenAI-style /api/coding/paas/v4. Clear any real ANTHROPIC_API_KEY so it doesn't conflict. Verified with Claude Code 2.0.14+. The GLM Coding Plan has Lite/Pro/Max tiers — confirm current pricing at z.ai/subscribe.
Path 2: DeepSeek & Qwen
Both ship first-party Anthropic endpoints, so no extra tooling is needed.
DeepSeek (its Claude Code path now uses the V4 line):
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=YOUR_DEEPSEEK_API_KEY
export ANTHROPIC_MODEL=deepseek-v4-pro
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4-flash
claude
The legacy V3.2 aliases deepseek-chat / deepseek-reasoner still resolve but are being deprecated (2026-07-24), after which they map to deepseek-v4-flash.
Qwen — the simplest route is Alibaba's Claude Code proxy, which auto-serves Qwen3-Coder (no model variable needed):
export ANTHROPIC_BASE_URL=https://dashscope-intl.aliyuncs.com/api/v2/apps/claude-code-proxy
export ANTHROPIC_AUTH_TOKEN=YOUR_DASHSCOPE_API_KEY
claude
Model Studio also offers plan-specific Anthropic endpoints (Coding Plan https://coding-intl.dashscope.aliyuncs.com/apps/anthropic, model qwen3.7-plus). The current recommended coder model is qwen3-coder-next.
Path 3: one key via a gateway
Per-vendor keys mean juggling several logins and bills. A gateway collapses that to one credential and lets you switch the backing model without re-configuring. The requirement: the gateway must serve an Anthropic Messages endpoint. Gateways built on new-api do — they expose a native POST /v1/messages (using x-api-key + anthropic-version: 2023-06-01), so they work with Claude Code directly:
export ANTHROPIC_BASE_URL=https://your-gateway.example.com # root only, no /v1
export ANTHROPIC_API_KEY=YOUR_GATEWAY_KEY # new-api maps this to x-api-key
# choose whichever models your gateway exposes
export ANTHROPIC_DEFAULT_OPUS_MODEL=glm-5.2
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3-coder-next
claude
This is how a DataLLM Lab key works with Claude Code: one key, and you route Opus-tier requests to GLM-5.2 and the fast/background tier to a cheap coder, all from the same endpoint. To reach any model that isn't already Anthropic-format, the community tool claude-code-router (@musistudio/claude-code-router) translates between Claude Code and OpenAI-style providers — install it, configure ~/.claude-code-router/config.json with your provider and a Router block (default, background, think, longContext, webSearch), and launch with ccr code.
Gotchas that trip people up
The connection is simple; these are the things that actually cause failed sessions (all from the official troubleshooting docs):
- Root URL only. No trailing
/v1onANTHROPIC_BASE_URL, or you get/v1/v1/messages. - Wrong credential header.
401? Switch betweenANTHROPIC_AUTH_TOKEN(Bearer) andANTHROPIC_API_KEY(x-api-key). For new-api gateways, useANTHROPIC_API_KEY. - 400s on Anthropic-only fields. Some non-Anthropic upstreams reject experimental beta fields — set
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1. - 403 with an HTML body. A web application firewall is blocking the request body — Claude Code's prompts contain XML-style tags that trip XSS rules. Exempt the
/v1/messagespath from body inspection. - MCP tool search disabled. On a non-first-party host it's off unless you set
ENABLE_TOOL_SEARCH=true. - Slack, web, and Remote Control ignore your gateway. They always use Anthropic's own API — gateway variables apply to the CLI only.
What you actually save
Here's a modeled monthly Claude Code workload — 80M input and 25M output tokens, the "coding agent" profile — priced on each model:
| Model behind Claude Code | Monthly cost (80M in / 25M out) | vs Opus | Coding test (from our benchmark) |
|---|---|---|---|
| Claude Opus 4.7 | $1,025 | 1× | 6/6 |
| GLM-5.2 | $222 | 4.6× cheaper | 6/6 |
| Qwen3 Coder Next | $28.80 | 36× cheaper | 6/6 |
| DeepSeek V3.2 | $26.90 | 38× cheaper | 5/6 |
The pattern from the benchmark holds here: the cheap models deliver the same correctness on routine work, so the practical setup is cheap-first with escalation — run Claude Code on GLM-5.2 or a cheap coder day-to-day, and switch back to Opus for the genuinely hard sessions. With a gateway that's a one-line model change, not a re-install.
One key for Claude Code — and 300+ models
Point Claude Code at DataLLM Lab and route GLM-5.2, Qwen, DeepSeek or Claude from a single OpenAI- and Anthropic-compatible endpoint.
FAQ
Can Claude Code use a non-Claude model?
Yes — it speaks the Anthropic Messages API and reads ANTHROPIC_BASE_URL. Point that at GLM-5.2, DeepSeek, Qwen, or your gateway, supply that endpoint's key, and Claude Code runs on that model. GLM/DeepSeek/Qwen all ship official endpoints.
How do I use Claude Code with GLM-5.2?
Set ANTHROPIC_BASE_URL=https://api.z.ai/api/anthropic, ANTHROPIC_AUTH_TOKEN=your Z.ai key, API_TIMEOUT_MS=3000000, then run claude. Server-side mapping points the tiers at GLM automatically. Key at z.ai/model-api.
Is it cheaper to run Claude Code on GLM-5.2 or DeepSeek?
Both are far cheaper than Opus. Modeled monthly: Opus ~$1,025, GLM-5.2 ~$222, DeepSeek and Qwen under $30. GLM-5.2 and Qwen matched Opus's score in our test.
What is ANTHROPIC_BASE_URL?
The variable telling Claude Code which server to use. Set the root URL only (no trailing /v1); pair with ANTHROPIC_AUTH_TOKEN (Bearer) or ANTHROPIC_API_KEY (x-api-key). 401 → switch credential.
Can I use Claude Code with my own gateway?
Yes if it serves an Anthropic Messages endpoint. new-api-based gateways expose a native /v1/messages, so set ANTHROPIC_BASE_URL to your gateway root and ANTHROPIC_API_KEY to your key. A DataLLM Lab key works this way.
How do I use Claude Code with Qwen or DeepSeek?
DeepSeek: base https://api.deepseek.com/anthropic, model deepseek-v4-pro. Qwen: base https://dashscope-intl.aliyuncs.com/api/v2/apps/claude-code-proxy (auto-serves Qwen3-Coder). Both use ANTHROPIC_AUTH_TOKEN.
Does running Claude Code on another model break features?
Mostly it just works. For 400 errors set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1; MCP tool search needs ENABLE_TOOL_SEARCH=true on non-first-party hosts; Slack/web/Remote Control always use Anthropic's API.
Is using Claude Code with another model official?
The ANTHROPIC_BASE_URL mechanism is documented by Anthropic, and Z.ai, DeepSeek, and Alibaba publish official Claude Code guides. Anthropic doesn't audit specific third-party gateways, but the method is supported.
Why is my gateway returning 401 or 403?
401 = wrong credential variable (switch AUTH_TOKEN ↔ API_KEY). 403 with HTML body = a firewall blocking the request body (exempt /v1/messages from body inspection). Also check the base URL is root-only.
DataLLM Lab