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

# Anthropic API 兼容（Beta）

## 说明

为了满足开发者对 Anthropic API 生态的使用需求，我们的 API 现支持通过  Anthropic API 调用所有的模型。支持 200+ LLMs，包括 7个免费模型。

## 快速开始

### 安装 Anthropic SDK

<CodeGroup>
  ```shellscript Python theme={null}
  pip install -U anthropic
  ```

  ```shellscript Node.js theme={null}
  npm install @anthropic-ai/sdk
  ```
</CodeGroup>

### 调用方法

**端点 ：**`https://aihubmix.com/v1/messages`

<CodeGroup>
  ```shellscript Curl theme={null}
  curl https://aihubmix.com/v1/messages \
    -H "Content-Type: application/json" \
    -H "x-api-key: <AIHUBMIX_API_KEY>" \
    -H "anthropic-version: 2023-06-01" \
    -d '{
      "model": "minimax-m2.1",
      "max_tokens": 16000,
      "thinking": {
        "type": "enabled",
        "budget_tokens": 10000
      },
      "messages": [
        {
          "role": "user",
          "content": "Are there an infinite number of prime numbers such that n mod 4 == 3?"
        }
      ]
    }'
  ```

  ```python Python theme={null}
  from anthropic import Anthropic

  client = Anthropic(
    api_key="<AIHUBMIX_API_KEY>",  
    base_url="https://aihubmix.com"
  )

  response = client.messages.create(
    model="glm-4.7",
    max_tokens=16000,
      thinking={
          "type": "enabled",
          "budget_tokens": 10000
      },
    messages=[
      {
        "role": "user",
        "content": "Are there an infinite number of prime numbers such that n mod 4 == 3?"
      }
    ]
  )

  # The response will contain summarized thinking blocks and text blocks
  for block in response.content:
      if block.type == "thinking":
          print(f"\nThinking summary: {block.thinking}")
      elif block.type == "text":
          print(f"\nResponse: {block.text}")
  ```
</CodeGroup>

## 兼容性说明

### 支持的参数

在使用 Anthropic API 接入时，我们支持以下输入参数：

| 参数            | 类型                                | 是否必需 | 说明                                         |
| ------------- | --------------------------------- | ---- | ------------------------------------------ |
| `model`       | string                            | 是    | 支持模型请查询[模型列表](https://aihubmix.com/models) |
| `messages`    | array of MessageParam             | 是    | 输入信息                                       |
| `max_toknes`  | number                            | 否    | 最大生成 token 数                               |
| `stream`      | boolean                           | 否    | 流式响应                                       |
| `system`      | string or array of TextBlockParam | 是    | 系统提示词                                      |
| `temperature` | number                            | 否    | 取值范围 (0.0, 1.0]，控制输出随机性，建议取值 1             |
| `top_p`       | number                            | 否    | 核采样参数                                      |
| `thinking`    | ThinkingConfigParam               | 否    | 推理内容                                       |

### Messages 字段支持

| 字段类型                 | 说明     |
| -------------------- | ------ |
| `type="text"`        | 文本消息   |
| `type="tool_use"`    | 工具调用   |
| `type="tool_result"` | 工具调用结果 |
| `type="thinking"`    | 推理的内容  |

## 使用示例

### 在 Claude Code 中使用 GPT-5.2

虽然您可以通过 AIHubMix 使用任何模型，但为了获得最佳体验，我们建议您使用功能强大的模型，例如 gpt-5.2、glm-4.7  等。

#### 1. 安装配置 Claude Code

Claude Code 安装请参考：[https://docs.aihubmix.com/cn/api/Claude-Code](https://docs.aihubmix.com/cn/api/Claude-Code)

#### 2. 将 Claude Code 连接到AIHubMix

**Claude 配置文件：**`.claude/settings.json`

```bash theme={null}
{
  "env": {
    "ANTHROPIC_API_KEY": "AIHUBMIX_API_KEY",
    "ANTHROPIC_BASE_URL": "https://aihubmix.com",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5.2",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "gpt-5.2",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.2",
    "ANTHROPIC_MODEL": "gpt-5.2"
  },
  "includeCoAuthoredBy": false
}
```

请替换 `AIHUBMIX_API_KEY` 为实际的 AIHUBMIX API 密钥。

<Tip>
  Claude Code 原生安装程序无法读取标准 `.env` 文件，因此请勿将这些内容放置在 `.env` 文件中。
</Tip>

#### 3. 开始对话

导航到您的项目目录并启动 Claude Code：

```bash theme={null}
$ cd /path/your-project
> claude
```

连接成功后，您发送的任何提示都将通过 AIHubMix 路由。

#### 4. 验证

您可以通过在 Claude Code 中输入 `/status`  命令来确认您的连接。

```bash theme={null}
> /status

 API key: ANTHROPIC_API_KEY
 Anthropic base URL: https://aihubmix.com

 Model: gpt-5.2 
```

***

更新时间：2026-06-01
