Get going in 30 seconds
npm install -g @mariozechner/pi-coding-agent
Create ~/.pi/agent/models.json:
{
"providers": {
"northerninference": {
"baseUrl": "https://northerninference.ca/v1",
"api": "openai-completions",
"apiKey": "ni_live_REPLACE_WITH_YOUR_KEY",
"models": [
{ "id": "vertex_ai/gemini-2.5-pro-ca" }
]
}
}
}
pi
In pi, use /model to pick your NI model, then type your prompt.
pi (@mariozechner/pi-coding-agent, source badlogic/pi-mono) is an MIT- licensed terminal coding harness. It speaks OpenAI Chat Completions natively, so NI works as a custom provider with no patching.
Install
npm install -g @mariozechner/pi-coding-agent
The binary is named pi.
Config file
~/.pi/agent/models.json (this exact path; pi reads it on startup AND on every /model switch):
{
"providers": {
"northerninference": {
"baseUrl": "https://northerninference.ca/v1",
"api": "openai-completions",
"apiKey": "ni_live_REPLACE_WITH_YOUR_KEY",
"models": [
{ "id": "azure/DeepSeek-V4-Pro-global" },
{ "id": "azure/DeepSeek-V4-Flash-global" },
{ "id": "vertex_ai/gemini-2.5-pro-ca" }
]
}
}
}
Three rules that catch most setup mistakes:
- **
baseUrlishttps://northerninference.ca/v1** - host root with
/v1, no trailing slash, no /chat/completions suffix. pi's OpenAI client appends /chat/completions itself.
- **
apiKeymust start withni_live_** - that's our key prefix.
Don't paste with quotes around it from somewhere else; raw string.
- **
models[].idis the routing key, not a friendly name.** Use exact
strings from https://northerninference.ca/v1/models. Mixing provider prefix is required (azure/..., bedrock/...).
Running
pi
Then in pi:
/model(or Ctrl+L) to pick a model - your NI entries appear under
the northerninference provider section.
- Type your prompt.
Route selection
NI routes to the upstream based on the model route key. Copy exact model IDs from /models or /api/billing/models into ~/.pi/agent/models.json. Use API key allowed route tiers to control which routes the key may call:
- NI portal → Keys → edit your key → set allowed route tiers.
- Save. Calls to disallowed model routes return
400.
To use a different route, change the exact model route key in your config.
Troubleshooting
"Invalid API key format" or "401 Unauthorized" with no further detail
Run pi with verbose HTTP logging (if the env var works for pi's transport):
NODE_DEBUG=http,https pi
Confirm the request includes Authorization: Bearer ni_live_.... If the header is missing or empty, pi isn't picking up apiKey from the config. Common causes:
- Typo:
apikeylowercase, orapi_keysnake_case (must beapiKey
camelCase per pi's schema).
~/.pi/agent/models.jsonhas invalid JSON - run
python -m json.tool < ~/.pi/agent/models.json to check.
- Your shell exported
ANTHROPIC_API_KEYorOPENAI_API_KEYand pi
picked one of those instead. Unset them or move the NI provider above the conflicting one.
"Route not allowed" or "ambiguous model route" 400 error
Your key is not allowed to use that model route, or the model ID is an unsuffixed base with multiple deployed routes. See Route selection above.
"Model not found" 400 error
Your models[].id doesn't match a deployed model. Visit https://northerninference.ca/models to see the current routing keys.
Rotating your key
If you've ever pasted your ni_live_... key into a chat, IRC, screenshot, or pair-debug session, treat it as compromised. NI portal → Keys → revoke → create a fresh one → update ~/.pi/agent/models.json.