How to Use TokenAir with OpenCode
OpenCode can cost significantly less through TokenAir when routine coding tasks move to lower-cost models and harder work keeps a premium model. OpenCode supports custom OpenAI-compatible providers, so you only need a TokenAir API key, base URL, and an account-enabled model ID.
Compatibility verdict
Direct setup
Direct setup is available. OpenCode documents a custom provider flow based on the OpenAI-compatible AI SDK package and a configurable baseURL.
The tool documents a custom OpenAI-compatible endpoint path.
Before you start
- A TokenAir API key stored outside source control.
- A model ID returned by TokenAir's /models endpoint or shown in your TokenAir account.
- A current OpenCode installation and a project where you can add opencode.json.
Setup and compatibility steps
Step 1
Store the TokenAir credential in OpenCode
Run /connect, choose Other, enter tokenair as the provider ID, and paste your TokenAir API key when OpenCode prompts for it. The provider ID must match the key used in opencode.json.
Step 2
Add the custom provider
Create or update opencode.json in the project. Use the OpenAI-compatible package, the TokenAir base URL, and one exact model ID enabled for your account.
Step 3
Select the model
Run /models and choose the model under the TokenAir provider. If it is missing, first check that the provider ID and model key match the configuration.
Step 4
Test one bounded coding task
Start with a small edit that has a clear expected diff. Compare tool calls, latency, retries, and whether you accept the result before moving a larger workload.
Example opencode.json
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"tokenair": {
"npm": "@ai-sdk/openai-compatible",
"name": "TokenAir",
"options": {
"baseURL": "https://api.tokenair.ai/v1"
},
"models": {
"YOUR_TOKENAIR_MODEL_ID": {
"name": "TokenAir model"
}
}
}
}
}Replace placeholders with values from your own TokenAir account. Never commit an API key to source control.
How to verify it
- OpenCode shows TokenAir and the configured model in /models.
- A simple prompt streams a complete answer without an authentication or model error.
- A small file edit produces a valid tool call and a reviewable diff.
- The result meets your acceptance bar at a lower total task cost rather than a lower token price alone.
How to lower cost without hiding quality loss
TokenAir gives the client access to premium and lower-cost model choices through one OpenAI-compatible API. Savings depend on matching each task with a model that still passes review.
- Use a lower-cost model for repository search, explanation, or first-pass edits.
- Keep a stronger model available for architecture changes, difficult debugging, or final review.
- Measure cost per accepted patch and include retries or rejected diffs.
Limits to know before production
- Model IDs are account-specific and can change. Do not copy a model name from an unrelated provider guide.
- Tool calling quality varies by model. A successful chat response does not prove that agent edits will work.
- TokenAir lowers cost through model choice; it does not guarantee that every OpenCode task will cost less.
FAQ
Does OpenCode support a custom TokenAir base URL?
Yes. OpenCode documents custom OpenAI-compatible providers with an options.baseURL field and explicit model IDs.
Which TokenAir model should I use in OpenCode?
Use an account-enabled model with reliable tool calling. Start with one bounded task and compare cost per accepted patch before making it the default.
Why does the model not appear in /models?
Check that the provider ID used by /connect matches the provider key in opencode.json and that the configured model ID is exact.
Official sources and related TokenAir docs
Tool settings change between releases. We checked these notes on July 17, 2026. Review the linked tool docs again before a production rollout.
Try one workflow before changing the default.
Use the cost checkup to choose a bounded test, then compare cost per accepted result with your current route.