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.
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 |