Reaching an OpenAI-compatible gateway
A provider block names a gateway, the models it offers and where its credential lives. An entry
keyed amazon-bedrock names an AWS account instead, which is
reached by signing rather than by a token; everything below is about the other entries. The models
a gateway ends up with are offered in /model beside Brave's roster and any AWS tiers. It takes nothing away
from those rosters and does not move the default: what answers when nobody has chosen stays what it
was, and the conversation budget stays where it was too.
{
"provider": {
"openrouter": {
"name": "OpenRouter",
"env": ["OPENROUTER_API_KEY"],
"models": {
"z-ai/glm-4.6": { "limit": { "context": 200000, "output": 8192 } }
}
}
}
}
| Where | Field | What it holds |
|---|---|---|
the key under provider | the gateway's id, which is also what a picker row names it by | |
| the entry | name | something friendlier to show than the id |
env | variable names that may hold the bearer token, tried in order | |
models | the models to offer, keyed by the name the gateway knows each by | |
whitelist | model ids; of a fetched roster, only these are offered | |
blacklist | model ids; of a fetched roster, these are not offered | |
options | baseURL | where requests go |
contextWindow | the context window of every model that states none, in prompt tokens (bravebot's own field) | |
maxRetries | how many times a request is sent again after a failure worth another attempt, 2 where unstated, or 5 after a rate limit that named no wait (bravebot's own field) | |
retryWindowMs | how long after its first failure a request whose connection failed is still sent again, in milliseconds, 300000 where neither this nor maxRetries is stated (bravebot's own field) | |
idleTimeoutMs | how long a reply may go quiet before it is given up on, in milliseconds, 120000 where unstated (bravebot's own field) | |
setCacheKey | true to send a prompt_cache_key in each chat-completions request, the same value for every request of a session and another value in the next session, for a service that routes by it to serve a session's prompt cache. A request to openrouter.ai also carries the value as a top-level session_id, which OpenRouter groups a session's requests by. Off where unstated, since it lets the host tie a session's requests together (bravebot's own field) | |
apiKey | a token written into the file directly | |
keyFile | the absolute path of a file that holds the token and nothing else, as The credential says (bravebot's own field) | |
headers | extra request headers, keyed by header name | |
| a model | limit.context | that model's context window, in prompt tokens |
options | anything extra to put in the request body |
The block is opencode's, field for field, so one copied out of opencode.json works unedited.
Nothing is required that opencode does not require, and a field bravebot does not know is read past
rather than refused. opencode's cost, modality and package fields do nothing here.
Where the requests go
A gateway bravebot already knows an endpoint for needs no baseURL. openrouter
and openai are the names it knows today. Any other id needs one written down, and an entry with neither a known name
nor a stated endpoint configures no service. A stated baseURL always wins, so a known name stays
usable against a proxy or a private deployment. A port is read as digits that fit in 65535 after the host; a : followed by anything else, such as https://gw.example.com:/v1 or :abc, leaves the entry out of the gateways, and bravebot doctor names it by its id and by the text written where the port belongs, without the rest of the address. A BRAVE_AI_CHAT_ENDPOINT written the same way fails the configuration with an error that names that text. A known name supplies the endpoint and no credential:
the block still says where its credential lives, as below. What is different at
api.openai.com follows the host a request goes to, whatever the entry is called, and is on the
OpenAI page.
The names it knows are compiled in, and nothing is fetched to resolve one. This value is where a bearer credential gets sent, so a service that could decide it could redirect your token by answering a request.
Extra request headers
options.headers adds headers to every request this gateway answers, including the one that asks
for its model list. A gateway in front of several services usually routes on one: a tenant id, a
routing key, a second credential.
{
"provider": {
"acme-gateway": {
"env": ["ACME_API_KEY"],
"options": {
"baseURL": "https://gateway.acme.internal/v1",
"headers": {
"x-tenant-id": "platform-eng",
"x-acme-route": "{env:ACME_ROUTE}"
}
}
}
}
}
A value written as {env:NAME} on its own is read from that variable when a request needs it, the
way a credential is, so exporting a new one takes effect in a session already open and the value
stays out of a file people paste into issues. A variable holding nothing sends no header. Braces
inside a longer value are refused rather than substituted.
Header values are treated as credentials: they are in no trace, no error text, and nothing
doctor prints.
Some names are refused, and the rest of the block still goes. host, content-length,
content-type, transfer-encoding and connection are the request's own framing. So is the
header your credential goes in, authorization or x-goog-api-key on a google-vertex entry,
where the entry names a credential at all; an entry naming none may set authorization itself. A
Bedrock entry takes no headers from here, because AWS signs over the headers it sends.
bravebot doctor lists every refused header under the gateway block it was written on, with the
name as you wrote it and which of those reasons refused it, so there is a name to go and edit. The
value is not printed.
This is read from your own settings file, the file --settings names, and a managed layer only.
A provider block in a checkout's .bravebot/settings.json or settings.local.json is ignored
whole and bravebot doctor names the file. A header is where a request goes as much as baseURL
is: a checkout that could add one could send your credential and your context somewhere you did not
agree to.
OpenAI
Reaching OpenAI with an API key says how an entry keyed openai reaches OpenAI, which
models it offers, and how an entry reaches the Responses API.
Google Vertex AI
Reaching Google Vertex AI says how an entry keyed google-vertex
reaches Vertex AI with or without a project, and what express mode is.
Cloudflare
An entry keyed cloudflare-workers-ai that states options.accountId reaches Cloudflare Workers AI
at https://api.cloudflare.com/client/v4/accounts/<accountId>/ai/v1. An entry keyed
cloudflare-ai-gateway that states options.accountId and options.gatewayId reaches Cloudflare AI
Gateway at https://gateway.ai.cloudflare.com/v1/<accountId>/<gatewayId>/compat. A model on the
gateway is named <provider>/<model>, as workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast, and
the name is sent as written.
{
"provider": {
"cloudflare-ai-gateway": {
"options": { "accountId": "abc123", "gatewayId": "my-gateway" }
}
}
}
An account id is letters and digits, and a gateway id is letters, digits, - and _. An entry whose
id is missing or holds any other character configures no service, and the gateway has no default id.
Where the entry names no env, states no apiKey or keyFile and states no baseURL, the key is read from
CLOUDFLARE_API_KEY for Workers AI and CLOUDFLARE_API_TOKEN for AI Gateway. The ids are read from
options only, so CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_GATEWAY_ID are not used. A gateway that
requires authentication takes its cf-aig-authorization header in options.headers. A baseURL the
entry states is where its requests go instead of the built address.
The credential
Name a variable in env and keep the token wherever you already keep secrets. Or store it with
bravebot:
bravebot auth login gateway openrouter
asks for the key with nothing shown as you type it, and keeps it in ~/.bravebot/gateway-keys.json,
readable only by your account, under the block's id. openrouter, openai and anthropic need no
block first: for one that no block names, the sign-in adds an entry that holds no field. Signing
in has the details. Or keep the token in a file of your own and name the
file in options.keyFile:
{
"provider": {
"acme-gateway": {
"options": {
"baseURL": "https://gateway.acme.internal/v1",
"keyFile": "/Users/you/.config/gateway-key.txt"
}
}
}
}
options.keyFile is the absolute path of a file that holds the token and nothing else. Make the file
readable by your account only. The file must be a regular file of at most 4,096 bytes, written in
UTF-8. Its whole content, without the whitespace at either end, is the key, so a final newline is
fine. The key must be non-empty ASCII with no whitespace or control character inside it. A value that
is blank or is not a string is read as not written, as a blank apiKey is. A value that is not
blank and is not an absolute path, ~/key included, is refused as below:
~ is not expanded, and the text of the value is kept nowhere and printed nowhere.
options.apiKey is read too, because it is opencode's field. It is read as written: {env:NAME} and
{file:path} written inside it are not substituted
(#3003). Where more than one source is present, a
variable the block's env names wins (the first one that holds text), then the stored key, then
options.keyFile, then options.apiKey. The first source that gives a token is used, and a source
later in the order is not read. A long-lived token in a settings file is a token in a file people
paste into issues, which is why the file and the stored key come before it.
A variable is read at the point a request needs it rather than once at startup, so exporting a new
one takes effect in a session already open. The key file is read at that point too, so replacing the
file takes effect in a session already open. A stored key is read when a session starts, so one
stored while a session is open reaches the next one. A block that names somewhere for a credential
to live and finds nothing there is a stale or missing token, and its requests are refused with the
remedy named rather than sent. bravebot doctor says whether a credential was found, and whether it
was a stored one or came from the key file, and never what it was. It prints an ends line for the
block too, naming the host the token is presented to: that host is the only surface that revokes it,
and deleting the value from this file, removing the file options.keyFile names, unsetting the
variable or running bravebot auth logout gateway ends this machine's custody and leaves the token
live there until it is revoked there.
A key file that gives no key refuses the request. A block that names options.keyFile has said where its credential lives. Where no variable and no
stored key gives a token, and the file cannot give one, the request is refused and nothing is sent.
The file cannot give a key when any of these holds:
- the value is not an absolute path, or the file is missing;
- the file is not a regular file, or cannot be read as text;
- the file holds more than 4,096 bytes;
- the file holds nothing but whitespace;
- the key holds whitespace, a control character or a character outside ASCII.
The refusal reads no credential for the <gateway> gateway: the file its `options.keyFile` names <reason>, so nothing was sent; fix the path, or put the key alone in that file, with the id of the gateway in
place of <gateway> and one of those reasons in place of <reason>. It names no path and holds no byte
of the file.
options.apiKey is not used in the file's place. A token left behind in apiKey after the key moved
to a file would otherwise be sent, and it is the stale one. A variable or a stored key that gives a
token is used before the file, and the file is then not read, so a file that is broken does not
matter while one of them is present.
bravebot doctor says in the block's key line that the key was found in the file options.keyFile
names, or, for a file that gives none, that no key could be used and which of the reasons above
applies. It does not print the path or any text of the file, since the setting is a string you wrote and
one pasted into the wrong field is the key itself. bravebot auth status and the desktop accounts list say that the
file gives no key. Storing a key with bravebot auth login gateway <id> makes the stored key win over
the file. A block that names options.keyFile names a credential, so the next paragraph does not
apply to it.
The managed layer drops options.keyFile. The file the administrator keeps
(managed settings) drops options.apiKey, and drops options.keyFile in
the same place, since everyone on the machine can read that file and the layer already names the host
a token goes to. Its host, models, variable names and headers are kept, and the credential comes from a
variable env names or a stored key.
A block naming no credential at all is a different statement, and a supported one. No env, no
options.apiKey, no options.keyFile and no stored key is you saying this gateway wants none: its
requests carry no authorization header and its roster is asked for without one. doctor reports it
as needing none rather than as missing one. A dummy apiKey would just teach people to write fake
credentials into a file they paste into issues.
One exception: a known name with no baseURL of its own. A block for openai, openrouter or
anthropic that states no baseURL is reached at a service that refuses every request without a key,
so naming no credential there means one is missing. bravebot auth status says it is not signed in,
doctor says none was found, and the request is refused with the remedy named. A block that states
its own baseURL, such as a local service reached under a known name, keeps the reading above. So
does a block that carries the credential in an Authorization header it names in headers.
A local Ollama, or another gateway that wants no key
Ollama wants no API key, so its block names none:
{
"provider": {
"ollama": {
"name": "Ollama (local)",
"npm": "ollama-ai-provider-v2",
"options": { "baseURL": "http://localhost:11434/api" }
}
},
"model": "ollama/qwen3-coder:30b"
}
A model written ollama/<name> while no provider block is named ollama is refused before any
request is sent, with a message naming the block to add. The same holds for the other ids bravebot
recognises: openrouter, openai, anthropic, lmstudio, llama-server, google-vertex,
cloudflare-workers-ai, cloudflare-ai-gateway and amazon-bedrock.
baseURL is written down because ollama is not one of the names an endpoint is
compiled in for. npm names Ollama's own SDK, so bravebot speaks Ollama's
own API at /api rather than its OpenAI-compatible one, and each request asks for the model's context
window, with room above what the session budgets for (Ollama). There is no models key, so Ollama
is asked what it has pulled and /model lists what came back. A first run with nothing configured offers to write this
block for you where Ollama is running (Importing from Claude Code, opencode or a local model
server).
LM Studio and llama-server want no key either. Ollama, LM Studio and llama-server each have a page that says how the first run finds the server, what its block looks like and what to state for its context window.
Which models are offered
A block that lists models is taken at its word, in the order you wrote them, and costs no round
trip. That is what keeps a configured gateway working with no network, and is the way to pin a short
list out of a service offering hundreds.
A block that lists none has the gateway asked, except on Google Vertex AI, which has no listing to ask. That is the ordinary case rather than a mistake: opencode resolves its roster from a registry it fetches, so the commonest block copied out of it names a credential and nothing else. What your credential may reach is asked for first, and the service's full catalogue answers only where a gateway does not offer the narrower question. Models that cannot call tools are left out.
Nothing is capped. Ordering does that work instead: the model a session would use comes first and the
rest are sorted by name. A listing that cannot be read contributes nothing and takes nothing away
from the rest of the roster, and the picker says which gateway's could not be read, by the name its
block gives it. The terminal says so in a note before the picker is drawn, and adds that one of its
models can be named as --model <id>/<model>. The desktop app shows a warning that names the gateway
and says to try again. A gateway whose block names a credential nothing holds is not asked and is not
mentioned in that note, since bravebot doctor reports the missing credential. A gateway whose block
lists its models is not asked.
whitelist and blacklist narrow a fetched roster without listing every model. Each is an array
of ids as the gateway names them. The whitelist is applied first and the blacklist then removes from
what remains, and the window a gateway reported is kept for each model left. An id the gateway does not
list changes nothing. Neither list applies to a block that lists models, which is offered as
written. bravebot doctor says how many ids each list names. Importing an opencode entry copies both.
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, the id being bravebot's own filing that no gateway has heard
of. A bare name your block lists still finds its gateway, so a choice already recorded by /model
keeps working.
The context window
limit.context is optional. A model that states none is assumed to have 131,072 prompt tokens, the
same deliberately low figure a Bedrock tier gets and for the same reason: a budget above the real
window does not compact a conversation late, it stops compacting it at all. A window a gateway reports
is taken where the file stated none; a figure in the file outranks it. options.contextWindow is the
figure for every model of the provider that states none, and is the place to keep one for a block
that lists no models, such as LM Studio, whose window is one server setting. A model's own
limit.context outranks it, and a gateway's report does not. The LM Studio import writes it where
the server holds the model with fewer than 131,072 tokens. Following opencode, limit
needs output alongside context or it is not a limit and its figure is not read. output states
how far a reply may run.
What a model's options can and cannot do
Whatever you put there reaches the request body as it stands. Nothing parses it, knows what any of its fields mean, or validates them, so a misspelled routing field is a request the gateway rejects, or worse one it silently routes somewhere you did not intend.
It cannot replace what the turn itself built. The settings file names a destination, not what was
asked. It also cannot add a tool list: tools and tool_choice in a model's options or in a
variant are left out of every request, and so are functions, function_call and
parallel_tool_calls for an OpenAI-compatible gateway, mcp_servers for Anthropic and toolConfig
or tool_config for Google. The tools a request offers are the ones bravebot chose for it, and a
request that offers none, such as a processor's or a check's, stays one that offers none.
Switching between sets of options with variants
A model may carry variants: named sets of the same kind of fields options holds, which you pick
between during a session.
{
"provider": {
"my-gateway": {
"options": { "baseURL": "https://gateway.example/v1" },
"models": {
"my-model": {
"variants": {
"deep": { "reasoningEffort": "high", "textVerbosity": "low" },
"quick": { "reasoningEffort": "low" },
"retired": { "disabled": true }
}
}
}
}
}
}
/variant lists the names the model in force offers, /variant deep picks one, and /variant off
drops the pick. Nothing is in force until you type a name, and the pick lasts for the session. The
chosen set is merged into the request as the model's options are, over them where both set a field,
and never over what the turn built, so the level /effort chose is the one sent. A variant marked
"disabled": true is not listed. A name the model has no variant for adds nothing.
Showing a model's thinking
A model that sends its working in a reasoning_content field beside its reply has that working drawn
under /thinking while the reply is still arriving. Nothing in the
request asks for it, so a model that sends none shows none, and a service that names the field
differently shows nothing. It is not saved to the session and is not sent back in a later request.
Retries and a reply gone quiet
A request that fails because the connection gave out, because the name of the host did not resolve, because the network is down or unreachable, or because the service said it was busy, is sent again for five minutes after the first failure. The pause before each attempt doubles from one second and stops growing at one minute, so a machine that wakes without a network, a VPN that reconnects or a service that recovers within a few minutes is reached without anyone asking again. Typing a message while it waits sends that message at once instead of waiting for the next attempt. A mistyped host is therefore sent again for those five minutes before the failure is reported, since a name that does not exist and a network that is not up yet cannot be told apart by the failure.
A reply that stopped before it was finished, or that the service reported as failing part way
through, is sent again twice, because each attempt is billed. A reply that is still arriving is
given up on when nothing has come for two minutes. A reply that goes quiet before any of its body has
arrived is sent again as a failed connection is. All three are figures you can change for one
gateway in its options:
{
"provider": {
"my-gateway": {
"options": {
"baseURL": "https://gateway.example/v1",
"maxRetries": 4,
"retryWindowMs": 3600000,
"idleTimeoutMs": 300000
}
}
}
}
maxRetries is how many times a request is sent again, so 4 is five requests in all and 0
sends each one once. It is at most 7. retryWindowMs is how long after its first failure a request
whose connection failed, or that the service said to try again later, is still sent again: stated,
it applies to those failures whatever maxRetries says, and it is at most 3600000, one hour. Stating
maxRetries and no window leaves only the count in force, so maxRetries: 0 still sends each
request once. idleTimeoutMs is for a model that thinks for longer than two minutes before it
writes; it is at most 600000, ten minutes. All three are written as numbers: "0" in quotes, a
fraction, a negative figure and a window or gap of 0 leave the figure at what it was, and a figure
above its limit is the limit.
Only the count and the waits change. Which failures are sent again does not: a refused credential or
a model the service does not have is refused the same way each time, whatever count you gave. A wait
the service asked for with a Retry-After, up to two minutes, is taken before each retry in place of
the pause, so a large count or window against a service that keeps asking for it is a long wait.
A rate limit (HTTP 429) that carries no usable Retry-After is sent again up to five times where you
state no maxRetries, after waits of 8, 16, 32, 64 and 120 seconds, 240 seconds in all. A count you
state replaces that figure as it replaces the two retries of every other failure, so 2 sends a rate
limit three times and 0 once, and each wait of the schedule is taken before each retry, up to two
minutes. A count of 7 against a limit that never lifts is held for about eight minutes of waiting.
A gateway on this machine, such as a local Ollama, is waited on through any silence while you can
stop the turn, so idleTimeoutMs does not reach it. maxRetries does.
These three are read from your own settings.json, from a file --settings names, and from the
machine-level file an administrator keeps. A .bravebot/settings.json in a checkout cannot set them,
as it cannot name a gateway: bravebot doctor says so when one tries. Brave's own endpoint and the
models you reach through the Bedrock tier variables alone have no entry to put them in and keep the
defaults. An AWS Bedrock entry takes the same two.