@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 the latest OpenCode
- Create a BetterToken API Key
- Copy a Model ID from the model plaza or key Setup dialog
Install
- curl
- npm
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.- macOS / Linux
- Windows
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: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.
/connect, add "apiKey": "YOUR_API_KEY" under options. Never commit a configuration containing a real key.
Verify the connection
Runopencode 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 newYOUR_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.
What the setup methods mean
What the setup methods mean
- 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.
Related FAQ
- How to connect Kimi K3 to OpenCode
- How to connect GLM to OpenCode
- OpenAI-compatible API vs Anthropic-compatible API
- MCP vs API Key and Base URL
- What are model_provider, base_url, and wire_api?
- How to configure an OpenAI-compatible API in Cline
Optional: manage the provider with CC Switch
To manage providers for several tools in one place, see OpenCode setup in CC Switch.Technical details
Provider and model provider
Provider and model provider
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.
