# Text generation API

## POST /v1/chat/completions

`POST /v1/chat/completions` · operation `createChatCompletion`

OpenAI-compatible JSON forwarded to an eligible target after replacing `model`
with the configured upstream model. With gemini_file_inputs (T199), a Gemini
target accepts a file content part, in a user message or a tool message:
`{"type":"file","file":{...}}` with exactly one of file_data (base64 or a base64
data URL), file_id or file_url (a gs:// object or a Files API URI under
file_inputs.reference_prefixes), an optional format (MIME type) and filename, and
the slice the provider reads and bills: document_metadata {start_page, end_page,
content_layers: [page_image, page_text]}, spreadsheet_metadata {sheet_index,
visible_cells, content_layers: [data, formulas, visual]}, video_metadata
{start_offset, end_offset, fps} and resolution (low, medium, high, or ultra_high
for images). An invalid or unapproved file part answers 422
unsupported_on_provider before any provider call. On a target that is not Gemini
the slice fields follow the alias's unsupported_parameters: refused by name, or
dropped and listed in X-Gateway-Dropped-Parameters. A 429/5xx response can trigger a configured
fallback before response bytes are sent. Streams cannot resume after first byte.
playground_streaming controls the console text streaming experience only; it
does not revoke this existing public SSE contract or authorize inference. The
console requests streaming explicitly with a separately supplied bearer key.
An applicable budget_limits or tpm_limits policy restricts admission to the
documented explicit protocol/unit quota profile with an explicit output
bound, no stream/tools/media/cache/retry, and approved exact rates for budget.
Quota profile mismatch returns 422 before any provider call. Unknown outcomes
retain their reservation; provider overages are debited, not truncated.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Gateway-Timeout-Ms` | header | string, max length 8, pattern `^[0-9]+$` | One decimal integer from 1 to 86400000 milliseconds. With request_timeout_header enabled it can only lower the total deadline, or every independent stream clock (including an otherwise disabled idle clock). Ignored when the header flag is disabled. Never forwarded upstream. |
| `X-Gateway-Tags` | header | string, max length 2048 | Optional explicit JSON string map for model inference only. With usage_tag_defaults, finite defaults come from the authenticated team and explicit values override matching names; an absent header or an empty JSON object preserves defaults. One header, at most 2 KiB and eight pairs; finite configured enum. Requires usage_tags and authentication/model/team/RPM admission. Never forwarded or added to logs/traces/metric labels/cache identity. Not supported for MCP or models inventory. Tags do not authorize access or establish financial attribution. |
| `X-Gateway-Add-Guardrails` | header | string, max length 600 | request_guardrails (T164.006). Optional comma-separated list of 1-8 distinct guardrail IDs added to this Chat Completions, Messages or Responses request. Each must exist, apply to the alias and list the key's team (or *) in selectable_teams; otherwise 403 guardrail_not_selectable before any guardrail or provider call. The header only adds checks; it never removes a configured one. With the flag off it is refused with 400 request_guardrails_disabled, never ignored. |
| `X-Gateway-End-User` | header | string, min length 1, max length 128 | Optional client-declared end user (1–128 printable characters) recorded under end_user_tracking. Takes precedence over the OpenAI user body field. Untrusted metadata: never authorization, routing, cache identity or a log/metric label. Required when the key's or its team's require block sets end_user (attribution_requirements): a request without it answers 400 missing_attribution before any provider call. |
| `X-Gateway-Session-Id` | header | string, min length 1, max length 128 | Optional client-declared session or agent-run ID (1–128 printable characters) recorded under session_tracking to group requests in logs. Untrusted metadata: never authorization, routing or cache identity. |
| `X-Gateway-Agent-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared agent that made this request (1–128 printable characters), kept with the session's agent graph. Asserted, never authentication; ignored with the flag off; an invalid or repeated value answers 400 invalid_agent_context. |
| `X-Gateway-Turn-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared turn this request belongs to (1–128 printable characters). Asserted; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Parent-Session-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional session that spawned this one (a sub-agent run), 1–128 printable characters. Asserted; ignored when equal to X-Gateway-Session-Id; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Feedback-Key` | header | string, min length 1, max length 200, pattern `^[\x21-\x7E]{1,200}$` | evaluation_results (T186.003). Optional external ID (a ticket or incident number) that feedback results join on with join_key: 1–200 printable ASCII characters without spaces, one value. Stored on the request log row and the request span; never a usage tag, a metric label or an analytics dimension. Ignored with the flag off; an invalid or repeated value answers 400 invalid_feedback_key. |
| `X-Gateway-Prompt-Render` | header | string, max length 512, pattern `^gpr_` | prompt_tracking (T186.013). The render token the published-prompt render answered: the request records that prompt and revision as rendered. Attribution only, never a refusal: a token of another team, a forged one, one past prompt_tracking.render_token_ttl, or a team whose plan lacks prompt_tracking records nothing and the answer carries X-Gateway-Prompt-Tracking (other_team, invalid_signature, malformed, expired, not_entitled, entitlement_unavailable). With X-Gateway-Prompt-Id and X-Gateway-Prompt-Revision they must name the token's prompt and revision (400 invalid_prompt_declaration); two tokens answer 400 invalid_prompt_render. Ignored with the flag off. |
| `X-Gateway-Prompt-Id` | header | string, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` | prompt_tracking (T186.013). The registry prompt the client built the request from, recorded as declared: a claim, never authorization, and only on the rows of the key's own team. Read while prompt_tracking.declared_headers is true (default); one value; an invalid one answers 400 invalid_prompt_declaration. |
| `X-Gateway-Prompt-Revision` | header | string, pattern `^[1-9][0-9]?$\|^100$` | prompt_tracking (T186.013). The revision (1-100) of X-Gateway-Prompt-Id; optional, recorded as declared. |
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required) — Public model alias
  - `messages` (array of object, required, min items 1)
  - `stream` (boolean, default `false`)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Upstream chat response or SSE stream | `application/json`: object<br/>`text/event-stream`: string |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `422` | Protected request profile or approved exact rate is unsupported | — |
| `429` | Gateway RPM, key or team concurrency cap (concurrency_limit_exceeded, T135) or applicable token/USD quota ceiling reached; the request was not forwarded upstream. | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local admission unavailable or shared quota storage/base unavailable before provider call | — |
| `default` | Provider status, content type and body passed through after model alias replacement. | `application/json`: object<br/>`application/octet-stream`: string (binary) |


## POST /v1/responses

`POST /v1/responses` · operation `createOpenAIResponse`

OpenAI Responses JSON/SSE. Requires openai_responses flag, route:responses scope
and a model alias with responses capability. On openai targets with the responses
API (the default) it is a native passthrough: the gateway replaces only model, then
sends its provider credential. When a target is another provider, or an openai target
with api chat_completions, the stateless profile is translated through the canonical
Chat Completions format (ADR 0172): store true, previous_response_id, conversation,
background, prompt templates and built-in tools answer 422 unsupported_translation,
and the answer is never stored. With gemini_file_inputs (T199) an input_file
part, in a user message or a function_call_output, translates to the canonical
file part: file_data, file_url or file_id, filename, format and the slice members
document_metadata, spreadsheet_metadata, video_metadata and resolution, as on
Chat Completions.
Requests are not automatically retried or failed over because Responses can be
stateful or invoke tools. With responses_lifecycle (ADR 0112) the returned id is a
signed, key-bound gateway ID (resp_gw1.…): a previous_response_id carrying it is
routed to the provider that created the response, even on a multi-target alias,
and background:true is accepted. With conversations (ADR 0120) conversation takes a
gateway conversation ID (conv_gw1.…) of the caller's team, routed to the provider
holding it even on a multi-target alias, and the response's conversation.id comes
back as that gateway ID; a raw or foreign conversation ID answers 404. With
containers (ADR 0123), every container the request names (a code_interpreter tool
container, a shell tool container_reference, or the container_id of a
code_interpreter_call or shell_call input item) must belong to the caller's team (or
teamless key): otherwise 404 container_not_found before any provider call. The call
goes to the provider holding those containers, even on a multi-target alias (422
conflicting_state when they, or the stored state, live at different providers). An
auto container with file_ids is refused (400 invalid_container): those IDs name
provider files. Containers the provider creates in auto mode become the caller's.
Without these flags, previous_response_id and conversation require a single-target alias
and background:true is rejected. OpenAI may store response data unless the client
sets store:false.
JSON usage is recorded; stream_usage observes explicit terminal SSE usage only in its bounded native profile.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Gateway-Timeout-Ms` | header | string, max length 8, pattern `^[0-9]+$` | One decimal integer from 1 to 86400000 milliseconds. With request_timeout_header enabled it can only lower the total deadline, or every independent stream clock (including an otherwise disabled idle clock). Ignored when the header flag is disabled. Never forwarded upstream. |
| `X-Gateway-Tags` | header | string, max length 2048 | Optional explicit JSON string map for model inference only. With usage_tag_defaults, finite defaults come from the authenticated team and explicit values override matching names; an absent header or an empty JSON object preserves defaults. One header, at most 2 KiB and eight pairs; finite configured enum. Requires usage_tags and authentication/model/team/RPM admission. Never forwarded or added to logs/traces/metric labels/cache identity. Not supported for MCP or models inventory. Tags do not authorize access or establish financial attribution. |
| `X-Gateway-Add-Guardrails` | header | string, max length 600 | request_guardrails (T164.006). Optional comma-separated list of 1-8 distinct guardrail IDs added to this Chat Completions, Messages or Responses request. Each must exist, apply to the alias and list the key's team (or *) in selectable_teams; otherwise 403 guardrail_not_selectable before any guardrail or provider call. The header only adds checks; it never removes a configured one. With the flag off it is refused with 400 request_guardrails_disabled, never ignored. |
| `X-Gateway-End-User` | header | string, min length 1, max length 128 | Optional client-declared end user (1–128 printable characters) recorded under end_user_tracking. Takes precedence over the OpenAI user body field. Untrusted metadata: never authorization, routing, cache identity or a log/metric label. Required when the key's or its team's require block sets end_user (attribution_requirements): a request without it answers 400 missing_attribution before any provider call. |
| `X-Gateway-Session-Id` | header | string, min length 1, max length 128 | Optional client-declared session or agent-run ID (1–128 printable characters) recorded under session_tracking to group requests in logs. Untrusted metadata: never authorization, routing or cache identity. |
| `X-Gateway-Agent-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared agent that made this request (1–128 printable characters), kept with the session's agent graph. Asserted, never authentication; ignored with the flag off; an invalid or repeated value answers 400 invalid_agent_context. |
| `X-Gateway-Turn-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared turn this request belongs to (1–128 printable characters). Asserted; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Parent-Session-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional session that spawned this one (a sub-agent run), 1–128 printable characters. Asserted; ignored when equal to X-Gateway-Session-Id; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Feedback-Key` | header | string, min length 1, max length 200, pattern `^[\x21-\x7E]{1,200}$` | evaluation_results (T186.003). Optional external ID (a ticket or incident number) that feedback results join on with join_key: 1–200 printable ASCII characters without spaces, one value. Stored on the request log row and the request span; never a usage tag, a metric label or an analytics dimension. Ignored with the flag off; an invalid or repeated value answers 400 invalid_feedback_key. |
| `X-Gateway-Prompt-Render` | header | string, max length 512, pattern `^gpr_` | prompt_tracking (T186.013). The render token the published-prompt render answered: the request records that prompt and revision as rendered. Attribution only, never a refusal: a token of another team, a forged one, one past prompt_tracking.render_token_ttl, or a team whose plan lacks prompt_tracking records nothing and the answer carries X-Gateway-Prompt-Tracking (other_team, invalid_signature, malformed, expired, not_entitled, entitlement_unavailable). With X-Gateway-Prompt-Id and X-Gateway-Prompt-Revision they must name the token's prompt and revision (400 invalid_prompt_declaration); two tokens answer 400 invalid_prompt_render. Ignored with the flag off. |
| `X-Gateway-Prompt-Id` | header | string, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` | prompt_tracking (T186.013). The registry prompt the client built the request from, recorded as declared: a claim, never authorization, and only on the rows of the key's own team. Read while prompt_tracking.declared_headers is true (default); one value; an invalid one answers 400 invalid_prompt_declaration. |
| `X-Gateway-Prompt-Revision` | header | string, pattern `^[1-9][0-9]?$\|^100$` | prompt_tracking (T186.013). The revision (1-100) of X-Gateway-Prompt-Id; optional, recorded as declared. |
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required) — Public model alias
  - `input` (any) — Native Responses input string or array
  - `stream` (boolean, default `false`)
  - `store` (boolean) — Provider-side response storage policy; set false for stateless requests
  - `background` (boolean) — Accepted only with responses_lifecycle; poll GET /v1/responses/{id} and cancel with POST /v1/responses/{id}/cancel. Under budgets or TPM it needs quota_background_responses (T168): the reservation made at create is held until the response ends, then settled at the exact usage (stream must be false, store must not be false)
  - `previous_response_id` (string) — A gateway response ID (responses_lifecycle) is routed to its origin provider; any other ID requires a single-target alias
  - `conversation` (any) — A gateway conversation ID (string or {id}) with conversations; without the flag, any ID requires a single-target alias

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Native OpenAI Response JSON or SSE stream | `application/json`: object<br/>`text/event-stream`: string |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `422` | Model does not support this operation | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `429` | Gateway RPM, key or team concurrency cap (concurrency_limit_exceeded, T135) or applicable token/USD quota ceiling reached; the request was not forwarded upstream. | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `default` | Provider status, content type and body passed through after model alias replacement. | `application/json`: object<br/>`application/octet-stream`: string (binary) |


## Retrieve a stored response

`GET /v1/responses/{id}` · operation `getOpenAIResponse`

Requires responses_lifecycle and route:responses. The ID is signed and bound to the key that created it; another key, a tampered ID or a raw provider ID answers 404 without calling the provider. Query parameters (include[], stream, starting_after) pass through.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required | Gateway response ID returned by POST /v1/responses (resp_gw1.…) |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Provider Response object (JSON, or SSE with stream=true) with the gateway ID. With quota_background_responses (T168), a JSON object showing a tracked background response ended settles its budget reservation before it is returned. | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown response ID for this key, or lifecycle disabled | — |


## Delete a stored response

`DELETE /v1/responses/{id}` · operation `deleteOpenAIResponse`

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required | Gateway response ID returned by POST /v1/responses (resp_gw1.…) |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | response.deleted object with the gateway ID | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown response ID for this key, or lifecycle disabled | — |
| `409` | background_response_pending (T168, quota_background_responses): the background response's budget reservation is still open; cancel it or wait until it ends | — |
| `503` | background_state_unavailable (T168): the tracking state could not be read; nothing was deleted | — |


## Cancel a background response

`POST /v1/responses/{id}/cancel` · operation `cancelOpenAIResponse`

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Response object with the gateway ID. With quota_background_responses (T168), the cancelled object settles a tracked reservation: released when it shows no output and no usage, settled at the usage it reports, otherwise held as unknown. | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown response ID for this key, or lifecycle disabled | — |


## List the input items of a stored response

`GET /v1/responses/{id}/input_items` · operation `listOpenAIResponseInputItems`

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Provider list of input items (item IDs are the provider's) | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown response ID for this key, or lifecycle disabled | — |


## Create a conversation

`POST /v1/conversations` · operation `createConversation`

Requires conversations (with openai_responses) and route:responses. The conversation is created at an OpenAI provider: the first OpenAI target of the alias named in model (a gateway field, removed before the call), or, without model, the only OpenAI provider the key reaches through its Responses aliases (422 model_required when there are several). Items pass the input guardrails of every alias of the key at that provider. The returned id is a signed gateway ID (conv_gw1.…) owned by the key's team, or by the key when it has no team (ADR 0120).

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |

**Request body** (required)

- `application/json`: object
  - `model` (string) — Gateway field: the alias whose provider stores the conversation; required when the key reaches several OpenAI providers
  - `items` (array of object, max items 20) — Initial items, as in Responses input
  - `metadata` (object)
    - any other key: string

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | conversation object with the gateway ID | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `415` | application/json required | — |
| `422` | No OpenAI provider for this key or alias, or model_required | — |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |


## Retrieve a conversation

`GET /v1/conversations/{id}` · operation `getConversation`

Requires conversations and route:responses. The ID is signed and owned by a team (or a teamless key); another team, a tampered ID, an ID from another deployment's secret or a raw provider ID answers 404 without calling the provider.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required | Gateway conversation ID (conv_gw1.…) |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | conversation object with the gateway ID | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown conversation ID for this team, or conversations disabled | — |


## Update a conversation's metadata

`POST /v1/conversations/{id}` · operation `updateConversation`

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required | Gateway conversation ID (conv_gw1.…) |

**Request body** (required)

- `application/json`: object
  - `metadata` (object, required)
    - any other key: string

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | conversation object with the gateway ID | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown conversation ID for this team, or conversations disabled | — |


## Delete a conversation

`DELETE /v1/conversations/{id}` · operation `deleteConversation`

The provider keeps the items; only the conversation is deleted.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required | Gateway conversation ID (conv_gw1.…) |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | conversation.deleted object with the gateway ID | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown conversation ID for this team, or conversations disabled | — |


## List the items of a conversation

`GET /v1/conversations/{id}/items` · operation `listConversationItems`

Only after, limit, order and include (or include[]) are forwarded; anything else answers 400 without calling the provider.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |
| `after` | query | string, pattern `^[A-Za-z0-9_-]{1,128}$` | Item ID to list after |
| `limit` | query | integer, default `20`, min 1, max 100 |  |
| `order` | query | string, one of `"asc"`, `"desc"`, default `"desc"` |  |
| `include` | query | array of string, max items 16 |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Provider list of items (item IDs are the provider's) | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown conversation ID for this team, or conversations disabled | — |


## Add items to a conversation

`POST /v1/conversations/{id}/items` · operation `createConversationItems`

1-20 items; they pass the input guardrails of every alias of the key at the conversation's provider. A key with no such alias left gets 403.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |
| `include` | query | array of string, max items 16 |  |

**Request body** (required)

- `application/json`: object
  - `items` (array of object, required, min items 1, max items 20)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Provider list of the added items | — |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown conversation ID for this team, or conversations disabled | — |


## Retrieve a conversation item

`GET /v1/conversations/{id}/items/{item_id}` · operation `getConversationItem`

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |
| `item_id` | path | string, required, pattern `^[A-Za-z0-9_-]{1,128}$` | Provider item ID |
| `include` | query | array of string, max items 16 |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Provider item | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown conversation or item | — |


## Delete a conversation item

`DELETE /v1/conversations/{id}/items/{item_id}` · operation `deleteConversationItem`

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |
| `item_id` | path | string, required, pattern `^[A-Za-z0-9_-]{1,128}$` | Provider item ID |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The updated conversation object, with the gateway ID | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Unknown conversation or item | — |


## Count input tokens of an Anthropic Messages request

`POST /v1/messages/count_tokens` · operation `countAnthropicMessageTokens`

Requires anthropic_messages and route:messages. Routed to the alias's first Anthropic target with the provider model; free at the provider, so no quota, budget or ledger entry. 422 when the alias has no Anthropic target.

**Authentication:** `bearerAuth`

**Request body** (required)

- `application/json`: object
  - `model` (string, required)
  - `messages` (array of object, required)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Provider count, e.g. {input_tokens: 19} | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed for this key | — |
| `404` | Unknown model or capability disabled | — |
| `422` | No Anthropic target on this alias | — |


## Count input tokens of a Responses request

`POST /v1/responses/input_tokens` · operation `countOpenAIResponseInputTokens`

Requires openai_responses and route:responses. Routed to the alias's first OpenAI-protocol target, or with conversations to the provider holding the gateway conversation ID in conversation (404 for a raw or foreign ID); free, so no quota, budget or ledger entry.

**Authentication:** `bearerAuth`

**Request body** (required)

- `application/json`: object
  - `model` (string, required)
  - `input` (any)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | response.input_tokens object | — |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed for this key | — |
| `404` | Unknown model or capability disabled | — |
| `422` | No OpenAI-protocol target on this alias | — |


## POST /v1/messages

`POST /v1/messages` · operation `createAnthropicMessage`

Anthropic Messages. Requires anthropic_messages flag, route:messages scope and a model with messages capability. When every target is Anthropic it is a native passthrough - the gateway replaces model and sets its own provider Authorization and pinned anthropic-version, preserving native body, response and SSE events. When a target is another provider (openai, gemini, cohere, bedrock), the request is translated through the canonical Chat Completions format (ADR 0172) and the answer, stream and provider errors come back in Messages shape, with X-Gateway-Translation and X-Gateway-Translation-Lossy headers; fields with no equivalent answer 422 unsupported_translation before any call. The gateway key may also come in x-api-key, as the Anthropic SDKs send it, when there is no Authorization header. A stream that breaks after the first byte ends with an error event, never message_stop. Provider-native skills (container.skills, T032.002) need the native_skills flag and an alias whose targets are all native Anthropic; before any call the gateway answers 422 native_skills_disabled, 400 invalid_native_skills (1-8 unique {type anthropic|custom, skill_id, version?}) or 422 native_skills_unsupported, and such a request is sent once to one target, without fallback.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Gateway-Timeout-Ms` | header | string, max length 8, pattern `^[0-9]+$` | One decimal integer from 1 to 86400000 milliseconds. With request_timeout_header enabled it can only lower the total deadline, or every independent stream clock (including an otherwise disabled idle clock). Ignored when the header flag is disabled. Never forwarded upstream. |
| `X-Gateway-Tags` | header | string, max length 2048 | Optional explicit JSON string map for model inference only. With usage_tag_defaults, finite defaults come from the authenticated team and explicit values override matching names; an absent header or an empty JSON object preserves defaults. One header, at most 2 KiB and eight pairs; finite configured enum. Requires usage_tags and authentication/model/team/RPM admission. Never forwarded or added to logs/traces/metric labels/cache identity. Not supported for MCP or models inventory. Tags do not authorize access or establish financial attribution. |
| `X-Gateway-Add-Guardrails` | header | string, max length 600 | request_guardrails (T164.006). Optional comma-separated list of 1-8 distinct guardrail IDs added to this Chat Completions, Messages or Responses request. Each must exist, apply to the alias and list the key's team (or *) in selectable_teams; otherwise 403 guardrail_not_selectable before any guardrail or provider call. The header only adds checks; it never removes a configured one. With the flag off it is refused with 400 request_guardrails_disabled, never ignored. |
| `X-Gateway-End-User` | header | string, min length 1, max length 128 | Optional client-declared end user (1–128 printable characters) recorded under end_user_tracking. Takes precedence over the OpenAI user body field. Untrusted metadata: never authorization, routing, cache identity or a log/metric label. Required when the key's or its team's require block sets end_user (attribution_requirements): a request without it answers 400 missing_attribution before any provider call. |
| `X-Gateway-Session-Id` | header | string, min length 1, max length 128 | Optional client-declared session or agent-run ID (1–128 printable characters) recorded under session_tracking to group requests in logs. Untrusted metadata: never authorization, routing or cache identity. |
| `X-Gateway-Agent-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared agent that made this request (1–128 printable characters), kept with the session's agent graph. Asserted, never authentication; ignored with the flag off; an invalid or repeated value answers 400 invalid_agent_context. |
| `X-Gateway-Turn-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared turn this request belongs to (1–128 printable characters). Asserted; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Parent-Session-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional session that spawned this one (a sub-agent run), 1–128 printable characters. Asserted; ignored when equal to X-Gateway-Session-Id; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Feedback-Key` | header | string, min length 1, max length 200, pattern `^[\x21-\x7E]{1,200}$` | evaluation_results (T186.003). Optional external ID (a ticket or incident number) that feedback results join on with join_key: 1–200 printable ASCII characters without spaces, one value. Stored on the request log row and the request span; never a usage tag, a metric label or an analytics dimension. Ignored with the flag off; an invalid or repeated value answers 400 invalid_feedback_key. |
| `X-Gateway-Prompt-Render` | header | string, max length 512, pattern `^gpr_` | prompt_tracking (T186.013). The render token the published-prompt render answered: the request records that prompt and revision as rendered. Attribution only, never a refusal: a token of another team, a forged one, one past prompt_tracking.render_token_ttl, or a team whose plan lacks prompt_tracking records nothing and the answer carries X-Gateway-Prompt-Tracking (other_team, invalid_signature, malformed, expired, not_entitled, entitlement_unavailable). With X-Gateway-Prompt-Id and X-Gateway-Prompt-Revision they must name the token's prompt and revision (400 invalid_prompt_declaration); two tokens answer 400 invalid_prompt_render. Ignored with the flag off. |
| `X-Gateway-Prompt-Id` | header | string, pattern `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` | prompt_tracking (T186.013). The registry prompt the client built the request from, recorded as declared: a claim, never authorization, and only on the rows of the key's own team. Read while prompt_tracking.declared_headers is true (default); one value; an invalid one answers 400 invalid_prompt_declaration. |
| `X-Gateway-Prompt-Revision` | header | string, pattern `^[1-9][0-9]?$\|^100$` | prompt_tracking (T186.013). The revision (1-100) of X-Gateway-Prompt-Id; optional, recorded as declared. |
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required) — Public model alias
  - `max_tokens` (integer, required, min 0)
  - `messages` (array of object, required, min items 1)
  - `stream` (boolean, default `false`)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Native Anthropic response or SSE stream | `application/json`: object<br/>`text/event-stream`: string |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `429` | Gateway RPM, key or team concurrency cap (concurrency_limit_exceeded, T135) or applicable token/USD quota ceiling reached; the request was not forwarded upstream. | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `default` | Provider status, content type and body passed through after model alias replacement. | `application/json`: object<br/>`application/octet-stream`: string (binary) |


## POST /v1/decisions

`POST /v1/decisions` · operation `decide`

OpenAI Decisions contract with input and 1-400 typed questions; requires decisions capability and openai_decisions flag. decision_translation optionally converts the text-only subset of up to 64 predicate/choice/score questions to configured TypeSafe or Clef targets, preserving typed choice values and answer order. Unsupported translated fields/media return 422 before any upstream call. Native OpenAI passthrough retains its own profile.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Gateway-Tags` | header | string, max length 2048 | Optional explicit JSON string map for model inference only. With usage_tag_defaults, finite defaults come from the authenticated team and explicit values override matching names; an absent header or an empty JSON object preserves defaults. One header, at most 2 KiB and eight pairs; finite configured enum. Requires usage_tags and authentication/model/team/RPM admission. Never forwarded or added to logs/traces/metric labels/cache identity. Not supported for MCP or models inventory. Tags do not authorize access or establish financial attribution. |
| `X-Gateway-End-User` | header | string, min length 1, max length 128 | Optional client-declared end user (1–128 printable characters) recorded under end_user_tracking. Takes precedence over the OpenAI user body field. Untrusted metadata: never authorization, routing, cache identity or a log/metric label. Required when the key's or its team's require block sets end_user (attribution_requirements): a request without it answers 400 missing_attribution before any provider call. |
| `X-Gateway-Session-Id` | header | string, min length 1, max length 128 | Optional client-declared session or agent-run ID (1–128 printable characters) recorded under session_tracking to group requests in logs. Untrusted metadata: never authorization, routing or cache identity. |
| `X-Gateway-Agent-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared agent that made this request (1–128 printable characters), kept with the session's agent graph. Asserted, never authentication; ignored with the flag off; an invalid or repeated value answers 400 invalid_agent_context. |
| `X-Gateway-Turn-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared turn this request belongs to (1–128 printable characters). Asserted; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Parent-Session-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional session that spawned this one (a sub-agent run), 1–128 printable characters. Asserted; ignored when equal to X-Gateway-Session-Id; same rules as X-Gateway-Agent-Id. |
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required)
  - `input` (string or array of object, required)
    - One of (1): string
    - One of (2): array of object
  - `questions` (array of object, required, min items 1, max items 400)
    - `type` (string, required, one of `"predicate"`, `"choice"`, `"score"`)
    - `name` (string)
    - `instructions` (string, required)
    - `choices` (array of object, min items 2)
    - `levels` (array of object, min items 2)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Provider status, content type and body passed through after model alias replacement. | `application/json`: object<br/>`application/octet-stream`: string (binary) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `422` | Model does not support this operation | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `429` | Gateway RPM, key or team concurrency cap (concurrency_limit_exceeded, T135) or applicable token/USD quota ceiling reached; the request was not forwarded upstream. | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `default` | Provider status, content type and body passed through after model alias replacement. | `application/json`: object<br/>`application/octet-stream`: string (binary) |


## POST /v1/systemone

`POST /v1/systemone` · operation `evaluateSystemOne`

TypeSafe System One compatible route for structured state and 1-64 named noul, choice or score questions. Requires systemone_decisions, route:systemone and a model alias with systemone capability. TypeSafe Jev uses /systemone; Cloudflare Clef uses a model-specific Workers AI path and its REST envelope is unwrapped. Streaming, audio and video are not accepted. Image assets (JSON base64 PNG/JPEG, up to 16, no multipart parts) and box questions require the TypeSafe-Danger-Zone-Images header and a direct TypeSafe target (ADR 0125); a Cloudflare, OpenRouter (it ignored images, ADR 0126) or translated target gets 422 before any call. With decision_translation enabled, supported text/structured-data questions can target OpenAI Decisions and return the System One shape; unsupported conversions return 422 before any upstream call.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Gateway-Tags` | header | string, max length 2048 | Optional explicit JSON string map for model inference only. With usage_tag_defaults, finite defaults come from the authenticated team and explicit values override matching names; an absent header or an empty JSON object preserves defaults. One header, at most 2 KiB and eight pairs; finite configured enum. Requires usage_tags and authentication/model/team/RPM admission. Never forwarded or added to logs/traces/metric labels/cache identity. Not supported for MCP or models inventory. Tags do not authorize access or establish financial attribution. |
| `X-Gateway-End-User` | header | string, min length 1, max length 128 | Optional client-declared end user (1–128 printable characters) recorded under end_user_tracking. Takes precedence over the OpenAI user body field. Untrusted metadata: never authorization, routing, cache identity or a log/metric label. Required when the key's or its team's require block sets end_user (attribution_requirements): a request without it answers 400 missing_attribution before any provider call. |
| `X-Gateway-Session-Id` | header | string, min length 1, max length 128 | Optional client-declared session or agent-run ID (1–128 printable characters) recorded under session_tracking to group requests in logs. Untrusted metadata: never authorization, routing or cache identity. |
| `X-Gateway-Agent-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared agent that made this request (1–128 printable characters), kept with the session's agent graph. Asserted, never authentication; ignored with the flag off; an invalid or repeated value answers 400 invalid_agent_context. |
| `X-Gateway-Turn-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared turn this request belongs to (1–128 printable characters). Asserted; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Parent-Session-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional session that spawned this one (a sub-agent run), 1–128 printable characters. Asserted; ignored when equal to X-Gateway-Session-Id; same rules as X-Gateway-Agent-Id. |
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |
| `TypeSafe-Danger-Zone-Images` | header | string, one of `"true"` | ADR 0125. Opt-in for image assets and box questions; forwarded only to TypeSafe targets (protocol systemone). Without it, assets give 422 and box questions 400. |
| `TypeSafe-Danger-Zone-Long-Context` | header | string, one of `"true"` | ADR 0125. Opt-in for TypeSafe long context; forwarded only to TypeSafe targets. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required)
  - `state` (string or object or array of any, required)
    - One of (1): string
    - One of (2): object
    - One of (3): array of any
  - `assets` (object) — Placeholder -&gt; image; the placeholder may appear in state, instructions or criteria. Requires TypeSafe-Danger-Zone-Images: true.
    - any other key: object
      - `type` (`"image"`, required)
      - `format` (string, required, one of `"png"`, `"jpg"`, `"jpeg"`)
      - `data_base64` (string, required)
  - `questions` (object, required)
    - any other key: object or object or object or object
      - One of (1): object
      - One of (2): object
      - One of (3): object
      - One of (4): object — Locates a region of an image asset; answer {type: box, box: {top, bottom, left, right}, confidence}. Requires TypeSafe-Danger-Zone-Images: true.

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Native System One result keyed by question name, with reported usage when supplied by the provider. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `413` | Request exceeds the configured body limit | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `415` | Only application/json is accepted | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `422` | Model does not support this operation | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `429` | Gateway RPM, key or team concurrency cap (concurrency_limit_exceeded, T135) or applicable token/USD quota ceiling reached; the request was not forwarded upstream. | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `model` (string, required)
  - `answers` (object, required)
  - `usage` (object)
    - `input_tokens` (integer)
    - `output_tokens` (integer)


## POST /v1beta/decisions

`POST /v1beta/decisions` · operation `createGeminiDecision`

Gemini Decisions API (T074.001), API version v1beta, as Google documents it (client.decisions.create). Requires the gemini_decisions flag, key scope route:gemini_decisions and an alias with the gemini_decisions capability alone, targeting the Gemini API (Vertex AI is refused by configuration). The gateway key goes in Authorization: Bearer or x-goog-api-key, never in ?key=. The request is checked against the documented limits before any call (1-1000 questions keyed [A-Za-z0-9_-]{1,64}; noul, choice with 2-255 options, score with 2-255 levels; text instructions; input a string or text/image/audio/video/document blocks with data or an https uri) and forwarded with only the model replaced; a Files API uri is refused with 422 file_uri_unsupported. The answer is relayed as received and valued from usage.total_input_tokens (no output, cache, thought or tool tokens). Budgets (quota_native_protocols) admit text input only.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Gateway-Tags` | header | string, max length 2048 | Optional explicit JSON string map for model inference only. With usage_tag_defaults, finite defaults come from the authenticated team and explicit values override matching names; an absent header or an empty JSON object preserves defaults. One header, at most 2 KiB and eight pairs; finite configured enum. Requires usage_tags and authentication/model/team/RPM admission. Never forwarded or added to logs/traces/metric labels/cache identity. Not supported for MCP or models inventory. Tags do not authorize access or establish financial attribution. |
| `X-Gateway-End-User` | header | string, min length 1, max length 128 | Optional client-declared end user (1–128 printable characters) recorded under end_user_tracking. Takes precedence over the OpenAI user body field. Untrusted metadata: never authorization, routing, cache identity or a log/metric label. Required when the key's or its team's require block sets end_user (attribution_requirements): a request without it answers 400 missing_attribution before any provider call. |
| `X-Gateway-Session-Id` | header | string, min length 1, max length 128 | Optional client-declared session or agent-run ID (1–128 printable characters) recorded under session_tracking to group requests in logs. Untrusted metadata: never authorization, routing or cache identity. |
| `X-Gateway-Agent-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared agent that made this request (1–128 printable characters), kept with the session's agent graph. Asserted, never authentication; ignored with the flag off; an invalid or repeated value answers 400 invalid_agent_context. |
| `X-Gateway-Turn-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared turn this request belongs to (1–128 printable characters). Asserted; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Parent-Session-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional session that spawned this one (a sub-agent run), 1–128 printable characters. Asserted; ignored when equal to X-Gateway-Session-Id; same rules as X-Gateway-Agent-Id. |
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required)
  - `input` (string or array of object, required)
    - One of (1): string
    - One of (2): array of object
      - `type` (string, required, one of `"text"`, `"image"`, `"audio"`, `"video"`, `"document"`)
      - `text` (string)
      - `data` (string) — base64
      - `uri` (string) — https URL fetched by the provider; Files API URIs are refused
      - `mime_type` (string)
      - `resolution` (string, one of `"low"`, `"medium"`, `"high"`, `"ultra_high"`)
  - `questions` (object, required)
    - any other key: object
      - `type` (string, required, one of `"noul"`, `"choice"`, `"score"`)
      - `instructions` (any, required) — A string, a text block or a list of text blocks
      - `criteria` (any) — noul: optional {true_description, false_description}; choice: option ID -&gt; description, 2-255 options; score: 2-255 ordered level strings

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The provider's CreateDecisionResponse, relayed as received. | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `401` | Missing or invalid bearer key | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `413` | Request exceeds the configured body limit | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `415` | Only application/json is accepted | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `422` | Model does not support this operation | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `429` | Gateway RPM, key or team concurrency cap (concurrency_limit_exceeded, T135) or applicable token/USD quota ceiling reached; the request was not forwarded upstream. | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `answers` (object) — Keyed by question ID: {type, noul \| choice + probabilities \| score + probabilities + legend, confidence 0-1}
  - `usage` (object)
    - `total_input_tokens` (integer)
    - `total_output_tokens` (integer)
    - `total_tokens` (integer)
  - `prompt_feedback` (object)


## POST /v1/moderations

`POST /v1/moderations` · operation `moderate`

OpenAI Moderation API passthrough (T097). Requires the moderations flag, route:moderations and an alias with the moderations capability. The gateway replaces model with the target's model and forwards the rest of the body unchanged; the provider's status and body come back as received, including its own 4xx errors (for example an unknown upstream model, missing input or an image URL it could not download). model is required here: it names a gateway alias, so the provider default (omni-moderation-latest) does not apply. Responses carry no usage, so the ledger records the call with unknown tokens and cost (unsupported_operation). With exact_cache, only inputs whose images are data URLs can be cached; a remote image URL always reaches the provider.

**Authentication:** `bearerAuth`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-Gateway-Tags` | header | string, max length 2048 | Optional explicit JSON string map for model inference only. With usage_tag_defaults, finite defaults come from the authenticated team and explicit values override matching names; an absent header or an empty JSON object preserves defaults. One header, at most 2 KiB and eight pairs; finite configured enum. Requires usage_tags and authentication/model/team/RPM admission. Never forwarded or added to logs/traces/metric labels/cache identity. Not supported for MCP or models inventory. Tags do not authorize access or establish financial attribution. |
| `X-Gateway-End-User` | header | string, min length 1, max length 128 | Optional client-declared end user (1–128 printable characters) recorded under end_user_tracking. Takes precedence over the OpenAI user body field. Untrusted metadata: never authorization, routing, cache identity or a log/metric label. Required when the key's or its team's require block sets end_user (attribution_requirements): a request without it answers 400 missing_attribution before any provider call. |
| `X-Gateway-Session-Id` | header | string, min length 1, max length 128 | Optional client-declared session or agent-run ID (1–128 printable characters) recorded under session_tracking to group requests in logs. Untrusted metadata: never authorization, routing or cache identity. |
| `X-Gateway-Agent-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared agent that made this request (1–128 printable characters), kept with the session's agent graph. Asserted, never authentication; ignored with the flag off; an invalid or repeated value answers 400 invalid_agent_context. |
| `X-Gateway-Turn-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional client-declared turn this request belongs to (1–128 printable characters). Asserted; same rules as X-Gateway-Agent-Id. |
| `X-Gateway-Parent-Session-Id` | header | string, min length 1, max length 128 | agent_sessions (T033.002). Optional session that spawned this one (a sub-agent run), 1–128 printable characters. Asserted; ignored when equal to X-Gateway-Session-Id; same rules as X-Gateway-Agent-Id. |
| `X-Request-Id` | header | string, max length 128 | Correlation ID echoed in the response and forwarded upstream when valid. |
| `traceparent` | header | string | W3C trace context. Invalid values create a new trace. |

**Request body** (required)

- `application/json`: object
  - `model` (string, required) — Gateway alias with the moderations capability
  - `input` (string or array of string or array of object or object, required) — A string, an array of strings, or an array of text and image_url parts (omni moderation models). image_url.url is an https URL the provider downloads or a base64 data URL.
    - One of (1): string
    - One of (2): array of string
    - One of (3): array of object or object
      - One of (1): object
      - One of (2): object

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | The provider's moderation result, passed through intact. | `application/json`: object |
| `400` | Gateway refusal (invalid_request, invalid_model when model is missing) or the provider's own 400 as received | `application/json`: object |
| `401` | Missing or invalid gateway key (unauthorized), or the provider refused the connection's credential (its body as received) | `application/json`: object |
| `403` | Gateway refusal (scope_forbidden without route:moderations, model_forbidden outside the key or team allowlist, entitlement_forbidden from a team plan) or the provider's own 403 as received | `application/json`: object |
| `404` | feature_disabled when the moderations flag is off, model_not_found for an unknown or disabled alias | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `413` | Request exceeds the configured body limit | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `415` | Only application/json is accepted | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `422` | Model does not support this operation | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `429` | Gateway rate or concurrency refusal before any provider call (rate_limit_exceeded, concurrency_limit_exceeded, with Retry-After), or the provider's own 429 as received | `application/json`: object |
| `502` | Provider unavailable | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `503` | Local concurrency limit reached | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `default` | Provider status, content type and body passed through after model alias replacement. | `application/json`: object<br/>`application/octet-stream`: string (binary) |

Response `200` fields:

- `application/json`: object
  - `id` (string, required)
  - `model` (string, required) — The provider's model, not the gateway alias
  - `results` (array of object, required) — One result per input string, or one result for a multimodal input
    - `flagged` (boolean)
    - `categories` (object)
      - any other key: boolean or null
    - `category_scores` (object)
      - any other key: number
    - `category_applied_input_types` (object)
      - any other key: array of string

