Codex CLI runs happily on GLM. Z.AI exposes an OpenAI-compatible endpoint — exactly what Codex expects — so you add it as a custom provider, set the wire protocol, and point Codex at GLM-5 or the cheaper GLM-5-Turbo. Combined with the GLM Coding Plan, it’s a low-cost way to use a fast agent without OpenAI’s rates.
This is the Windows config, the gotcha to avoid, and the plan options. For Codex’s general provider model, see Codex CLI custom provider setup.
Step 1: Codex CLI and a Z.AI key
Install Codex CLI per its docs. Sign up at Z.AI and get a key — either pay-per-token or via the GLM Coding Plan (from $18/month). On Windows, env vars are cleaner in WSL — see Codex CLI on Windows with WSL.
Step 2: Add GLM to config.toml
Codex reads ~/.codex/config.toml. Add a Z.AI provider using its OpenAI-compatible endpoint:
model = "glm-5"
model_provider = "zai"
[model_providers.zai]
name = "Z.AI GLM"
base_url = "https://api.z.ai/api/paas/v4"
env_key = "ZAI_API_KEY"
wire_api = "chat"
Export the key and run:
export ZAI_API_KEY="your-zai-key"
codex
Confirm the exact base URL in Z.AI’s docs.
Step 3: Pick the model
GLM models in Codex (by plan)
| glm-5 | Flagship; Pro plan |
|---|---|
| glm-5-turbo | Fast, cheaper; all plans — good default |
| glm-4.7 | Previous flagship; all plans |
If glm-5 returns an access error, your plan tier doesn’t include it — switch the model to glm-5-turbo. See GLM-4.6 vs GLM-5 vs GLM-5-Turbo to choose.
Pricing and the coding plan
GLM bills two ways, both usable with Codex:
- GLM Coding Plan — flat from $18/month, with rolling-window usage caps (commonly per 5 hours). Best for heavy use.
- Pay-per-token — standard API rates, best for light use.
See GLM Coding Plan setup. Confirm current rates and whether the plan key works for direct API/Codex use on Z.AI’s docs.
Troubleshooting
- Format/streaming errors — missing
wire_api = "chat", or you used the/anthropicURL. - Auth errors —
ZAI_API_KEYnot set in the shell. - Access denied on glm-5 — plan tier doesn’t include it; use
glm-5-turbo. - Changes ignored — restart Codex;
config.tomlloads at startup.
GLM-5 + Codex checklist
- Codex CLI installed; Z.AI key or plan active
- [model_providers.zai] block with the OpenAI (paas/v4) URL
- wire_api = "chat" set
- model set to a GLM your plan includes
- ZAI_API_KEY exported; Codex restarted
Wrapping up
Using GLM-5 with Codex CLI is a config.toml edit: a [model_providers.zai] block on Z.AI’s OpenAI-compatible endpoint, wire_api = "chat", and a model your plan covers (glm-5 on Pro, glm-5-turbo everywhere). Export the key, restart Codex, and you’ve got a fast agent on a cheap backend.
To run GLM with other tools, see run GLM-5 with Claude Code or GLM + OpenCode.