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

# TTAPI 快速开始｜AI API调用指南（图像、视频、音频、LLM接口接入）

> 本指南将帮助你快速上手 TTAPI，通过统一API接入图像生成、视频生成、音频生成和大语言模型（LLM）接口，几分钟内完成调用并获取响应结果。

## 1. 获取 API KEY

在调用 API 之前，你需要获取 **TT-API-KEY** 用于身份认证。获取方式：

### Step 1：注册你的账户

<AccordionGroup>
  <Accordion title="注册你的账户">
    打开 [TTAPI 官网](https://ttapi.io/) ，右上角点击 **SIGN IN** ，或者直接打开 [TTAPI Dashboard](https://dashboard.ttapi.io/login) 登录页面，选择 **Github** 或者 **Google** 账户注册/登录。
    <Tip>如果选择google账户注册/登录，需要有外网访问环境，否则页面会超时！目前不支持常规邮箱注册</Tip>
  </Accordion>

  <Accordion title="KEY与额度">
    * 注册成功后，将会收到TTAPI的官方邮件通知并跳转 Dashboard 主页，默认生成一个 TT-API-KEY，这个key将会应用在TTAPI中所有[接口的鉴权](/grids/cn/development/authentication)
    * 并且默认获得 30 quota (≈\$0.3) 的试用额度，页面中会显示当前剩余额度
  </Accordion>
</AccordionGroup>

### Step 2：使用你的账户

<AccordionGroup>
  <Accordion icon="key" title="重置你的 TT-API-KEY">
    我们建议首次注册使用之前修改您的默认TT-API-KEY，控制面板主页点击“RESET”，确认并提交修改您的默认KEY
  </Accordion>

  <Accordion icon="circle-user" title="修改你的账户密码">
    如果您后续不希望使用 github 或者 google 一键登录，可以在 [登录页面](https://dashboard.ttapi.io/login) 点击“忘记密码？”，通过接收注册邮箱中的验证码修改您的登录密码，后续可以进行账户密码登录
  </Accordion>
</AccordionGroup>

## 2. 设置请求头

所有 API 请求都必须在请求头中包含 **TT-API-KEY** 进行身份认证。

```bash theme={null}
TT-API-KEY: YOUR_API_KEY
```

## 3. 发送第一个请求

### 第一步：发送生成请求

下面是一个简单的图像生成 API 调用示例。

<CodeGroup>
  ```bash title="cURL" theme={null}
  curl --request POST \
    --url https://api.ttapi.io/midjourney/v1/imagine \
    --header 'Content-Type: application/json' \
    --header 'TT-API-KEY: "YOUR_API_KEY"' \
    --data '
  {
    "prompt": "一只可爱的猫咪",
    "mode": "fast",
    "hookUrl": "<string>"
  }
  '
  ```

  ```bash title="Python" theme={null}
  import requests

  url = "https://api.ttapi.io/midjourney/v1/imagine"

  payload = {
      "prompt": "一只可爱的猫咪",
      "mode": "fast",
      "hookUrl": "<string>"
  }
  headers = {
      "TT-API-KEY": "YOUR_API_KEY",
      "Content-Type": "application/json"
  }

  response = requests.post(url, json=payload, headers=headers)

  print(response.text)
  ```

  ```bash title="JavaScript" theme={null}
  const options = {
    method: 'POST',
    headers: {'TT-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
    body: JSON.stringify({prompt: '一只可爱的猫咪', mode: 'fast', hookUrl: '<string>'})
  };

  fetch('https://api.ttapi.io/midjourney/v1/imagine', options)
    .then(res => res.json())
    .then(res => console.log(res))
    .catch(err => console.error(err));
  ```

  ```bash title="Java" theme={null}
  HttpResponse<String> response = Unirest.post("https://api.ttapi.io/midjourney/v1/imagine")
    .header("TT-API-KEY", "<api-key>")
    .header("Content-Type", "application/json")
    .body("{\n  \"prompt\": \"一只可爱的猫咪\",\n  \"mode\": \"fast\",\n  \"hookUrl\": \"<string>\"\n}")
    .asString();
  ```
</CodeGroup>

#### 响应示例

```json theme={null}
{
    "status": "SUCCESS", 
    "message": "success",
    "data": {
        "jobId": "b8bd3ff0-4349-4b71-8938-5e13aefa64fe"
    }
}
```

### 第二步：检查任务状态

通过第一步返回的任务ID（jobId）查询生成结果：

<CodeGroup>
  ```bash title="cURL" theme={null}
  curl -X GET https://api.ttapi.io/midjourney/v1/fetch?jobId={jobId} \
  -H "TT-API-KEY: YOUR_API_KEY" \
  ```

  ```bash title="Python" theme={null}
  import requests

  url = "https://api.ttapi.io/midjourney/v1/fetch"
  headers = {
      "TT-API-KEY": "YOUR_API_KEY"
  }
  params = {
      "jobId": "jobId"
  }
  response = requests.get(url, headers=headers, params=params)

  print(response.status_code)
  print(response.json())
  ```

  ```bash title="JavaScript" theme={null}
  const options = {method: 'GET', headers: {'TT-API-KEY': 'YOUR_API_KEY'}};

  fetch('https://api.ttapi.io/midjourney/v1/fetch?jobId={jobId}', options)
    .then(res => res.json())
    .then(res => console.log(res))
    .catch(err => console.error(err));
  ```

  ```bash title="Java" theme={null}
  OkHttpClient client = new OkHttpClient();

  Request request = new Request.Builder()
          .url("https://api.ttapi.io/midjourney/v1/fetch?jobId={jobId}")
          .get()
          .addHeader("TT-API-KEY", "YOUR_API_KEY")
          .build();

  Response response = client.newCall(request).execute();

  System.out.println(response.body().string());
  ```
</CodeGroup>

#### 响应示例

```json theme={null}
{
    "status": "SUCCESS",
    "message": "",
    "jobId": "8ddd973f-b5ff-4192-b418-b37fb65c65f3",
    "data": {
        "action": "imagine",
        "jobId": "8ddd973f-b5ff-4192-b418-b37fb65c65f3",
        "progress": "100",
        "prompt": "一只可爱的猫咪",
        "quota": "2",
        "discordImage": "https://cdn.ttapi.io/midjourney/2025-11-14/20260307_024522_19cf9806e1c7438b.png",
        "cdnImage": "https://cdn.ttapi.io/midjourney/2025-11-14/20260307_024522_19cf9806e1c7438b.png",
        "width": 960,
        "height": 1200,
        "hookUrl": "https://webhook-test.com/40bb50795afa242aee8c837617cd72e9",
        "components": [
            "upsample1","upsample2","upsample3","upsample4","reroll","variation1","variation2","variation3","variation4"
        ],
        "seed": null,
        "images": [
            "https://cdn.ttapi.io/midjourney/20260307/5c7261ec-7271-495d-a0f7-4dd395652a84tl.png",
            "https://cdn.ttapi.io/midjourney/20260307/5c7261ec-7271-495d-a0f7-4dd395652a84tr.png",
            "https://cdn.ttapi.io/midjourney/20260307/5c7261ec-7271-495d-a0f7-4dd395652a84bl.png",
            "https://cdn.ttapi.io/midjourney/20260307/5c7261ec-7271-495d-a0f7-4dd395652a84br.png"
        ]
    }
}
```

## 任务状态说明

|                 |           |
| --------------- | --------- |
| `PENDING_QUEUE` | 任务正在队列中等待 |
| `ON_QUEUE`      | 任务正在处理中   |
| `SUCCESS`       | 任务成功完成    |
| `FAILED`        | 任务执行失败    |

## 帮助及说明

* 如果有关于产品队列限制和使用问题，请参考 [常见问题](/grids/cn/faq/queue) 的相关栏目
* 如有未做说明的其他问题，请[联系技术支持](/grids/cn/about/connect)
