Integrations
opencode
Point opencode at Token Harbor manually — Base URL, API key, context limit, and exact steps. One key, every model, no CLI required.
opencode + Token Harbor
The open-source terminal agent. Route it through Token Harbor to use every model with a single key.
Get a thk_… key from /dashboard/api-keys (a free account works), then:
opencode reads ~/.config/opencode/opencode.json. Add a provider (opencode 2.x;
check with opencode --version, and see opencode 1.x for older
releases):
{
"$schema": "https://opencode.ai/config.json",
"providers": {
"tokenharbor": {
"name": "Token Harbor",
"env": ["TOKENHARBOR_API_KEY"],
"package": "@opencode/ai/providers/openai-compatible",
"settings": { "baseURL": "https://tokenharbor.ai/v1" },
"models": {
"deepseek-v4.1-flash:free": {
"name": "DeepSeek V4.1 Flash (Free)",
"limit": { "context": 1048576, "output": 32000 }
}
}
}
}
}
Set TOKENHARBOR_API_KEY=YOUR_thk_KEY in your environment. This keeps the
secret out of opencode.json.
Run opencode and pick the Token Harbor model with /models.
Context limit
opencode decides when to compact the conversation from limit.context. Without
it, opencode assumes 200,000 tokens and compacts at about 170,000, long before a
1M-token model is full.
limit.context— the model's window: thecontext_lengththatGET /v1/modelsreturns for it, 1,048,576 for DeepSeek V4.1 Flash. opencode compacts once the conversation fills the window minus its buffer (compaction.buffer, 15% by default), here about 890,000 tokens.limit.output— the most the model may write in one turn. 32,000 is what the gateway uses when a request sets no limit; it accepts up to 128,000.
Add one entry under models for each model you use, with that model's own
context_length.
opencode 1.x
opencode 1.x uses the older provider / npm / options keys, and limit
needs both context and output. opencode 2.x still reads this form, but keep
each provider entry in one form or the other:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"tokenharbor": {
"name": "Token Harbor",
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://tokenharbor.ai/v1",
"apiKey": "{env:TOKENHARBOR_API_KEY}"
},
"models": {
"deepseek-v4.1-flash:free": {
"name": "DeepSeek V4.1 Flash (Free)",
"limit": { "context": 1048576, "output": 32000 }
}
}
}
}
}
Prefer one command? The tokenharbor CLI configures opencode
automatically (and can undo it).