Claude Code with GLM-5.3: Config, Model IDs and Session Cost
Claude Code GLM setup: run GLM-5.3 and GLM-5.3 Flash with one config block. Model IDs, a 2-hour session from $0.62, and the Coding Plan compared.
Agent integrations·Published ·By RouterPlex·8 min
One API key for every model on RouterPlex: vendor list price, $0 top-up fee, from $5.
Create a key
On this page
To run Claude Code with GLM, set ANTHROPIC_BASE_URL to https://api.routerplex.com, put your RouterPlex key in ANTHROPIC_AUTH_TOKEN, and set ANTHROPIC_MODEL to glm-5.3. Use glm-5.3-flash for small background tasks. RouterPlex bills Z.ai's list price, $1.40 input and $4.40 output per 1M tokens, with a $0 top-up fee.
This GLM Claude Code guide gives you one config block, the model id for each Claude Code slot, and a dated cost table. It also compares per-token billing with Z.ai's GLM Coding Plan. You keep the Claude Code app and its tools. Only the model behind it changes.
Checked 4 November 2026: Z.ai pricing, Z.ai Claude Code guide, GLM Coding Plan overview, RouterPlex catalog, Claude Code settings. Z.ai prices and the RouterPlex catalog re-checked 10 November 2026. Rates change. Read the checkout before a large purchase.
RouterPlex publishes this guide and sells the prepaid wallet described below.
The Claude Code GLM config block
Create a RouterPlex key, export it as ROUTERPLEX_API_KEY, then run this block in the same terminal on macOS or Linux.
export ANTHROPIC_BASE_URL="https://api.routerplex.com"export ANTHROPIC_AUTH_TOKEN="$ROUTERPLEX_API_KEY"export ANTHROPIC_API_KEY=""export ANTHROPIC_MODEL="glm-5.3"export ANTHROPIC_DEFAULT_OPUS_MODEL="glm-5.3"export ANTHROPIC_DEFAULT_SONNET_MODEL="glm-5.3"export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-5.3-flash"export CLAUDE_CODE_MAX_CONTEXT_TOKENS="868928"claude
The base URL has no /v1, because the app adds /v1/messages itself. ANTHROPIC_API_KEY is set to empty so an old Anthropic key cannot take over. The context cap is GLM's 1M window minus its 131,072-token max output, as the RouterPlex Claude Code docs describe. Without it, Claude Code assumes 200,000 tokens for non-Claude ids and compacts too early.
On Windows PowerShell:
$env:ANTHROPIC_BASE_URL = "https://api.routerplex.com"$env:ANTHROPIC_AUTH_TOKEN = $env:ROUTERPLEX_API_KEY$env:ANTHROPIC_API_KEY = ""$env:ANTHROPIC_MODEL = "glm-5.3"$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "glm-5.3"$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "glm-5.3"$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "glm-5.3-flash"$env:CLAUDE_CODE_MAX_CONTEXT_TOKENS = "868928"claude
To keep the setting for every session, add an env block to ~/.claude/settings.json (on Windows, %USERPROFILE%\.claude\settings.json). Settings files cannot read shell variables, so paste the key there. Never put it in a project's .claude/settings.json, because that file is usually committed.
{"env": {"ANTHROPIC_BASE_URL": "https://api.routerplex.com","ANTHROPIC_AUTH_TOKEN": "paste-your-routerplex-key-here","ANTHROPIC_API_KEY": "","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_MAX_CONTEXT_TOKENS": "868928"}}
Before you give it a real repository, send one test call with the exact model id:
curl https://api.routerplex.com/v1/messages \-H "Authorization: Bearer $ROUTERPLEX_API_KEY" \-H "anthropic-version: 2023-06-01" \-H "content-type: application/json" \-d '{"model": "glm-5.3", "max_tokens": 64, "messages": [{"role": "user", "content": "Say ok."}]}'
Then run /status inside Claude Code. It should show the RouterPlex base URL.
GLM-5.3 or GLM-5.3 Flash for each Claude Code slot
The app has a main model and three named slots. The Haiku slot runs background work such as titles and short summaries. The Opus slot is what you get when you pick Opus in /model. Set all of them. If one slot is left empty, Claude Code asks for a Claude model there, and that slot bills at the much higher Claude rate.
| Claude Code slot | Model id | Context | Max output | Input / cached / output per 1M on RouterPlex |
|---|---|---|---|---|
| Main, Opus, Sonnet | glm-5.3 | 1M | 131K | $1.40 / $0.26 / $4.40 |
| Haiku (background) | glm-5.3-flash | 1M | 131K | $0.15 / $0.03 / $0.50 |
Both ids support tool calling in the RouterPlex catalog, and both match Z.ai's list price. The older glm-5.2 id costs the same as GLM-5.3, so there is no saving in staying on it. To cut cost further, put glm-5.3-flash in every slot. Model pages: GLM-5.3 and GLM-5.3 Flash.
What a 2-hour Claude Code session costs on GLM
Method: a 2-hour Claude Code session is modelled as 60 agent turns of 100K input and 10K output tokens. That is 6M input and 600K output in total. The cache column assumes 80% of input is read from cache (input the provider has already seen in an earlier turn). Cache hits depend on the upstream, so treat that column as "up to". These numbers are computed from list rates checked 4 November 2026, not measured.
| Model | No cache | 80% cache reads |
|---|---|---|
glm-5.3 (RouterPlex or Z.ai per-token) | $11.04 | $5.57 |
glm-5.3-flash (RouterPlex or Z.ai per-token) | $1.20 | $0.62 |
| Claude Sonnet 5.5, Anthropic list | $18.00 | $8.88 |
| Claude Opus 5.5, Anthropic list | $36.00 | $17.76 |
Sources: RouterPlex catalog, Z.ai pricing, Claude pricing, all checked 4 November 2026. Claude cache writes are left out, which flatters the Claude rows slightly.
Flash runs a long session for about a dollar. GLM-5.3 costs roughly nine times as much. Input makes up about three quarters of the no-cache bill, so cache hits matter more than short replies.
Per-token billing vs the Z.ai GLM Coding Plan
Z.ai sells the GLM Coding Plan as a monthly subscription. Its devpack overview lists Lite, Pro and Max tiers, "starting at just 18 USD per month". Every tier includes GLM-5.3 and GLM-5.3 Flash. Each plan has a 5-hour credit allowance and a weekly one: Lite 2,000 and 10,000, Pro 12,000 and 60,000, Max 28,000 and 140,000. Off-peak use costs half the usual credits. Z.ai does not state how many tokens one credit buys, so we cannot convert a plan into dollars per session.
On our session model, one heavy GLM-5.3 session costs $5.57 to $11.04 per token. If you code with GLM most days and stay inside the limits, the plan is likely the better deal. Per-token billing wins when you code a few times a month or want other models on the same key. It also wins when you need a hard dollar cap instead of a credit window that resets.
Using Z.ai's own Anthropic endpoint
Z.ai runs its own Anthropic-compatible endpoint at https://api.z.ai/api/anthropic and publishes a Claude Code guide. It uses the same variables with a Z.ai API key. The manual config there maps the Opus and Sonnet slots to glm-5.3[1m] and Haiku to glm-5.3-flash[1m]. The [1m] suffix turns on the 1M context on Z.ai's side. Do not copy that suffix into a RouterPlex config. Use the plain catalog ids shown above.
If you only ever use GLM, and you code every day, Z.ai direct with a Coding Plan is a sensible choice.
A RouterPlex key helps in other cases. One key switches between GLM, DeepSeek, Kimi, Qwen and other catalog models by changing one variable. Each key can carry a hard USD cap, so an agent loop stops at the number you set. Card or crypto top-ups carry a $0 fee, and the balance stops at $0 instead of going negative.
Routing with Claude Code Router instead
Claude Code Router (CCR) is a local proxy that sits between Claude Code and your providers. It can send different kinds of requests to different models, such as long-context work to one model and background tasks to another. Use it if you want rules that the four Claude Code model variables cannot express. For most GLM setups, the plain config block above is enough and has fewer moving parts. The Claude Code Router setup guide shows how to point CCR at RouterPlex and add GLM models.
Claude Code GLM troubleshooting
401 or a login prompt
The app cannot find your key, or an old ANTHROPIC_API_KEY is taking precedence. Put the RouterPlex key in ANTHROPIC_AUTH_TOKEN and set ANTHROPIC_API_KEY to empty. Do not run /login. That signs in to Anthropic, not RouterPlex. If you see a warning about two credential sources, run /logout once.
404 or 400 model not found
The id is wrong. GLM ids on RouterPlex are lowercase with a dot in the version (glm-5.3, glm-5.3-flash). Z.ai's capitalised names such as GLM-5.3-Flash and the [1m] suffix are for Z.ai's own endpoint. Copy the id from the model catalog and check every model variable, including the Opus and Haiku slots.
Claude charges on the bill
One slot still points at a Claude model, which bills at the Claude rate. Set ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL to GLM ids, then restart claude.
402 payment required
Your balance or the key's budget is used up. Retrying will not help. The error message carries a billing link. Top up or raise the key budget, then rerun. Details are in the errors docs.
429 too many requests
You hit a rate limit or a rolling-window budget. Wait a few seconds and retry with backoff. Long agent loops with many parallel tool calls hit this first.
Tool calls or file edits fail
Some models follow Claude Code's tool format less reliably than Claude. If edits keep failing on Flash, move the main model back to glm-5.3 and keep only the Haiku slot on Flash. Run a small read-only task first to check the round trip.
Context length errors
Set CLAUDE_CODE_MAX_CONTEXT_TOKENS to 868928 so Claude Code compacts before it overruns the 1M window. Run /compact by hand on very long sessions.
Set a hard budget on the Claude Code key
An agent left running overnight can make hundreds of calls. Give Claude Code its own RouterPlex key and set a hard lifetime budget on it, such as $5 for a first test. When the key reaches that number, requests stop with a 402 and nothing more is charged. Your account balance also stops at $0, so a runaway loop cannot push you into debt. Set the budget in the dashboard when you create the key. The keys and budgets docs show how. Use one key per tool or repository so you can see which agent spent what.
Try GLM-5.3 in Claude Code with $1 of test credit, no card. Compare prices on the GLM-5.3 model page, or read the full GLM-5.3 API pricing guide.
Common questions
Frequently asked questions
Can Claude Code use GLM?
Yes. Claude Code sends Anthropic Messages requests to whatever ANTHROPIC_BASE_URL points at, and it accepts a non-Claude model id in ANTHROPIC_MODEL. Point it at https://api.routerplex.com with your RouterPlex key in ANTHROPIC_AUTH_TOKEN, then set the model variables to glm-5.3 and glm-5.3-flash. Z.ai also runs its own Anthropic-compatible endpoint at https://api.z.ai/api/anthropic, with a Claude Code guide in its GLM Coding Plan docs. Either route keeps the Claude Code app, its tools and its workflow. Only the model behind it changes. Checked 4 November 2026.
Which GLM model should I use in Claude Code?
Use glm-5.3 as the main model and for the Opus and Sonnet slots. Put glm-5.3-flash in the Haiku slot, which runs background work such as titles and short summaries. Both have a 1M-token context, 131K max output and tool calling in the RouterPlex catalog. GLM-5.3 costs $1.40 input and $4.40 output per 1M tokens. GLM-5.3 Flash costs $0.15 and $0.50. If cost matters more than depth, run Flash in every slot. Z.ai's own Claude Code docs use the same split. Prices checked 4 November 2026 at https://routerplex.com/api/models and https://docs.z.ai/guides/overview/pricing.
How much does GLM cost in Claude Code?
A 2-hour session, modelled as 60 turns of 100K input and 10K output tokens, costs $11.04 on glm-5.3 with no cache hits. With 80% of input read from cache it drops to about $5.57. The same session on glm-5.3-flash costs $1.20 with no cache and $0.62 with cache. RouterPlex bills Z.ai's list price, so Z.ai direct per-token billing gives the same numbers. For scale, Claude Sonnet 5.5 at Anthropic list price makes the same session $18.00 without cache. These figures are computed from list rates checked 4 November 2026, not measured from a live session.
Do I need the GLM Coding Plan to use GLM in Claude Code?
No. The GLM Coding Plan is Z.ai's monthly subscription, starting at 18 USD per month for the Lite tier according to Z.ai's devpack overview. It gives credits that reset every 5 hours and every week. You can instead pay per token. Through RouterPlex you need no Z.ai account at all. You top up a prepaid USD balance by card or crypto with a $0 top-up fee and a $5 minimum, and the balance stops at $0. If you code with GLM most days, the plan may cost less. If you code now and then, or switch models, per-token billing is easier to predict. Checked 4 November 2026.
Is GLM-5.3 Flash still on promotion?
No. Z.ai ran a launch promotion on GLM-5.3 Flash at $0.075 input and $0.25 output per 1M tokens, and it ended on 9 September 2026. The current Z.ai list price is $0.15 input, $0.03 cached input and $0.50 output per 1M tokens. RouterPlex bills that list price with 0% markup. Z.ai still marks cached input storage as limited-time free on its pricing page, with no end date stated. Checked 4 November 2026 at https://docs.z.ai/guides/overview/pricing and the RouterPlex catalog.
How do I switch Claude Code back to Claude models?
Unset the variables you exported, or delete the env block from ~/.claude/settings.json, then restart claude. With no ANTHROPIC_BASE_URL set, Claude Code goes back to Anthropic and asks you to log in with a Claude plan or an Anthropic API key. To use Claude through RouterPlex instead, keep the base URL and key and set the model variables to a Claude id from the catalog, such as claude-sonnet-4-6.
Run the smallest paid test.
Add $5, cap the key, and verify the result with your own workload. No subscription, and credit never expires — a first top-up of $25+ is matched with $25 extra.



