Use OpenRouter with a coding agent
Export OPENROUTER_API_KEY and run oharness -m openrouter/<vendor>/<model>. OHarness discovers OpenRouter's model list, so every model it routes is available under /models.
Three commands
npm install -g oharnessexport OPENROUTER_API_KEY="..."oharnessThen /models to see what OpenRouter offers and /model openrouter/<vendor>/<model> to pick one — the model id is OpenRouter's own, which already contains a slash.
When OpenRouter is the right choice
- Trying many models without opening an account with each vendor.
- One bill and one key for a team that uses several vendors.
- Fallback: if one upstream is down, the next turn can go to another through the same key.
Worth knowing
- Buying OpenRouter credits carries a fee, so a vendor's direct API can be cheaper for heavy use of one model.
- OHarness identifies itself to OpenRouter as
OHarnessin the request headers, so usage appears under that app on OpenRouter. - Mixing is fine: DeepSeek through its own key and Claude through OpenRouter, in one session.
Common questions
Can I use OpenRouter with a Claude Code-style coding agent?
Yes. OHarness has OpenRouter as a built-in provider. Set OPENROUTER_API_KEY and pick any model with /model openrouter/<vendor>/<model>.
Does switching OpenRouter models mid-session lose context?
Not in OHarness. History is stored vendor-neutral, so moving between models behind OpenRouter — or between OpenRouter and a direct provider — converts nothing.
OpenRouter reference
| Provider id | openrouter |
| Base URL | https://openrouter.ai/api/v1 |
| Protocol | OpenAI-compatible chat completions |
| API key | OPENROUTER_API_KEY |
| Model discovery | Yes — the model list is asked of the endpoint rather than shipped. |
Connecting it
The endpoint above is built in, so there is nothing to configure. Put the key in the environment and the provider appears in the model picker:
export OPENROUTER_API_KEY="..."Keys are issued by OpenRouter — where to get one.
Pointing it somewhere else
A regional host, a gateway, or a server of your own. Overrides in ~/.oharness/config.json are field level, so changing the endpoint does not mean restating the rest of the provider — this is the whole block, shown holding the default so the shape is clear:
{
"providers": {
"openrouter": {
"baseUrl": "https://openrouter.ai/api/v1"
}
}
}What you get either way
The same agent loop, the same tools, the same MCP servers and the same permission rules, whichever provider is underneath — and switching between them mid-session converts nothing, because history is never stored in a vendor’s shape. What an agent harness is covers why that is the hard part, and the providers reference covers the catalogue itself.