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

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

Non-streaming

Response headers

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.

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-modeBearer, 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