> ## 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+ LLM**，其中包含 **7 個免費模型**。

## 快速開始

### 安裝 Anthropic SDK

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

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

### API 用法

**端點：** `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 contains 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_tokens`  | number                            | 否  | 生成的最大 token 數                               |
| `stream`      | boolean                           | 否  | 啟用串流回應                                      |
| `system`      | string or array of TextBlockParam | 是  | 系統提示                                        |
| `temperature` | number                            | 否  | 範圍：(0.0, 1.0]。控制輸出隨機性；建議值為 1                |
| `top_p`       | number                            | 否  | Nucleus sampling 參數                         |
| `thinking`    | ThinkingConfigParam               | 否  | 推理設定                                        |

### 支援的訊息類型

| 類型                   | 說明     |
| -------------------- | ------ |
| `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`

```json 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 key。

<Tip>
  原生 Claude Code 安裝程式無法讀取標準的 `.env` 檔案。請勿將上述設定置於 `.env` 檔案中。
</Tip>

#### 3. 開始對話

切換到您的專案目錄並啟動 Claude Code：

```bash theme={null}
$ cd /path/to/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
