How-To

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.

How to use Claude Code with GLM-5.2, DeepSeek and Qwen - verified config and cost savings

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 this is sourced. Every config block below is verified against the official docs (Z.ai, DeepSeek, Alibaba Cloud Model Studio, code.claude.com, new-api) as of June 2026. Cost figures combine our own executed benchmark with a transparent monthly model (methodology below). We flag the one path that's community tooling vs the officially-documented ones. Primary sources: Z.ai docs, DeepSeek Claude Code, Claude Code gateway docs.

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:

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):

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:

Modeled monthly Claude Code cost by backing model80M input / 25M output tokens · June 2026Claude Opus 4.7$1,025GLM-5.2$222Qwen3 Coder Next$29DeepSeek V3.2$27
Chart: DataLLM Lab — modeled monthly cost of a Claude Code workload (80M input / 25M output tokens), June 2026. GLM-5.2, Qwen and DeepSeek (highlighted) are a fraction of Opus.
Model behind Claude CodeMonthly cost (80M in / 25M out)vs OpusCoding test (from our benchmark)
Claude Opus 4.7$1,0256/6
GLM-5.2$2224.6× cheaper6/6
Qwen3 Coder Next$28.8036× cheaper6/6
DeepSeek V3.2$26.9038× cheaper5/6
Methodology. Monthly cost = input_price × 80M + output_price × 25M, using catalog rates (GLM-5.2 $1.40/$4.40; Qwen3 Coder Next $0.11/$0.80; DeepSeek V3.2 $0.23/$0.34; Claude Opus 4.7 $5/$25). The "coding test" column is the pass rate from our executed 6-task benchmark. Your real spend depends on how much you use Claude Code; the ratios hold.

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.

Written by
Kevin Fan

Founder of DataLLM Lab, the unified LLM gateway. Kevin tests models the boring way — same prompts, real costs, unedited outputs — and writes up what the runs actually show.

One API for every model

One API, every model.

Get a single API key for Claude Opus 4.7, GPT-5.4, and 300+ more — with automatic price comparison and routing to the best model for every request.