> ## 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 Message

> 使用 Anthropic Messages 格式生成回复

请求头必须包含 `x-api-key: API_KEY`、`anthropic-version: 2023-06-01` 和 `Content-Type: application/json`。

| 字段                              | 类型           | 必填 | 说明                              |
| ------------------------------- | ------------ | -- | ------------------------------- |
| `model`                         | string       | 是  | 模型 ID。                          |
| `messages`                      | array        | 是  | user 与 assistant 消息；内容为字符串或内容块。 |
| `max_tokens`                    | integer      | 是  | 最大生成 token 数。                   |
| `system`                        | string/array | 否  | 系统指令。                           |
| `stream`                        | boolean      | 否  | 返回 SSE 事件。                      |
| `temperature`, `top_p`, `top_k` | number       | 否  | 采样参数。                           |
| `stop_sequences`                | array        | 否  | 自定义停止序列。                        |
| `tools`, `tool_choice`          | mixed        | 否  | 工具定义和选择策略。                      |
| `metadata`                      | object       | 否  | 请求元数据。                          |

<CodeGroup>
  ```bash cURL 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": "你好"}]
    }'
  ```

  ```python Python theme={null}
  client.messages.create(model="your-model", max_tokens=1024, messages=[{"role":"user","content":"你好"}])
  ```

  ```javascript Node.js theme={null}
  await client.messages.create({ model: "your-model", max_tokens: 1024, messages: [{ role: "user", content: "Hello" }] });
  ```
</CodeGroup>

响应包含 `id`、`type`、`role`、`content[]`、`model`、`stop_reason`、`stop_sequence` 与 `usage`。流式模式返回 message、content block 与 ping 等事件。
