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

# Aihubmix 一站式调用指南

> 了解 Aihubmix 的通用模型呼叫方式

Aihubmix 以 OpenAI 模型呼叫介面為標準，聚合了多個模型，包括 OpenAI、谷歌 Gemini、Anthropic Claude 等系列模型。呼叫任何模型都使用相同的方式，只需要修改對應的 `模型 ID` 即可。

<Tip>
  核心要點：只需要在 client 內部加入轉發的 `base_url` 和 AiHubMix 平台的[密鑰](https://aihubmix.com/token)。
  模型 ID 可以在[模型廣場的卡片上](https://aihubmix.com/models)點擊「複製按鈕」來獲取。
</Tip>

## 基礎整合：使用 OpenAI 官方庫

### Python 示例

```py Python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-***", # 換成你在 AiHubMix 生成的密鑰
    base_url="https://aihubmix.com/v1"
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="gpt-4o-mini",  # 替換為任意支援的模型 ID
)

print(chat_completion)
```

<Info>
  OpenAI 官方當前服務狀態 [查詢](https://status.openai.com/)
</Info>

## 通用模型轉發 API

端點（Endpoint）： `POST` /v1/chat/completions

**Body 請求參數：**

```json theme={null}
{
  "model": "gpt-4o-mini",
  "messages": [
    {
      "role": "user",
      "content": "What is the meaning of life?"
    }
  ]
}
```

### 請求參數

| 名稱            | 位置     | 類型     | 必選 | 說明                        |
| ------------- | ------ | ------ | -- | ------------------------- |
| Authorization | header | string | 否  | Bearer AIHUBMIX\_API\_KEY |
| Content-Type  | header | string | 否  | none                      |
| body          | body   | object | 否  | none                      |

**返回示例：**

```json theme={null}
200 Response
```

```json theme={null}
{
  "id": "chatcmpl-AzJqsyf2h02BKjrqHMA1HVUQpiDfL",
  "model": "gpt-4o-mini",
  "object": "chat.completion",
  "created": 1739177682,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The meaning of life is a philosophical question that has been debated for centuries. Different people and cultures may have different beliefs about the purpose and significance of life. Some believe that the meaning of life is to seek happiness and fulfillment, while others believe in spiritual or religious meanings such as serving a higher power or fulfilling a destiny. Ultimately, the meaning of life may be a deeply personal and individual question that each person must answer for themselves."
      },
      "finish_reason": "stop"
    }
  ],
  "system_fingerprint": "fp_0165350fbb",
  "usage": {
    "prompt_tokens": 14,
    "completion_tokens": 86,
    "total_tokens": 100
  }
}
```

### 返回結果

| 狀態碼 | 狀態碼含義 | 說明   | 資料模型   |
| --- | ----- | ---- | ------ |
| 200 | OK    | none | Inline |

***

最後更新：2026-06-01
