Skip to content

Use GLM-5 With Codex CLI on Windows

Configure Codex CLI to use GLM-5 on Windows through Z.AI's OpenAI-compatible endpoint. config.toml provider, wire_api, model choice, coding plan, and fixes.

MGMCSA Guru Team July 4, 2026 3 min read
Codex CLI on Windows configured to use GLM-5 via Z.AI

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 /anthropic URL.
  • Auth errorsZAI_API_KEY not set in the shell.
  • Access denied on glm-5 — plan tier doesn’t include it; use glm-5-turbo.
  • Changes ignored — restart Codex; config.toml loads 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.

Frequently asked questions

Can Codex CLI use GLM-5?

Yes. Z.AI exposes an OpenAI-compatible endpoint, so you add it as a custom provider in Codex's config.toml with wire_api set to chat, then point the model at glm-5 (or glm-5-turbo). It runs like any OpenAI-style provider.

Which Z.AI endpoint does Codex use?

The OpenAI-compatible one (commonly https://api.z.ai/api/paas/v4), not the Anthropic endpoint. Codex speaks the OpenAI format, so use Z.AI's OpenAI-compatible base URL. Confirm the exact path in Z.AI's docs.

Do I need the Pro plan for GLM-5 in Codex?

GLM-5 availability follows your Z.AI plan tier the same way it does elsewhere — GLM-5 on Pro, GLM-5-Turbo on all plans. If glm-5 is rejected, use glm-5-turbo or upgrade your tier.

Why doesn't a base-URL swap alone work?

Codex defaults to OpenAI's responses API. Z.AI uses chat completions, so you must set wire_api = "chat" in the provider block. Without it, requests fail even with the right URL and key.

Does GLM have a coding plan for this?

Yes — the GLM Coding Plan from $18/month works for API access too, alongside pay-per-token. Heavy users save with the plan; light users pay per token.

Sources & further reading

Official vendor documentation referenced while writing this guide.

MG

MCSA Guru Team

IT & Systems Administration

We are working IT pros and system administrators who spend our days in Windows Server, Microsoft 365, and the wider Microsoft stack. MCSA Guru is where we write down the fixes and walkthroughs we wish we had found the first time.

MCSA Guru provides independent, educational IT guidance. Microsoft, Windows, Windows Server, Microsoft 365, Exchange, and Microsoft Teams are trademarks of Microsoft Corporation; Docker is a trademark of Docker, Inc. MCSA Guru is not affiliated with or endorsed by Microsoft or Docker. Always test changes in a safe environment before applying them in production.

Related guides

Fixing something right now?

Jump straight into the guide library or search for the exact error or task you are dealing with.