Use Tokun with OpenCode

Connect OpenCode to Tokun using your API key and a supported model.

Overview

OpenCode, the terminal agent, connects to Tokun through an OpenAI-compatible provider. Your OpenCode workflow stays the same, and requests use Tokun's pricing and model routing.

Before you start

  • A Tokun API key (starts with sk-) from the API keys page.
  • A funded Tokun balance.
  • OpenCode, installed.
  • A model ID, such as anthropic/claude-opus-4-8.

Quickstart

In your opencode.json (project root or ~/.config/opencode/opencode.json), add Tokun as an OpenAI-compatible provider:

json
{
  "$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.

Set up with an AI assistant

Paste this prompt into your AI coding agent. It reads the setup guide at /llms.txt and sets up OpenCode for you. You only need to provide your API key.

text
Read https://tokun.sh/llms.txt and integrate Tokun into this project.
Prefer exact, step-by-step instructions? Paste this detailed prompt instead. It sets up OpenCode specifically.
text
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.

Set up manually

The provider is defined under provider in opencode.json, using @ai-sdk/openai-compatible with baseURL: https://api.tokun.sh/v1 and your key. To roll back, remove the provider block.

Model IDs

Each key under models is a Tokun model ID in lab/model format, such as anthropic/claude-opus-4-8 or openai/gpt-5.5. Tokun never substitutes a different model: an unknown ID returns an error.

Official model pools

Official model pools appear in the model catalog and use a pool ID such as flash-pool. Choose an available pool from the live catalog; pool names and members are configured by Tokun administrators.

When the pool enables member selection, use pool-id/member-name, replacing the model's lab prefix with the pool ID. The selected member is the only model that can execute; the pool's pricing mode still applies. When selection is disabled, this form returns 400.

  • Fixed token pricing uses the pool's input, output, cache and context-tier rates for every member, including a member you select yourself.
  • Actual model pricing uses the serving member's price, frozen before the request. A retry to another member uses that member's frozen price.
  • Fixed per-request pricing charges once after an upstream success response begins. Missing usage, a partial response or a client disconnect after that point still counts once. Failures before success and unsuccessful retries do not add charges.

Use a pool that lists the API format this client sends. Model pool settings in the live catalog control which members are shown and whether member selection is available.

Troubleshooting

Use @ai-sdk/openai-compatible and keep the /v1 suffix on baseURL (https://api.tokun.sh/v1). The key is your Tokun sk- key.
SymptomLikely causeFix
401 / auth errorWrong or missing keySet options.apiKey to your Tokun sk- key.
402 / payment requiredEmpty Tokun balanceTop up on the Billing page.
Model not foundModel ID not listed under "models"Add the lab/model ID, such as anthropic/claude-opus-4-8.