Get going in 60 seconds
Create or edit opencode.json in your project root (or ~/.config/opencode/opencode.json for a global default):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"northerninference": {
"npm": "@ai-sdk/openai-compatible",
"name": "Northern Inference",
"options": { "baseURL": "https://northerninference.ca/v1" },
"models": {
"bedrock/global.anthropic.claude-sonnet-4-6-global": { "name": "Claude Sonnet 4.6 (NI)" },
"vertex_ai/gemini-2.5-pro-ca": { "name": "Gemini 2.5 Pro (NI, CA)" }
}
}
}
}
Then add your key: run opencode auth login, scroll to Other, enter the provider id northerninference, and paste your ni_live_ key. Restart OpenCode. Both models appear in the model picker under Northern Inference.
OpenCode is a terminal-native coding agent. It supports custom OpenAI-compatible providers via the @ai-sdk/openai-compatible npm adapter -- no plugin required.
Config file
Place opencode.json in your project root for per-project config, or at ~/.config/opencode/opencode.json for a global default. The two locations can coexist; the project file takes precedence.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"northerninference": {
"npm": "@ai-sdk/openai-compatible",
"name": "Northern Inference",
"options": { "baseURL": "https://northerninference.ca/v1" },
"models": {
"bedrock/global.anthropic.claude-sonnet-4-6-global": { "name": "Claude Sonnet 4.6 (NI)" },
"vertex_ai/gemini-2.5-pro-ca": { "name": "Gemini 2.5 Pro (NI, CA)" }
}
}
}
}
Authentication
Run:
opencode auth login
Scroll to Other, enter provider id northerninference, and paste your ni_live_ key. OpenCode stores the credential in its keychain. Restart OpenCode after saving the config for the provider to appear.
Choosing model IDs
The object keys under models are sent to NI verbatim as the model field in every chat completion request. They must be exact deployed route IDs.
Copy the exact route from the live list:
curl https://northerninference.ca/v1/models | jq '.[].id'
Use the returned string case-sensitive. Display names in the model picker ("name") are cosmetic only and do not affect routing.
Key points
- **
npm: "@ai-sdk/openai-compatible"**: this adapter is the supported path
for custom providers. No other adapter works with NI's /v1 endpoint.
- **
options.baseURL**: must behttps://northerninference.ca/v1exactly.
No trailing slash.
- Model object keys: these are the NI route IDs, not display names.
Copy them from /v1/models to be certain. A mismatched key returns 400 model_not_found.
- Privacy tier: the route itself sets the tier.
vertex_ai/gemini-2.5-pro-ca
routes through Canadian-resident Vertex AI (Tier 3). No extra header or body field is needed.
Verify
After the first response, check portal โ Usage to confirm the request landed on NI and shows the expected route and cost.
Cost control
OpenCode fires requests on every agentic turn. If you want a spend limit, create a dedicated key in portal โ Keys โ Create key with a daily spend cap and enter that key during opencode auth login.
Quirks
- OpenCode must be restarted after any change to
opencode.json. A running
instance does not hot-reload the provider config.
- The
"name"field inside each model entry is a display label only. It does
not affect what NI receives.
- NI route IDs contain slashes (e.g.
vertex_ai/gemini-2.5-pro-ca). This is
expected. OpenCode passes them through unchanged to the API.
- Fallback and PII substitution settings come from the NI key configuration,
not from per-request fields. Adjust them in the portal on the key.