Skip to content

GLM + OpenCode: Free-Tier-Friendly Coding Agent

Set up OpenCode with GLM models from Z.AI for a cheap, open-source coding agent. Provider config, model IDs, coding plan vs pay-per-token, and the common fixes.

MGMCSA Guru Team July 5, 2026 3 min read
OpenCode configured with a GLM provider from Z.AI on Windows

OpenCode is free and open source; GLM is one of the cheapest capable model families, with a flat coding plan from $18/month. Together they make a low-cost, fully terminal coding agent that reads your repo, edits files, and runs commands without OpenAI or Anthropic pricing.

This is the OpenCode + GLM setup: the provider block, model IDs, and the billing choice. For OpenCode’s general provider model, see OpenCode custom providers.

Step 1: Install OpenCode and get a Z.AI key

npm install -g opencode-ai

Sign up at Z.AI for a key — pay-per-token or the GLM Coding Plan. On Windows, WSL gives the cleaner shell — see install OpenCode on Windows with WSL.

Step 2: Add the GLM provider

OpenCode connects to OpenAI-compatible APIs through @ai-sdk/openai-compatible. Add Z.AI in opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "zai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Z.AI GLM",
      "options": {
        "baseURL": "https://api.z.ai/api/paas/v4",
        "apiKey": "{env:ZAI_API_KEY}"
      },
      "models": {
        "glm-5-turbo": { "name": "GLM-5 Turbo" },
        "glm-5": { "name": "GLM-5" }
      }
    }
  },
  "model": "zai/glm-5-turbo"
}

Export the key:

export ZAI_API_KEY="your-zai-key"

Step 3: Run it

opencode

The default is zai/glm-5-turbo. Switch in the TUI or change the model key.

GLM models in OpenCode (by plan)

zai/glm-5-turbo Everyday default; all plans
zai/glm-5 Hard tasks; Pro plan
zai/glm-4.7 Solid alternative; all plans

Pricing

OpenCode is free; GLM bills via pay-per-token or the GLM Coding Plan (from $18/month, with rolling-window caps). Heavy daily users save with the plan. See GLM Coding Plan setup and GLM-4.6 vs GLM-5 vs GLM-5-Turbo.

Troubleshooting

  • Provider not found — the provider key (zai) must match the model prefix.
  • Auth errorsZAI_API_KEY not set in the launching shell.
  • Format errors — you used /anthropic; switch to the OpenAI (paas/v4) URL.
  • Access denied on glm-5 — plan tier doesn’t include it; use glm-5-turbo.

GLM + OpenCode checklist

  • OpenCode installed
  • Z.AI key or GLM Coding Plan active
  • Provider block with the OpenAI (paas/v4) base URL
  • GLM model IDs listed; default set
  • Launched with opencode

Wrapping up

GLM with OpenCode is a cheap, open agent: add a Z.AI provider in opencode.json using @ai-sdk/openai-compatible on the OpenAI endpoint, list glm-5-turbo and glm-5, and set a default. Pay per token or use the GLM Coding Plan, and default to Turbo to stretch your usage.

For other GLM setups, see run GLM-5 with Claude Code and GLM + Cline in VS Code.

Frequently asked questions

How do I use GLM in OpenCode?

Add a custom provider in opencode.json using @ai-sdk/openai-compatible, with Z.AI's OpenAI-compatible base URL and your key, then list the GLM model IDs. Set a default model and launch OpenCode.

What base URL does OpenCode use for GLM?

Z.AI's OpenAI-compatible endpoint (commonly https://api.z.ai/api/paas/v4), not the Anthropic one. OpenCode speaks the OpenAI format via the SDK. Confirm the exact path in Z.AI's docs.

Is OpenCode with GLM cheap?

OpenCode is free and open source; GLM is cheap via pay-per-token or the GLM Coding Plan from $18/month. Together they make a low-cost agent, with the plan best for heavy daily use.

Which GLM model should I list?

glm-5-turbo as the everyday default (all plans), glm-5 for hard tasks (Pro), and optionally glm-4.7 or glm-4.5-air. Set the default in the model key.

Does it run on Windows?

Yes, and cleanly in WSL. The config is the same; WSL just gives the smoother terminal for a CLI agent.

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.