# API Overview

> The gateway surface: /v1 endpoints with one path per schema, passthrough APIs, auth, and the error envelope.

Every deployed model is served through the API gateway. You call the gateway, not the engines. The examples in these API pages use the placeholder base URL `https://<platform-address>` and a placeholder key. The API gateway answers over HTTPS only, by default on port 443, with a certificate from the control plane's root CA (see [Trusting the control plane in your browser](/en/platform/docs/v5.10/guides/certificates-and-network/browser-certificate-trust/index.md)). Your platform's real endpoint, your API gateway keys, and per-model curl examples are shown on the **APIs** page (`/apis`) in this app. For interactive use, the **Playground** page (`/playground`) sends real requests through this same gateway.

## Endpoints

| Method | Path | What it does |
|---|---|---|
| POST | `/v1/chat/completions` | Chat completions, OpenAI schema |
| POST | `/v1/messages` | Chat messages, Anthropic schema |
| GET | `/v1/models` | List models callable through the OpenAI-schema route |
| ANY | `/<prefix>/...` | Passthrough APIs of non-LLM services (OCR etc.), routed by path prefix, see Passthrough APIs |

GET requests to other paths under `/v1/` return 404. POST requests to other `/v1/` paths are forwarded to the engine unchanged -- the `model` name in the body selects the route, so an engine operation the table does not name (for example `/v1/embeddings`) is reachable when the engine serves it.

## Which replica answers

A model deployed with several replicas answers through all of them. For chat requests (`/v1/chat/completions`, `/v1/completions`, `/v1/messages`) the API gateway prefers the replica that recently served the same beginning of a prompt -- a shared system prompt, the earlier turns of a conversation, the steps of an agent -- because that replica can reuse the work it already did, and it avoids replicas with a long queue. Other requests go to any replica of the model.

You do not choose the replica and do not need to: send the same system prompt and conversation history the same way each time, and repeated prompts get faster. This only helps models whose deploy profile has prefix caching on. If the API gateway cannot make this choice for a while, it spreads requests across the replicas instead: models keep answering, repeated prompts are slower, and the `ApiGatewayReplicaSelectionFallback` alert names an error report with the cause. How the choice works, and how to write prompts that benefit: [How the Gateway Chooses a Replica](/en/platform/docs/v5.10/concepts/replica-routing/index.md).

## One path, one schema

`/v1/chat/completions` is always parsed as an OpenAI chat completion. `/v1/messages` is always parsed as an Anthropic Messages request. The path selects the schema. No header changes it.

## Authentication

All endpoints (except health) require an API gateway key. A key starts with `onprem-gw-`. Send it in one of two headers:

```
Authorization: Bearer onprem-gw-your-key
```

```
x-api-key: onprem-gw-your-key
```

OpenAI clients send the first header and Anthropic clients send the second. Both work on every path. When a request has both, the gateway reads `Authorization`.

A missing, unknown, or revoked key returns HTTP 401. An unreachable key database returns 503. Keys are created and shown on the APIs page (`/apis`).

The `anthropic-version` header is optional. If it is present and not `2023-06-01`, the gateway logs a server-side warning and processes the request anyway. It never rejects on the version.

## Error envelope

Errors from the gateway itself use one JSON envelope. OpenAI-schema paths:

```json
{"error": {"message": "...", "type": "...", "code": "..."}}
```

Anthropic-schema paths (`/v1/messages`) use the Anthropic error shape instead. The `code` field names the refusal:

| `code` | When |
|---|---|
| `no_such_route` | The API gateway has no route for the request: no deployed model has that name, the path is not one of the gateway's paths, or a debug path names a port the model does not answer on (HTTP 404). The answer comes from the API gateway, not from a model. |
| `model_not_available` | The model is deployed, but no running replica of it can take the request now (HTTP 503; retry) |
| `invalid_request_error` | The body is not valid for the route |
| `request_too_large` | The request body is above the limit (HTTP 413) |
| `ttft_deadline_exceeded` | A streamed request produced no first token within the deadline (HTTP 503, `Retry-After: 2`) |
| `concurrency_budget_exceeded`, `kv_cache_utilization_exceeded` | Defined in the gateway's error vocabulary; not enforced today |
| `upstream_failure` | The engine returned an error, or was unreachable |
| `missing_api_key`, `invalid_api_key`, `revoked_api_key` | The key is missing, unknown, or revoked (HTTP 401) |
| `auth_unavailable` | The key database could not be reached (HTTP 503) |

Overload refusals are **503**, not 429. They carry a `Retry-After` header -- back off instead of hot-retrying.

Passthrough API responses are the exception: the backend service's status code and body are returned verbatim (see Passthrough APIs).

For the full refusal behavior and client guidance, see [How the Gateway Refuses Work](/en/platform/docs/v5.10/concepts/concurrency-and-overload/index.md).
