Skip to main content

Reaching a model through OpenRouter

OpenRouter is reached as an OpenAI-compatible gateway. bravebot knows its endpoint, so an entry keyed openrouter needs no baseURL. A stated baseURL always wins, so a proxy or a private deployment is reached by writing where it is.

{
"provider": {
"openrouter": {
"name": "OpenRouter",
"env": ["OPENROUTER_API_KEY"],
"models": {
"z-ai/glm-4.6": { "limit": { "context": 200000, "output": 8192 } }
}
}
}
}

The key​

Name a variable in env and keep the token wherever you already keep secrets. Or store it with bravebot:

bravebot auth login gateway openrouter

It asks for the key with nothing shown as you type it, and keeps it in ~/.bravebot/gateway-keys.json, readable only by your account. No block has to be written first: where none names openrouter, the sign-in adds "provider": {"openrouter": {}} to your settings, which reaches openrouter.ai and names no variable. Signing in has the details. Where more than one source of the key is present, a variable wins, then the stored key, then the file options.keyFile names, then options.apiKey (The credential).

Which models are offered​

A block that lists models is offered those and no others, as the block above is, which is the way to pin a short list out of a service offering hundreds. A block that lists none has OpenRouter asked, and Which models are offered says what the answer is filtered by.

Keeping a session on one cache​

Set options.setCacheKey to true and each request carries a prompt_cache_key and, because the request goes to openrouter.ai, a session_id of the same value. Both are the same for every request of a session and differ in the next session. Neither is sent where the setting is off, and a baseURL that is not openrouter.ai gets the prompt_cache_key alone. The setCacheKey option is described in Reaching an OpenAI-compatible gateway.

Naming one​

Where one model is reachable through more than one service, put the gateway's id in front of the name to say which you mean:

openrouter/z-ai/glm-4.6

The name is split once, at the first slash, because most gateway names contain one. The id picks the service and only the remainder is sent (Naming one).