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

# Anthropic 兼容接入

> 使用 Anthropic SDK 或 HTTP Messages 接口调用 APIONE。

APIONE 支持 Anthropic 兼容协议。Anthropic SDK 的基础地址不带 `/v1`，SDK 会自行追加 `/v1/messages`。

## HTTP 示例

```bash theme={null}
curl --fail-with-body --max-time 120 https://api.apione.ai/v1/messages \
  -H "x-api-key: $APIONE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  --data "{\"model\":\"$APIONE_MODEL\",\"max_tokens\":512,\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}]}"
```

先按[快速开始](https://apione.ai/docs/quickstart.md)设置 `APIONE_API_KEY` 和 `APIONE_MODEL`，并确认模型支持 Anthropic Messages。

## Python 示例

```bash theme={null}
python -m pip install anthropic
```

```python theme={null}
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.apione.ai",
    api_key=os.environ["APIONE_API_KEY"],
)
message = client.messages.create(
    model=os.environ["APIONE_MODEL"],
    max_tokens=512,
    messages=[{"role": "user", "content": "解释接口兼容的含义。"}],
)
for block in message.content:
    if block.type == "text":
        print(block.text)
```

## 与 OpenAI 协议的区别

* 系统提示放在顶层 `system`，而不是 messages 中的 system 消息。
* `max_tokens` 是必填字段。
* 正文来自 `content[]` 文本块，不是 `choices`。
* 流式输出使用具名事件，不可套用 OpenAI 的分片解析逻辑。

协议兼容不代表所有扩展字段都能转换。遇到不支持的参数，请先减到最小请求。[公开协议说明](https://apione.ai/zh/api-docs/docs/anthropic-compat)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.