Skip to main content
OpenCode connects to BetterToken with @ai-sdk/openai-compatible. Name the OpenCode provider BetterToken or OpenAI Compatible. GPT, Kimi, and GLM are model providers inside BetterToken, not OpenCode provider names. Stay on this page for general API Key, Base URL, or opencode.json setup. Use the dedicated GLM guide or Kimi K3 guide only when you need to select and verify that specific model.

Key settings

Prerequisites

Install

Command-line setup

The BetterToken Automatic setup script creates or updates the BetterToken provider in OpenCode. It requires Node.js. If you do not pass an API Key or Model ID as an argument, the script prompts you for them.
Select bettertoken/YOUR_MODEL_ID after the script finishes. If OpenCode is already running, restart it before testing.

Manual setup

Option 1: save credentials with /connect

Start OpenCode and run:
Choose Other, enter bettertoken as the provider id, and then enter YOUR_API_KEY. OpenCode stores the credential locally.

Option 2: configure JSON

The global file is ~/.config/opencode/opencode.json. A project can use opencode.json in its root.
If you do not use /connect, add "apiKey": "YOUR_API_KEY" under options. Never commit a configuration containing a real key.

Verify the connection

Run opencode in a project, select bettertoken/YOUR_MODEL_ID, and send a short message. A normal response confirms the setup. Restart OpenCode after changing JSON.

Switch models

Add a new YOUR_MODEL_ID under provider.bettertoken.models, update the top-level model, save, and restart.

Common errors

Advanced setup

Supported providers

Statuses apply to the BetterToken setup documented on this page.
  • Command-line + manual setup: use a generated command or follow the complete manual steps.
  • Manual setup: enter the API Key, Base URL, and Model.
  • Not supported: no verified direct setup is currently available.

Optional: manage the provider with CC Switch

To manage providers for several tools in one place, see OpenCode setup in CC Switch.

Technical details

The OpenCode provider is bettertoken, backed by @ai-sdk/openai-compatible and Chat Completions. GPT, Kimi, and GLM are model providers in BetterToken; put the selected complete Model ID in models.