GLM52.pro

GLM 5.2 + OpenCode

Configure GLM 5.2 as your OpenCode backend through OpenRouter or the direct Z.ai coding API.

Why GLM 5.2 for OpenCode?

1M context
Use the 1M-token context window for larger repositories and long coding sessions
Coding Plan endpoint
Z.ai exposes a dedicated coding endpoint for agentic coding workflows
OpenRouter option
Use z-ai/glm-5.2 when you want unified billing and provider routing

Setup via OpenRouter

1. Get an OpenRouter API key

Sign up at openrouter.ai and add credits. Use model z-ai/glm-5.2. Current listed pricing is $1.20/M input and $4.10/M output tokens.

2. Configure OpenCode
# opencode.json
{
  "model": {
    "provider": "openai",
    "name": "z-ai/glm-5.2",
    "baseURL": "https://openrouter.ai/api/v1",
    "apiKey": "sk-or-YOUR_KEY_HERE"
  }
}
3. Start OpenCode
opencode

Setup via Z.ai Coding API

# opencode.json (Z.ai direct)
{
  "model": {
    "provider": "openai",
    "name": "glm-5.2[1m]",
    "baseURL": "https://api.z.ai/api/coding/paas/v4",
    "apiKey": "YOUR_ZAI_API_KEY"
  }
}

Use the Z.ai coding endpoint when you want the dedicated Coding Plan path. For general chat completions, use https://api.z.ai/api/paas/v4.

Recommended OpenCode Settings for GLM 5.2

{
  "model": {
    "provider": "openai",
    "name": "z-ai/glm-5.2",
    "baseURL": "https://openrouter.ai/api/v1",
    "apiKey": "sk-or-YOUR_KEY_HERE"
  },
  "autoshare": false,
  "keybinds": {
    "leader": "ctrl+x"
  }
}