# Chat completion (Anthropic format)

Anthropic-compatible messages endpoint. The gateway internally translates requests to the upstream format (OpenAI or native Anthropic),
and translates responses back to standard Anthropic format before returning to the caller.

Supports streaming: when `stream: true`, returns a standard Anthropic SSE event stream containing
`message_start`, `content_block_start`, `content_block_delta`, `message_stop`, and other events.

**The `anthropic-version: 2023-06-01` header is required.**

## POST /v1/messages

> Chat completion (Anthropic format)

Anthropic-compatible messages endpoint. The gateway internally translates requests to the upstream format (OpenAI or native Anthropic),
and translates responses back to standard Anthropic format before returning to the caller.

Supports streaming: when `stream: true`, returns a standard Anthropic SSE event stream containing
`message_start`, `content_block_start`, `content_block_delta`, `message_stop`, and other events.

**The `anthropic-version: 2023-06-01` header is required.**

### Authentication

`Authorization: Bearer tr-xxx`

### Request Body

Content-Type: `application/json`

- **model** `string` **(required)**  
  Model ID. Available models can be retrieved via `GET /v1/models`
- **max_tokens** `integer` **(required)**  
  Maximum number of output tokens (required)
- **messages** `object[]` **(required)**  
  Message list. Roles must alternate between user and assistant
- **messages[].role** ``user` | `assistant`` **(required)**  
  
- **messages[].content** `string | object[]` **(required)**  
  Message content, either a string or an array of content blocks
- **system** `string`  
  System prompt
- **stream** `boolean` (default: `false`)  
  Whether to enable streaming response
- **temperature** `number`  
  Sampling temperature, range [0, 1]
- **stop_sequences** `string[]`  
  List of stop sequences

### Response

- **id** `string`  
  Unique message ID in `msg_xxx` format
- **type** ``message``  
  Object type, fixed value `message`
- **role** ``assistant``  
  Response role, fixed value `assistant`
- **content** `object[]`  
  List of content blocks
- **content[].type** ``text`` **(required)**  
  
- **content[].text** `string` **(required)**  
  Text content
- **model** `string`  
  Actual model ID used
- **stop_reason** ``end_turn` | `max_tokens` | `stop_sequence` | `null``  
  Stop reason
- **usage** `object`  
  
- **usage.input_tokens** `integer`  
  Number of input tokens
- **usage.output_tokens** `integer`  
  Number of output tokens

### Error Codes

- `400`: 
- `401`: 
- `402`: 
- `429`: 
- `502`:
