> ## Documentation Index
> Fetch the complete documentation index at: https://bianxieai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic 兼容协议

> 使用原生 Messages API 调用 Claude 模型

Anthropic Messages 协议使用独立的消息结构和鉴权头。Base URL 为 `https://api.bianxie.ai`，模型 ID 以[实时模型页](https://api.bianxie.ai/pricing)为准。

## 请求

```bash theme={null}
curl https://api.bianxie.ai/v1/messages \
  -H "x-api-key: API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model",
    "max_tokens": 1024,
    "messages": [{
      "role": "user",
      "content": "用一段话解释量子纠缠。"
    }]
  }'
```

`max_tokens` 为必填字段。系统指令通过顶层 `system` 字段传递，不要使用 OpenAI 的 system message 格式。加入 `"stream": true` 可启用 SSE 流式输出。

## 返回结构

```json theme={null}
{
  "id": "msg_example",
  "type": "message",
  "role": "assistant",
  "model": "your-model",
  "content": [{"type": "text", "text": "量子纠缠是..."}],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {"input_tokens": 18, "output_tokens": 42}
}
```

读取 `content[]` 中 `type` 为 `text` 的内容。工具调用会以其他内容块类型返回；流式模式则依次发送 message 与 content block 事件。
