Gateway
Conifer Gateway API reference
Every route, header and field the gateway serves, in one place.
The Conifer Gateway API speaks OpenAI’s and Anthropic’s formats at one address. This page lists what the gateway adds and reads: its routes, headers, the router object, streaming, idempotency and limits. Errors has every error code.
A request takes each format’s own body, which the gateway passes to the model as sent, translating between formats where the provider speaks another, apart from these:
- A member set to
nullis left out, and an output cap above what the provider writes is lowered to the provider’s own. - On a Claude host, a Chat Completions or Responses conversation that offers tools or is past its first turn gets prompt-cache breakpoints from the gateway, on its head and its newest turn.
x-conifer-cache: offstops that. - OpenAI’s hosts are sent a keyed hash of the workspace as
safety_identifier, in place of any the request sets. - On Conifer’s keys, which every workspace shares, a Responses request goes with
storeoff and asks for its reasoning encrypted, so the next turn can send it back. - On Conifer’s keys, OpenAI’s hosts are sent a
prompt_cache_keyof the gateway’s, so each workspace’s prompt cache stays its own: a conversation the request names keeps a key of its own, and one known only by its opening shares its workspace’s. On the workspace’s own key, the request’s goes as sent. - Where Conifer marks an OpenAI host as answering sooner through Responses, a Chat Completions request goes there first, translated, and its answer carries a
resp_id. - A router’s instructions go first in the conversation, as a system message.
| Client | Base URL |
|---|---|
| OpenAI SDKs | https://gateway-api.conifer.build/v1 |
| Anthropic SDKs | https://gateway-api.conifer.build |
Routes
| Route | What it does | Key |
|---|---|---|
POST /v1/chat/completions | OpenAI Chat Completions, for any model or router, streamed or not. | Yes |
POST /v1/messages | Anthropic Messages, for any model or router. | Yes |
POST /v1/messages/count_tokens | Counts a Messages request’s input tokens. Free. | Yes |
POST /v1/responses | OpenAI Responses. State kept between requests needs the workspace’s own OpenAI key. | Yes |
POST /v1/responses/compact | OpenAI compaction, for models with an OpenAI host. Doesn’t stream. | Yes |
POST /v1/embeddings | Embeddings. Doesn’t stream, and takes a model, not a router. | Yes |
POST /v1/images/generations | OpenAI images, made from a prompt, for a model that makes them. Takes a model, not a router. | Yes |
POST /v1/images/edits | OpenAI image edits, sent as a form, for a model that makes images. | Yes |
GET /v1/models | The routers, then the models, the key may call. | Yes |
GET /v1/models/{id} | One model, by id or alias, or one router. | Yes |
GET /v1/catalog | The public catalog, with list prices. | No |
GET /v1/status | How each provider has served: uptime, time to first token, speed. | No |
GET /v1/usage | Usage by hour or by day, as the console’s Dashboard shows it. | Yes |
GET /v1/balance | The balance and the month. Read-only keys only. | Yes |
GET /v1/requests | The request log, a page at a time, up to 31 days per query. | Yes |
GET /v1/requests/{request} | One request, with its receipt line by line. | Yes |
An images request needs a model that makes images, and Models says which do today. Any other route answers 404 route_not_found, the routes that read a stored response, such as GET /v1/responses/{id}, among them, and a route sent with the wrong method answers 405 method_not_allowed.
Authentication
OpenAI’s SDKs send a key in Authorization: Bearer, and Anthropic’s in x-api-key. An api-key header is also read. When a request sends more than one, Authorization wins, then x-api-key. A missing or wrong key answers 401 invalid_api_key with www-authenticate: Bearer. API keys covers what a key may be limited to.
Request headers
Beside a key, these are the headers the gateway reads.
| Header | What it does |
|---|---|
anthropic-version | The Messages API version Anthropic’s SDKs send, such as 2023-06-01, which the gateway sends where a request leaves it out. On a route that reads, such as GET /v1/models, it asks for Anthropic’s shapes, its errors’ among them. |
anthropic-beta | Passed to the hosts that speak Messages. On the workspace’s own key, every anthropic- header goes as sent. |
Idempotency-Key | Runs the request once, below. |
x-conifer-max-cost-nanousd | The most the request may cost, in whole nanodollars, sent once. One whose worst case at list price is more answers 422 no_eligible_model, giving both figures, before anything is held or sent; through a router, the models it leaves out are passed over first. |
x-conifer-cache | On Chat Completions and Responses, off stops the gateway placing prompt-cache breakpoints of its own on the request. It never turns caching on, and breakpoints the request sets stay. |
The gateway also reads a coding tool’s session header to recognise a conversation, as Routing says.
Response headers
| Header | When | What it says |
|---|---|---|
x-conifer-request-id | Every response, errors among them | The request’s id: req_ and 26 more characters. |
x-request-id, request-id | Every response | The same id, under the header OpenAI’s SDKs read, or Anthropic’s on Messages. |
x-conifer-model | Answers | The model that answered, by its catalog id. |
x-conifer-router | Routed answers | The router and version, such as custom-router-support@7, or auto@0 for a default router nobody has saved. An answer sent again for its Idempotency-Key says it in its body alone. |
x-conifer-cost-nanousd | Whole answers | What the request cost, in nanodollars. Absent on streams, on a slow answer whose head went early, and when its use can’t be priced. |
x-conifer-own-key | A whole answer served on your own provider key | true: the cost is what that provider charges, and nothing came off the balance. |
x-conifer-keepalive | A slow whole answer | committed: the 200 went out after 45 seconds, with whitespace sent until the body was ready. |
x-conifer-replayed | An answer sent again | true: the answer is the first request’s, for its Idempotency-Key, charged once. |
x-conifer-replay-of | A 409 or 422 for a reused Idempotency-Key | The id of the request the key was first sent with. |
retry-after | Some 409, 429 and 503 errors | The seconds to wait before sending again. |
x-should-retry | Errors a retry can’t help | false, which OpenAI’s and Anthropic’s SDKs obey. |
www-authenticate | 401 errors | Bearer |
The router object
The gateway adds one field, router, to every answer’s JSON, beside the model’s own. The body’s model names the model that answered. A whole answer carries the field in its body; a stream carries it on its final event.
{"model": "claude-haiku-5-5", "choices": [ … ], "usage": { … },
"router": {
"router": "custom-router-support@7",
"served": {"model": "claude-haiku-5-5", "provider": "anthropic"},
"fallback": true,
"fallback_reason": "rate_limited",
"cost_nanousd": 5800
}}| Field | What it says |
|---|---|
router | The router and version. Absent when the request named a model. |
served | The model and provider that served the request. |
fallback | Whether the router’s pick failed before its first token and a fallback answered. |
fallback_reason | Why the pick was left, where a fallback answered: timeout, connection, rate_limited, server_error, context_length, content_policy, invalid_request, empty_answer or thinking_refused. |
cost_nanousd | What the request cost: every meter at the model’s list price, less any discount. |
list_nanousd, discount_bps | Where a discount was given: the cost before it, and how much came off, in hundredths of a percent. |
own_key | true where your own provider key served it. |
moved_for_spend_limit | true where the key’s spend limit moved the request to the router’s cheapest model. |
passed_nanousd | Where the router’s pick answered with nothing usable and another model answered, what that empty answer is charged, beside the cost. |
decision_nanousd | Only where routing decisions are charged, which they aren’t unless Conifer sets it. |
The answer carries the total. The receipt line by line, each meter with its units, price and cost, is in GET /v1/requests/{request}, as lines, and on the console’s Logs page.
Streaming
Chat Completions, Messages and Responses stream as server-sent events; embeddings, images and compaction don’t. On a stream, the router object and its cost arrive with the final event: the last Chat Completions chunk before data: [DONE], Messages’ message_stop, or Responses’ final event. The response’s head goes out with the first text, refusal or tool call, or after 15 seconds of reasoning; if nothing has come 15 seconds after the request arrived, it goes out then, or for a routed request that can still move to another model, after up to 45 seconds. After the head, the gateway sends a comment whenever the stream is quiet for 15 seconds. A stream whose client goes away is read to its end and charged what the provider produced.
Idempotency
Send Idempotency-Key, 1 to 255 printable ASCII characters, to run a request once; a key of another shape, or sent twice, answers 400. Without it, nothing is replayed.
- A whole answer of up to 1 MiB, asked for again within 24 hours of the first request, comes back as the same JSON, byte for byte, under the first request’s ids, with
x-conifer-replayed: true, and isn’t charged again. - Sent while the first request still runs, it answers 409
idempotency_conflictwithretry-after: 5. - A stream’s answer, or one larger than 1 MiB, isn’t kept: sent again after the first ran, it answers 409 with
x-should-retry: false. - The same key with another body answers 422
idempotency_key_reused. - Replays stop for the day once a workspace’s have sent a gibibyte of answers.
The answer is kept sealed for those 24 hours; Data handling says more.
Limits and timeouts
| Limit | Value |
|---|---|
| Request body | 32 MiB uncompressed, nested at most 128 levels, arriving within 120 seconds. Too large answers 413 request_too_large. |
| A request in all | 870 seconds (14.5 minutes); then a stream ends cleanly. |
| Connecting to a provider | 10 seconds. |
| One attempt | 600 seconds for a whole answer to end, or for a stream’s first output, its reasoning or its words, each silence counted from the last thing the provider sent. A provider that timed out isn’t asked again where it waited longer than the request has left. |
| A provider silent during a stream, after its first output | 280 seconds, or 600 at the flex tier. |
| A provider’s count of tokens, or the rest of its refusal | 60 seconds. |
| A new attempt | Not started with less than 30 seconds of the request left. |
| A client that stops reading | Disconnected after 120 seconds. |
Rate limits are optional and set on a key or a saved router. A limit of L requests a minute lets L through at once, then one every 60/L seconds, and past it answers 429 rate_limited with retry-after.
Maintenance
While the API is paused for maintenance, every route that takes a key answers 503 maintenance, with a message and retry-after. A server that hasn’t confirmed keys with the database for 15 minutes answers 503 unavailable with retry-after: 30. Either way nothing is sent or charged, and GET /v1/catalog and GET /v1/status still answer.
CORS
Browsers may call /v1 from any origin. A preflight OPTIONS answers 204 at once, granting the request headers it asks for, and every response names the headers a browser may read. No request carries credentials but the key it sends, and a key in a web page can be read by anyone who opens it.