Nanobot
Use Router9 as a custom provider in Nanobot
Nanobot is an MCP-native agent runtime. It reads its model configuration from ~/.nanobot/config.json, where you register a provider, name a model preset, and point the agent defaults at it. Router9 plugs in as a custom OpenAI-compatible provider.
Install
python -m pip install nanobot-ai
nanobot onboard --wizardnanobot onboard creates ~/.nanobot/config.json if it doesn't exist yet.
Setup
Add Router9 as a custom provider, define a model preset that points at it, and select that preset in your agent defaults. Merge this into ~/.nanobot/config.json:
{
"providers": {
"router9": {
"apiBase": "https://api.router9.com/v1",
"apiKey": "${ROUTER9_API_KEY}"
}
},
"modelPresets": {
"primary": {
"label": "Router9",
"provider": "router9",
"model": "gpt-4o",
"maxTokens": 8192,
"contextWindowTokens": 128000,
"temperature": 0.1
}
},
"agents": {
"defaults": {
"modelPreset": "primary"
}
}
}A custom provider key like router9 is treated as a direct OpenAI-compatible provider, so apiBase is required — include the /v1 version path. Choose a name that doesn't collide with a built-in provider (openai, anthropic, ollama, etc.), and leave apiType unset.
Environment Variables
Set your Router9 key so the ${ROUTER9_API_KEY} reference resolves:
export ROUTER9_API_KEY=sk-r9k-your-key-hereEnvironment variables set this way apply only to the current terminal. For long-running services (systemd, Docker, a remote shell), set the variable in that service's environment before starting nanobot.
Verify
nanobot status
nanobot agent -m "Hello!"If the CLI reply works, you can go on to connect the WebUI, gateway, or chat apps.
Choosing Models
The model field inside a preset is the id Router9 routes on. Add more presets to expose several models, and switch between them at runtime with /model:
{
"modelPresets": {
"fast": {
"label": "Fast",
"provider": "router9",
"model": "gpt-4o",
"maxTokens": 8192,
"contextWindowTokens": 128000
},
"deep": {
"label": "Deep",
"provider": "router9",
"model": "claude-sonnet-4-20250514",
"maxTokens": 8192,
"contextWindowTokens": 200000
}
},
"agents": {
"defaults": {
"modelPreset": "fast"
}
}
}Swap the model id for any model Router9 supports. In a chat surface, /model deep switches presets for the next turn without editing the config.
Fallback Models
Named presets double as fallback targets. List them under agents.defaults.fallbackModels; nanobot tries the active preset first, then each fallback in order:
{
"agents": {
"defaults": {
"modelPreset": "fast",
"fallbackModels": ["deep"]
}
}
}Tips
- Nanobot is MCP-native — expose Router9 Skills as tools by adding Router9's hosted MCP server.
- Router9's flat monthly pricing suits Nanobot's long-running, tool-heavy sessions.
- Keep your
sk-r9k-key in the environment rather than committing it toconfig.json.