Use Tokun with OpenCode
Use Tokun as the model backend for OpenCode (the terminal agent) via an OpenAI-compatible provider — the same OpenCode workflow, billed at Tokun pricing with Tokun's model routing.
What this connects
Use Tokun as the model backend for OpenCode (the terminal agent) via an OpenAI-compatible provider — the same OpenCode workflow, billed at Tokun pricing with Tokun's model routing.
Before you start
- A Tokun API key (starts with
sk-) from the console. - A funded Tokun balance.
OpenCodeinstalled.- A chosen model id, e.g.
anthropic/claude-opus-4-8.
Recommended quickstart
In your opencode.json (project root or ~/.config/opencode/opencode.json), add Tokun as an OpenAI-compatible provider:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"tokun": {
"npm": "@ai-sdk/openai-compatible",
"options": { "baseURL": "https://api.tokun.sh/v1", "apiKey": "sk-..." },
"models": { "anthropic/claude-opus-4-8": {} }
}
}
}Run opencode and select the Tokun model.
Copy for AI agent
Working inside an AI coding agent? The shortest path is one line — paste this and your agent reads the full machine-readable guide at /llms.txt and does the OpenCode setup itself. You only supply your key:
Read https://tokun.sh/llms.txt and integrate Tokun into this project.OpenCode specifically.You are helping the user configure OpenCode to use Tokun. Edit opencode.json (project root or ~/.config/opencode/opencode.json) and add an OpenAI-compatible provider:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"tokun": {
"npm": "@ai-sdk/openai-compatible",
"options": { "baseURL": "https://api.tokun.sh/v1", "apiKey": "<the Tokun sk- key>" },
"models": { "anthropic/claude-opus-4-8": {} }
}
}
}
Notes:
- baseURL keeps the /v1 suffix (https://api.tokun.sh/v1).
- The key is a Tokun sk- key, NOT an OpenAI key.
- Add more model ids under "models" as needed.Manual configuration
The provider lives under provider in opencode.json using @ai-sdk/openai-compatible with baseURL: https://api.tokun.sh/v1 + your key. To roll back, remove the provider block.
Model naming
Each key under models is a Tokun lab/model id, e.g. anthropic/claude-opus-4-8 or openai/gpt-5.5. Tokun does not silently substitute models — an unknown id returns an error.
Verify & troubleshoot
@ai-sdk/openai-compatible and keep the /v1 suffix on baseURL (https://api.tokun.sh/v1). The key is your Tokun sk- key.| Symptom | Likely cause | Fix |
|---|---|---|
401 / auth error | Wrong or missing key | Set options.apiKey to your Tokun sk- key. |
402 / payment required | Empty Tokun balance | Top up in the console. |
Model not found | Model id not under "models" | Add the lab/model id, e.g. anthropic/claude-opus-4-8. |