Get 6% back at Conifer with an ernd card
SectionsAPI reference

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 null is 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: off stops 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 store off 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_key of 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.
ClientBase URL
OpenAI SDKshttps://gateway-api.conifer.build/v1
Anthropic SDKshttps://gateway-api.conifer.build

Routes

RouteWhat it doesKey
POST /v1/chat/completionsOpenAI Chat Completions, for any model or router, streamed or not.Yes
POST /v1/messagesAnthropic Messages, for any model or router.Yes
POST /v1/messages/count_tokensCounts a Messages request’s input tokens. Free.Yes
POST /v1/responsesOpenAI Responses. State kept between requests needs the workspace’s own OpenAI key.Yes
POST /v1/responses/compactOpenAI compaction, for models with an OpenAI host. Doesn’t stream.Yes
POST /v1/embeddingsEmbeddings. Doesn’t stream, and takes a model, not a router.Yes
POST /v1/images/generationsOpenAI images, made from a prompt, for a model that makes them. Takes a model, not a router.Yes
POST /v1/images/editsOpenAI image edits, sent as a form, for a model that makes images.Yes
GET /v1/modelsThe 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/catalogThe public catalog, with list prices.No
GET /v1/statusHow each provider has served: uptime, time to first token, speed.No
GET /v1/usageUsage by hour or by day, as the console’s Dashboard shows it.Yes
GET /v1/balanceThe balance and the month. Read-only keys only.Yes
GET /v1/requestsThe 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.

HeaderWhat it does
anthropic-versionThe 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-betaPassed to the hosts that speak Messages. On the workspace’s own key, every anthropic- header goes as sent.
Idempotency-KeyRuns the request once, below.
x-conifer-max-cost-nanousdThe 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-cacheOn 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

HeaderWhenWhat it says
x-conifer-request-idEvery response, errors among themThe request’s id: req_ and 26 more characters.
x-request-id, request-idEvery responseThe same id, under the header OpenAI’s SDKs read, or Anthropic’s on Messages.
x-conifer-modelAnswersThe model that answered, by its catalog id.
x-conifer-routerRouted answersThe 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-nanousdWhole answersWhat 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-keyA whole answer served on your own provider keytrue: the cost is what that provider charges, and nothing came off the balance.
x-conifer-keepaliveA slow whole answercommitted: the 200 went out after 45 seconds, with whitespace sent until the body was ready.
x-conifer-replayedAn answer sent againtrue: the answer is the first request’s, for its Idempotency-Key, charged once.
x-conifer-replay-ofA 409 or 422 for a reused Idempotency-KeyThe id of the request the key was first sent with.
retry-afterSome 409, 429 and 503 errorsThe seconds to wait before sending again.
x-should-retryErrors a retry can’t helpfalse, which OpenAI’s and Anthropic’s SDKs obey.
www-authenticate401 errorsBearer

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.

response
{"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
 }}
FieldWhat it says
routerThe router and version. Absent when the request named a model.
servedThe model and provider that served the request.
fallbackWhether the router’s pick failed before its first token and a fallback answered.
fallback_reasonWhy 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_nanousdWhat the request cost: every meter at the model’s list price, less any discount.
list_nanousd, discount_bpsWhere a discount was given: the cost before it, and how much came off, in hundredths of a percent.
own_keytrue where your own provider key served it.
moved_for_spend_limittrue where the key’s spend limit moved the request to the router’s cheapest model.
passed_nanousdWhere the router’s pick answered with nothing usable and another model answered, what that empty answer is charged, beside the cost.
decision_nanousdOnly 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_conflict with retry-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

LimitValue
Request body32 MiB uncompressed, nested at most 128 levels, arriving within 120 seconds. Too large answers 413 request_too_large.
A request in all870 seconds (14.5 minutes); then a stream ends cleanly.
Connecting to a provider10 seconds.
One attempt600 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 output280 seconds, or 600 at the flex tier.
A provider’s count of tokens, or the rest of its refusal60 seconds.
A new attemptNot started with less than 30 seconds of the request left.
A client that stops readingDisconnected 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.