Coding Tools
OpenCode
Configure OpenCode to use TokenLab API
Let my agent set this up
Copy this task to an agent already running on your computer:
Read this guide and help me connect OpenCode to TokenLab:
https://tokenlab.sh/docs/en/integrations/opencode
Check my installed version and active configuration first.
Preserve existing accounts, providers, permissions and other settings.
Back up local files and show proposed changes.
Have me enter any API key locally; never ask for, print or paste it in chat.
Check configuration loading first.
Explain any paid request test separately before running it.Overview
OpenCode can use TokenLab through a custom OpenAI-compatible provider. Add the TokenLab API key, Base URL, and a current model ID.
Installation
npm install -g opencode-ai@1.18.31Verify installation:
opencode --versionConfiguration
Step 1: Set Environment Variables
Use the Quickstart terminal instructions for macOS, Linux, WSL, or Windows PowerShell to set TOKENLAB_API_KEY without putting the key in command history. Launch OpenCode from that terminal. For persistent use, use your local secret manager; do not append a plaintext key to your shell profile.
Step 2: Configure OpenCode
The configuration below was checked with OpenCode 1.18.31. Other versions need their own verification against the official documentation.
Create a separate ~/.config/opencode/tokenlab.jsonc file with the configuration below. If XDG_CONFIG_HOME is set, use opencode/tokenlab.jsonc under that directory. Keep the normal opencode.json / opencode.jsonc, accounts, default model and permissions unchanged: this separate file is loaded only for an invocation that selects it with OPENCODE_CONFIG. If the file or provider name already belongs to another setup, choose a different file/name and adjust the commands.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"tokenlab": {
"npm": "@ai-sdk/openai-compatible",
"name": "TokenLab",
"options": {
"baseURL": "https://api.tokenlab.sh/v1",
"apiKey": "{env:TOKENLAB_API_KEY}"
},
"models": {
"gpt-5.6-terra": {
"name": "GPT-5.6 Terra"
},
"gpt-5.6-luna": {
"name": "GPT-5.6 Luna"
}
}
}
}
}This configuration uses @ai-sdk/openai-compatible for Chat Completions. Choose a current model whose details support Chat Completions and the tools you need; do not infer support for another protocol or version from this example.
Optional: the reversible OpenCode setup helper provides preview, apply and original-file restoration with Python 3.11+. TokenLab Skills plugin 0.1.2 includes these scripts; a standalone Skill installation can also be used after updating to a version that contains them. For an existing plugin or standalone Skill installation, follow the README update instructions and confirm the script is present. The manual configuration here remains usable without the helper.
Basic Usage
Set the key using Quickstart, then load this file and select the model explicitly for this invocation. Substitute your actual path and provider name if customized. Keep any existing OPENCODE_CONFIG or inline OPENCODE_CONFIG_CONTENT setup in a separate launch environment; project and managed settings may still take precedence.
OPENCODE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/tokenlab.jsonc" opencode models tokenlab
OPENCODE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/tokenlab.jsonc" opencode --model tokenlab/gpt-5.6-terraModel discovery checks local loading, not key validity or a successful live request. A prompt uses TokenLab balance and OpenCode may send separately billed auxiliary requests, such as title generation. Check the reply and the matching request records.
To use your ordinary setup, launch without this layer. Do not persist OPENCODE_CONFIG in your shell profile for this guide. To undo the manual setup, remove only the separate file you created, or restore its backup if it existed before.
Generate images and video in the same agent
OpenCode can also create images and short videos with the TokenLab MCP server. Each generation is paid from the same TokenLab balance. Merge this mcp entry into the same tokenlab.jsonc, next to provider. OpenCode replaces {env:TOKENLAB_API_KEY} with the variable from your terminal, so the key is not written to the file:
{
"mcp": {
"tokenlab": {
"type": "local",
"command": ["npx", "-y", "@tokenlabai/mcp-server@0.6.48"],
"environment": {
"TOKENLAB_MCP_TOOL_PROFILE": "core",
"TOKENLAB_API_KEY": "{env:TOKENLAB_API_KEY}"
},
"timeout": 30000
}
}
}The longer timeout gives npx time to download the package on first start. Run opencode mcp list with the same OPENCODE_CONFIG and check that tokenlab is connected. Then try:
Call get_model_pricing for nano-banana-2, then use create_image with nano-banana-2 at 1k to make a photo of a matte black coffee mug on a white desk.create_video returns a task ID. The agent calls get_task_status until the video is ready. See OpenCode MCP servers for other settings.
Choose a Model
Copy a current coding model ID from the Models page. Compare models on your own repository before setting a default.
Common Commands
Analyze code:
OPENCODE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/tokenlab.jsonc" opencode run --model tokenlab/gpt-5.6-terra "What does this function do?" < src/utils.tsGenerate code:
OPENCODE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/tokenlab.jsonc" opencode run --model tokenlab/gpt-5.6-terra "Create a REST API with Express"Review changes:
git diff | OPENCODE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/tokenlab.jsonc" opencode run --model tokenlab/gpt-5.6-terra "Review these changes"Fix errors:
OPENCODE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/opencode/tokenlab.jsonc" opencode run --model tokenlab/gpt-5.6-terra "Fix the TypeScript errors in this project"Interactive Commands
| Command | Description |
|---|---|
/help | Show available commands |
/models | Switch to a different model |
/clear | Clear conversation history |
/exit | Exit OpenCode |
Billing and top-up
Check your balance in Billing before the first request. A new account may get a one-time trial credit; otherwise it starts at $0, and the first request returns HTTP 402 with the error code insufficient_balance. Top up at least $5 (the minimum top-up), then send the same request again. The same API key keeps working once the balance covers the request. Each request sent through TokenLab is billed at the price of the model it uses, and auxiliary requests such as title generation can use a different model than the one you selected. Billed requests appear in Requests.