How to Use Z.AI with Claude Code
Claude Code reads an Anthropic-compatible endpoint, and Z.AI publishes one for the GLM Coding Plan.
To use Z.AI with Claude Code, set ANTHROPIC_BASE_URL to https://api.z.ai/api/anthropic and ANTHROPIC_AUTH_TOKEN to a key from your Z.AI account. At Layer3Labs, we connect third-party model endpoints to the agent tooling that powers both client systems and our own sites.
The setup itself is simple: four steps and one config file. The details that tend to trip people up come later. The GLM Coding Plan supports only two models, and usage is measured against two clocks at once.
What You Need Before the First Command
Three things have to exist before Claude Code can reach Z.AI. You need the Claude Code command-line interface (CLI) on your machine, a Z.AI account, and an application programming interface (API) key issued under it.
The GLM Coding Plan is the subscription that makes those keys usable at a flat monthly rate instead of per token. Z.AI publishes one price in its developer docs, 18 USD per month as a starting figure, and our GLM Coding Plan guide covers the tier breakdown.
- The Claude Code CLI, installed with
npm install -g @anthropic-ai/claude-codeso theclaudecommand exists in your shell - A Z.AI account, created at z.ai/model-api, which is what a key gets issued against
- An API key from the key list. This is the string Claude Code sends as its auth token, and you can revoke it from the same page.
- A GLM Coding Plan subscription from z.ai/subscribe if you want plan credits rather than pay-per-token billing

First Month Free
Get one month of Starlink free when you sign up through this link. Fast, reliable internet at home and on the go.
Set Up Z.AI in Claude Code in Four Steps
Z.AI's own Claude Code page gives four steps, and the third one carries the whole integration: six environment variables written into ~/.claude/settings.json under an env key.
Every variable name in that block belongs to Claude Code. Only the values are Z.AI's. That is why nothing has to be patched, forked, or proxied to make the swap work.
| Variable | Value |
|---|---|
ANTHROPIC_AUTH_TOKEN | your Z.AI API key |
ANTHROPIC_BASE_URL | https://api.z.ai/api/anthropic |
ANTHROPIC_DEFAULT_HAIKU_MODEL | glm-5.3-flash |
ANTHROPIC_DEFAULT_SONNET_MODEL | glm-5.3 |
ANTHROPIC_DEFAULT_OPUS_MODEL | glm-5.3 |
API_TIMEOUT_MS | 3000000 |
The three model variables decide which GLM model answers each Claude Code tier. Whatever the session treats as Haiku goes to GLM-5.3-Flash. Sonnet and Opus both go to GLM-5.3, so you end up with one cheap fast model and one strong one. API_TIMEOUT_MS at 3000000 gives a long agent turn room to finish before the client stops waiting for it.
- 1. Install the CLI with
npm install -g @anthropic-ai/claude-code. - 2. Register at z.ai/model-api and create a key at z.ai/manage-apikey/apikey-list.
- 3. Add the six variables above to the
envobject in~/.claude/settings.json, keeping the file parseable. - 4. Open a NEW terminal,
cdinto your project, runclaude, and answer Yes at the API key prompt.
Verify That Claude Code Is Calling Z.AI
Verification is one prompt in a fresh terminal, followed by a look at your Z.AI usage. A config file that looks right proves nothing until a request has gone out and come back.
Open a new terminal so the shell picks up the change, move into a project directory, and run claude. The client asks you to confirm the API key the first time it sees one. Answer Yes, send a one-line prompt, and wait for the reply.
Then check the Z.AI side. Usage against the key shows on the billing page. A reply that arrives with nothing recorded against your key means Claude Code answered from somewhere other than the endpoint you configured. The usual cause is a second copy of ANTHROPIC_BASE_URL exported in a shell profile.
- Open a NEW terminal. An existing session keeps the environment it started with and will not see the edit.
- Run
claudeinside a project directory and answer Yes at the API key confirmation prompt. - Send one short prompt and confirm a reply comes back at all.
- Confirm the usage on Z.AI billing, which is the proof the request reached Z.AI and not somewhere else.
- If nothing is recorded, run
env | grep ANTHROPICand remove any duplicate exports before touching the config again.
Which GLM Models the Coding Plan Serves
The GLM Coding Plan serves exactly two models, GLM-5.3 and GLM-5.3-Flash. Older model ids still work, but not in the way their names suggest.
A request for GLM-5.2 or GLM-5.1 is routed to GLM-5.3, and a request for GLM-4.7 is routed to GLM-5.3-Flash. The call does not fail, so the substitution is invisible unless you go looking for it. If you pinned a model id months ago because a benchmark run favoured it, that pin no longer selects anything.
GLM-5.3 shipped on 17 August 2026 as a post-training update on the same base model as GLM-5.2, by Z.AI's own account. The flagship carries 753 billion parameters and a 1-million-token maximum context. GLM-5.3-Flash carries 320 billion, and our GLM-5.3 guide goes through what changed.
- Served directly:
glm-5.3andglm-5.3-flash, which is what the three model variables should point at - GLM-5.2 and GLM-5.1 requests: routed to GLM-5.3, so an old pin silently changes model
- GLM-4.7 requests: routed to GLM-5.3-Flash, the cheap tier rather than the flagship
- Every tier also includes Vision Understanding plus the Web Search, Web Reader, and Zread Model Context Protocol (MCP) servers, so a session can search and read pages without a second subscription
How the 5-Hour and Weekly Credit Windows Work
The GLM Coding Plan meters two windows at once: a rolling 5-hour allowance and a weekly one. Whichever runs out first stops the session, which is the behaviour that catches Claude Code users off guard.
| Tier | Credits per 5 hours | Credits per week |
|---|---|---|
| Lite | 2,000 | 10,000 |
| Pro | 12,000 | 60,000 |
| Max | 28,000 | 140,000 |
Do the division and the shape of the plan appears. Every tier sets the weekly allowance at exactly five times its 5-hour figure, so you can spend a full 5-hour window five times a week and no more. Paying for a higher tier buys bigger windows, not more of them.
Claude Code spends credits in bursts rather than evenly, because one agent turn can read and rewrite many files before it answers. A single long refactor can therefore drain a window that would have carried a whole afternoon of short questions. Z.AI gives you one way to stretch a window. The DevPack docs describe a 50% off-peak deduction, so the same job costs half the credits when it runs outside busy hours.
- Both windows apply at the same time, and the tighter one is what stops you
- Off-peak requests deduct 50% of the credits, per the Z.AI DevPack docs
- Weekly allowance is five times the 5-hour figure on Lite, Pro, and Max alike
- Before assuming a key broke, check both counters. Running dry in one window while the other has room looks identical to an auth failure from inside the session.
Common Failures When Claude Code Points at Z.AI
Most failed setups come from configuration that exists in two places at once rather than from the endpoint itself. The six variables are simple. Having two copies of them is not.
Across the automation we run on our own sites, the same shape of bug turns up every time a model endpoint gets swapped. The config file says one thing, a leftover environment variable says another, and the request that goes out is the one nobody edited. Check for duplicates before you re-read the docs.
- 1. Edited the wrong file. Z.AI documents
~/.claude/settings.json, the user-level file, which is not the same as a project.claude/settings.json. - 2. Reused the old terminal. The session keeps the environment it started with, so open a new one and run
claudeagain. - 3. A duplicate
ANTHROPIC_AUTH_TOKENorANTHROPIC_BASE_URLexported in a shell profile. Unset the shell copy so one source remains. - 4. A trailing comma in
settings.json. One stray character makes the file unreadable, and none of the six variables apply. - 5. Asking for a model the plan does not serve. GLM-5.2 and GLM-4.7 requests are re-routed rather than rejected, so the run succeeds on a model you did not choose.
- 6. Out of credits in one window while the other still has room. Check the 5-hour and weekly counters before you regenerate the key.
GLM Coding Plan or Pay-per-Token API for Claude Code
The GLM Coding Plan is the route Z.AI documents for Claude Code, and the pay-per-token API is documented against a different base URL. Z.AI publishes the Anthropic-compatible endpoint only on its Claude Code page inside the DevPack docs.
The general quick-start documents https://api.z.ai/api/paas/v4/ with an OpenAI-compatible chat/completions path and says nothing about the Anthropic endpoint. Treat those as two separately documented paths rather than one integration, and read both pages before you build anything that depends on either staying put.
| Criterion | GLM Coding Plan | Pay-per-token API |
|---|---|---|
| Claude Code setup Z.AI documents | Yes, on the DevPack Claude Code page | Not documented there |
| Price basis | Credits, from 18 USD per month | GLM-5.3 at $1.40 per million input tokens and $4.40 per million output |
| Models reachable | GLM-5.3 and GLM-5.3-Flash only | The full price list, including $0 models such as GLM-4.7-Flash |
| What stops you | The 5-hour and weekly credit windows | Your own spend |
| Verdict | Steady daily coding at a fixed monthly cost | Bursty work, or models the plan will not serve |
This is the wrong route for a team whose source code cannot leave its own network. Z.AI publishes the GLM-5.3 weights on Hugging Face under a bespoke licence named glm-5.3, so self-hosting is the alternative. Our guide to running GLM locally covers the hardware that takes.
Two things would change this recommendation. If Z.AI published Pro and Max prices in the DevPack docs, you could size the plan against token rates instead of guessing at it. If the plan went back to serving GLM-5.2 and GLM-4.7 directly, the routing caveat above would stop mattering. Until then, create the key, paste the six variables into ~/.claude/settings.json, and send one prompt to confirm your Z.AI Claude Code setup is reaching GLM-5.3.
Frequently Asked Questions
- Set
ANTHROPIC_BASE_URLtohttps://api.z.ai/api/anthropicandANTHROPIC_AUTH_TOKENto a Z.AI API key in theenvblock of~/.claude/settings.json. Then map the model tiers:ANTHROPIC_DEFAULT_HAIKU_MODELtoglm-5.3-flash, and bothANTHROPIC_DEFAULT_SONNET_MODELandANTHROPIC_DEFAULT_OPUS_MODELtoglm-5.3. Open a new terminal, runclaude, and confirm the key prompt with Yes. - Z.AI publishes one GLM Coding Plan price in its developer docs, 18 USD per month as a starting figure. Per-tier Pro and Max prices are not published there, and the numbers on third-party sites disagree with each other, so check z.ai/subscribe for the current figure. On the pay-per-token API, GLM-5.3 is $1.40 per million input tokens and $4.40 per million output.
- No free GLM Coding Plan tier is published. Z.AI does list $0 models on its API price sheet, including GLM-4.7-Flash, GLM-4.5-Flash, and GLM-4.6V-Flash. The Coding Plan itself serves only GLM-5.3 and GLM-5.3-Flash, and GLM-5.3-Flash is cheap rather than free at $0.075 per million input tokens.
- GLM-5.3 or GLM-5.3-Flash, and nothing else. Requests for GLM-5.2 and GLM-5.1 are routed to GLM-5.3, and GLM-4.7 requests go to GLM-5.3-Flash. An older model id in your config no longer selects the model it names.
- No. The setup only changes environment variables that Claude Code reads at startup, so the same install can point at either provider. Deleting the six variables from
~/.claude/settings.jsonand opening a new terminal returns the client to its default behaviour.
Wiring Z.AI into Your Team Tooling?
Book a free 30-minute AI workflow audit with Layer3 Labs. We will look at where a GLM Coding Plan endpoint fits your existing Claude Code work, what the credit windows will cost you at your real usage, and which jobs belong on a pay-per-token key instead.
Book Now