# Messages (Anthropic schema)

> POST /v1/messages -- Anthropic-compatible body, both key headers, anthropic-version handling, and streaming events.

`POST https://<platform-address>/v1/messages`. The `/v1/messages` path is
always parsed with the Anthropic schema -- the path selects the schema, no
header changes it (see [API Overview](/en/platform/docs/guides/inference-api/api-overview/index.md)).

## Differences from stock Anthropic

| Aspect | Stock Anthropic | This gateway |
|---|---|---|
| Auth header | `x-api-key: ...` | `x-api-key: onprem-gw-your-key` or `Authorization: Bearer onprem-gw-your-key`; both are accepted |
| `anthropic-version` | Required | Optional. If present and not `2023-06-01`, the gateway logs a server-side warning and processes the request anyway -- it never rejects on version |
| Model ids | `claude-*` | The platform's deployed model ids (see the APIs page) |

## Request headers

```
Content-Type: application/json
Authorization: Bearer onprem-gw-your-key
anthropic-version: 2023-06-01
```

## Request body

```json
{
  "model": "my-model-id",
  "max_tokens": 1024,
  "system": "You are a helpful assistant.",
  "messages": [
    { "role": "user", "content": "Hello!" }
  ],
  "stream": false,
  "temperature": 0.7
}
```

| Parameter | Type | Required | Description |
|---|---|---|---|
| `model` | string | yes | Deployed model id (or a configured alias) |
| `messages` | array | yes | User/assistant turns |
| `max_tokens` | integer | yes | Required by the Anthropic schema (unlike OpenAI) |
| `system` | string | no | Top-level field, NOT a `role: "system"` message |
| `stream` | boolean | no (false) | Enable SSE streaming |
| `temperature`, `top_p`, `top_k`, `stop_sequences` | -- | no | Sampling controls |
| `tools`, `tool_choice`, `thinking`, `metadata` | -- | no | Accepted by the gateway's request schema; support depends on the serving engine |

## Non-streaming response

```json
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    { "type": "text", "text": "Hello! How can I help?" }
  ],
  "model": "my-model-id",
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 10, "output_tokens": 25 }
}
```

`content` is an array of blocks, not a single string. When the gateway
translates from an OpenAI-speaking engine, `stop_reason` is mapped from the
engine's `finish_reason`: `stop` -> `end_turn`, `length` -> `max_tokens`,
`tool_calls` -> `tool_use`.

## Streaming (SSE)

With `"stream": true`, events follow the Anthropic event vocabulary, each
with an SSE `event:` name and JSON `data:`:

1. `message_start` -- message metadata
2. `content_block_start` -- a content block begins
3. `content_block_delta` -- incremental text: `{"delta": {"type": "text_delta", "text": "chunk"}}`
4. `content_block_stop` -- block complete
5. `message_delta` -- `stop_reason` plus output token usage
6. `message_stop` -- stream complete

```
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":25}}

event: message_stop
data: {"type":"message_stop"}
```

Mid-stream failures are emitted as an `event: error` with the gateway's
error envelope as data. Errors before the first token (including overload
rejections) are plain HTTP error responses -- see [API Overview](/en/platform/docs/guides/inference-api/api-overview/index.md) for the
envelope and the 503 `Overloaded` codes.
