# 文本对话（Anthropic 格式）

Anthropic 兼容的消息接口。网关内部会将请求翻译成上游格式（OpenAI 或原生 Anthropic），
响应也会翻译回标准 Anthropic 格式返回给调用方。

支持流式响应：当 `stream: true` 时，返回标准 Anthropic SSE 事件流，包含
`message_start`、`content_block_start`、`content_block_delta`、`message_stop` 等事件。

**必须携带请求头 `anthropic-version: 2023-06-01`。**

## 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`:
