Skip to main content
Use this guide only to select and verify GLM in OpenCode. For general API Key, Base URL, and opencode.json setup, start with the OpenCode setup guide, then return here with the exact GLM Model ID from the Setup dialog.

GLM settings

GLM prerequisites

Connect GLM with /connect

Start OpenCode and run:
Choose Other, enter bettertoken as the provider id, and paste your BetterToken API Key. Then select bettertoken/YOUR_GLM_MODEL_ID and restart OpenCode.

Manual GLM configuration

Open ~/.config/opencode/opencode.json or a project-level opencode.json:
Replace YOUR_API_KEY and YOUR_GLM_MODEL_ID with values from the Setup dialog. Do not reuse a Model ID from an old article; use one currently available to your API Key.

Verify GLM

Select bettertoken/YOUR_GLM_MODEL_ID in OpenCode and send a short prompt. A response without an API error confirms the setup. Fully restart OpenCode after editing JSON.

Common GLM errors

Technical details

OpenCode uses OpenAI-compatible Chat Completions. Set only https://bettertoken.ai/v1 as the Base URL because OpenCode appends the request path. The available GLM Model ID depends on the selected provider and your API Key.