Skip to main content
POST
POST /v1/chat/completions Send a chat request to any supported provider through the gateway. The response format is identical to OpenAI’s chat completions API regardless of which provider handles the request.

Auth

All three schemes are accepted:
Bearer (OIDC) is supported but in Alpha. Contact us if you need OIDC auth.

Request

Content blocks

messages[].content may be a string or an array of content blocks:
Remote URLs are fetched server-side with SSRF checks and a shared deadline. Text files are inlined as text on every model; images and documents require a model with the matching capability. Anthropic accepts images and PDF documents only. See prompt file variables for the dashboard upload flow.

Gateway-specific fields

Metadata

metadata lets you attach business context to a request — environment, feature, session, tenant, experiment — without polluting the provider call:
Rules:
  • Values must be string, number, or boolean — nested objects and arrays are rejected (400)
  • Keys are limited to 64 characters and values to 128 characters; at most 100 keys per request
  • The field is stripped before forwarding to the provider — it never reaches the upstream API
  • It appears on the log entry and can be filtered with key=value in the dashboard
The gateway also accepts user in the body — a standard OpenAI field. It is forwarded to OpenAI-compatible providers unchanged, and used as the logged end-user ID when no signed-token claim or x-gatelit-end-user-id header set one. (Non-OpenAI providers that lack the field — e.g. Anthropic, Google — ignore it; the gateway still logs it.)

Response caching

cache opts into an exact-match response cache. Only deterministic requests are eligible — non-streaming, explicit temperature: 0, no tools — and only successful responses are stored, so a failure retry always hits the upstream provider fresh.
  • true — cache with the default TTL (5 minutes)
  • { "ttl": 3600 } — custom TTL in seconds; must be positive and is clamped to 60–3600
  • false — bypass both reads and writes; pass this when you explicitly retry for a fresh answer
The cache key is scoped to org + model + the full request body (minus gateway-internal fields) + output schema, so changing response_format, seed, or any other parameter produces a distinct entry. A fallback-winning response is cached under the model that actually answered. The response header tells you what happened:

Response

Non-streaming

Response headers

Params are forwarded to the provider as-is within the resolved model’s catalog limits. The gateway clamps out-of-range values (e.g. max_tokens above the model’s cap) rather than erroring — when that happens, x-gatelit-clamped tells you what changed. The provider enforces the budget itself: a response that ends with finish_reason: "length" hit the max_tokens cap. Streaming responses surface the same header; the final SSE chunk carries the model’s finish_reason.

Streaming

When stream: true, the response is an OpenAI-compatible SSE stream. Each data: line is a JSON chunk. Final line is data: [DONE].

Examples

Structured output

With fallback chain

Trigger conditions (triggers): rate_limit, provider_error, timeout, refusal_detected. Without triggers, the fallback fires on any failure. A fallback candidate never falls through when its provider is disabled for your org — it is skipped in order.

Errors

Authorizations

Authorization
string
header
required

OIDC JWT issued by your auth provider (Alpha). Full self-serve configuration is coming soon — contact us for early access. Use this for browser/frontend clients where a user is signed in.

Body

application/json
model
string
required

Model in provider/model-id format. Supported providers: openai, anthropic, google, mistral.

Examples:

"openai/gpt-4o"

"anthropic/claude-3-5-sonnet-20241022"

"google/gemini-2.5-flash"

"mistral/mistral-large-latest"

messages
object[]
required
Minimum array length: 1
max_tokens
integer

Maximum tokens to generate. The gateway maps this to the correct upstream parameter — max_completion_tokens for OpenAI reasoning models, max_tokens for everything else.

Example:

1024

temperature
number

Sampling temperature. Omit for reasoning models (o3, o3-mini, o4-mini) — the gateway strips it automatically based on the model catalog.

Required range: 0 <= x <= 2
Example:

0.7

top_p
number

Nucleus sampling. Supported by all providers.

Required range: 0 <= x <= 1
stream
boolean
default:false

When true, the response is an OpenAI-compatible SSE stream. Each data: line is a JSON object regardless of the upstream provider.

user
string

End-user identifier (standard OpenAI field). Forwarded to the provider unchanged, and used as the logged end-user ID when no signed-token claim or x-gatelit-end-user-id header is present.

Example:

"customer_42"

metadata
object

Arbitrary tags attached to the request — environment, feature, session, tenant, and so on. Values must be string, number, or boolean; keys are limited to 64 characters and string values to 128 characters. Stripped before forwarding to the provider, stored on the log entry, and filterable in the dashboard.

Example:
output_schema
object

Structured output configuration. The gateway translates to the correct provider-specific format automatically.

prompt_id
string

Associates this request with a saved prompt in the dashboard. The prompt's content is not used — only the ID is logged for correlation.

fallback_chain
object[]

Ordered list of fallback models to try if the primary model fails. Each entry specifies a model and the error types that trigger it.

cache

Opt-in exact-match response cache. Only deterministic requests are cached — non-streaming, explicit temperature: 0, no tools — and only successful upstream responses are stored. Cache reads happen before any upstream call; a fallback-winning response is cached under the model that actually answered. The response header x-gatelit-cache reports HIT, MISS, or BYPASS.

Response

Successful response.

  • Non-streaming: Content-Type: application/json
  • Streaming: Content-Type: text/event-stream

Response headers always include:

  • x-gatelit-request-id — use for log lookup in the dashboard
  • x-gatelit-model — the provider/model that responded
  • x-gatelit-auth-mode — Bearer, GatelitSigned, or GatelitKey

OpenAI-compatible chat completion response. Returned when stream is false (default).

id
string
object
string
Example:

"chat.completion"

created
integer
model
string

The upstream model that handled the request.

choices
object[]
usage
object