Skip to main content
You can connect GLM to OpenCode through BetterToken as an OpenAI-compatible provider. Enter your BetterToken API Key, the Base URL https://bettertoken.ai/v1, and the exact GLM Model ID from the Setup dialog.

Key settings

Prerequisites

Configure 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 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 the connection

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 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.