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

# claude文本聊天

# 聊天 (Chat) - 原生 Claude 格式

Anthropic Claude Messages API 格式的请求。需要在请求头中包含 `anthropic-version`。

* **接口地址**: `POST /v1/messages`
* **基础 URL (示例)**: `https://www.ominiapi.com`

## 认证与请求头 (Headers)

* `Authorization` (**必选**): 使用 Bearer Token 认证。格式: `Bearer sk-xxxxxx`
* `anthropic-version` (**必选**): Anthropic API 版本，例如 `2023-06-01`
* `x-api-key` (*可选*): Anthropic API Key (也可使用 Bearer Token 替代)
* `Content-Type`: `application/json`

## 请求参数 (Request Body)

| 参数名              | 类型             | 必选    | 说明                                 |
| :--------------- | :------------- | :---- | :--------------------------------- |
| `model`          | String         | **是** | 模型名称，如 `claude-3-opus-20240229` 等  |
| `messages`       |                | **是** | 包含对话历史的消息数组，需指定 `role` 和 `content` |
| `max_tokens`     | Integer        | **是** | 生成的最大 Token 数量，范围必须 `>= 1`         |
| `system`         | String / Array | 否     | 系统提示词，用于指导模型行为                     |
| `temperature`    | Number         | 否     | 采样温度，取值范围 `0 <= value <= 1`        |
| `top_p`          | Number         | 否     | Nucleus 采样参数                       |
| `top_k`          | Integer        | 否     | Top-K 采样参数                         |
| `stream`         | Boolean        | 否     | 是否启用流式响应返回数据                       |
| `stop_sequences` |                | 否     | 触发停止生成的字符或字符串序列                    |
| `tools`          |                | 否     | 模型可使用的外部工具（函数）定义列表                 |
| `tool_choice`    | Object         | 否     | 控制模型对工具的选择模式                       |
| `thinking`       | Object         | 否     | 思考过程的相关配置（针对特定模型）                  |
| `metadata`       | Object         | 否     | 附加元数据信息                            |

## 示例代码 (cURL)

```bash theme={null}
curl -X POST "[https://www.ominiapi.com/v1/messages](https://www.ominiapi.com/v1/messages)" \
  -H "anthropic-version: 2023-06-01" \
  -H "Authorization: Bearer <您的_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-opus-20240229",
    "messages": [
      {
        "role": "user",
        "content": "你好！"
      }
    ],
    "max_tokens": 1024
  }'
```

## 响应体结构 (Response - 200 OK)

成功请求返回 JSON 格式结果。

```bash theme={null}
{
  "id": "string",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "string",
      "text": "string"
    }
  ],
  "model": "string",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}
```
