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

# 快速集成

> 几分钟即可开始使用 AihubMax

## 概述

AihubMax 提供兼容 OpenAI 标准的统一 API 网关。您可以通过一个 API Key 和 Base URL 集成任何 AI 模型。

<Info>
  **Base URL：** `https://api.aihubmax.com`
</Info>

## 第一步：获取 API Key

1. 登录 AihubMax 控制台
2. 找到 API Keys 管理页面
3. 点击「创建新 Key」
4. 复制生成的 Key（以 `sk-` 开头）

<Warning>
  请妥善保管您的 API Key，切勿在客户端代码或公开仓库中暴露。
</Warning>

## 第二步：发送第一个请求

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl --request POST \
      --url https://api.aihubmax.com/v1/images/generations \
      --header 'Authorization: Bearer YOUR_API_KEY' \
      --header 'Content-Type: application/json' \
      --data '{
        "model": "gemini-3.1-flash-image-preview",
        "prompt": "一只猫在草地上玩耍"
      }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    response = requests.post(
        "https://api.aihubmax.com/v1/images/generations",
        headers={
            "Authorization": "Bearer YOUR_API_KEY",
            "Content-Type": "application/json"
        },
        json={
            "model": "gemini-3.1-flash-image-preview",
            "prompt": "一只猫在草地上玩耍"
        }
    )

    result = response.json()
    task_id = result["id"]
    print(f"任务已创建: {task_id}")
    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    const response = await fetch('https://api.aihubmax.com/v1/images/generations', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        model: 'gemini-3.1-flash-image-preview',
        prompt: '一只猫在草地上玩耍'
      })
    });

    const result = await response.json();
    console.log('任务已创建:', result.id);
    ```
  </Tab>
</Tabs>

## 第三步：查询任务结果

大多数生成类 API 使用异步处理模式。使用返回的任务 ID 查询结果：

```bash theme={null}
curl --request GET \
  --url https://api.aihubmax.com/v1/tasks/YOUR_TASK_ID \
  --header 'Authorization: Bearer YOUR_API_KEY'
```

当 `status` 变为 `completed` 时，`output` 字段将包含生成的内容。

## 第四步：使用文本模型

AihubMax 完全兼容 OpenAI 的 Chat Completions API：

```bash theme={null}
curl --request POST \
  --url https://api.aihubmax.com/v1/chat/completions \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "user", "content": "你好，你是谁？"}
    ]
  }'
```

## 认证方式

所有接口均需要使用 Bearer Token 进行认证。在每个请求中添加以下请求头：

```
Authorization: Bearer YOUR_API_KEY
```

## 下一步

<CardGroup cols={2}>
  <Card title="API 手册" icon="book" href="/zh/api-manual/image-series/nanobanana/gemini-3.1-flash-image-preview">
    浏览所有可用的 API 端点
  </Card>

  <Card title="集成指南" icon="puzzle-piece" href="/zh/integration-guide/claude-code-cli">
    连接 Claude Code CLI 和其他工具
  </Card>
</CardGroup>
