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

# 送出生成任務 API · 影像、影片和音訊任務

> 送出影像、影片、音訊或實用工具模型的非同步任務，傳入模型所需的參數，並透過輪詢或 Webhook 取得結果。

此端點每次送出**一個生成任務**。將模型 ID 寫入路徑，將該模型的參數放入 `input`。非同步請求送出成功後會傳回 `data.taskId`。將其與模型 ID 一起儲存，再用這兩個值透過[查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)取得結果。

要在一個請求中送出多個獨立任務，請使用[批次送出](https://apixo.ai/docs/zh-hant/api-reference/batch-generate.md)，可檢視各項是否被受理以及批次進度。

## 端點

```
POST https://api.apixo.ai/api/v1/generateTask/{model}
```

將 `{model}` 替換成模型 ID，例如 `nano-banana`、`flux-2`、`sora-2` 或 `midjourney`。

## 請求標頭

**Authorization** `string` *required*

用於 API 身分驗證的 Bearer 令牌。格式為 `Bearer YOUR_API_KEY`。

**Content-Type** `string` *required*

必須為 `application/json`。

## 請求主體

**request\_type** `string` *required* (default: async)

取得結果的方式。`async` 表示透過狀態端點輪詢，`callback` 表示透過 Webhook 通知結果。

**callback\_url** `string`

用於接收結果的 Webhook URL。`request_type` 為 `callback` 時必填。必須是可公開存取的 HTTPS URL，且能在 30 秒內傳回 HTTP 200。詳見 [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

模型專用的生成參數。

**常用欄位**

**mode** `string` *required*

生成模式，例如 `text-to-image`、`image-to-image` 或 `text-to-video`。

**prompt** `string` *required*

用文字說明想要的輸出。

**image\_urls** `string[]`

編輯模式使用的參考影像，例如 `image-to-image`。

**aspect\_ratio** `string`

輸出的長寬比，例如 `1:1`、`16:9` 或 `9:16`。

> [!NOTE]
>
> 完整參數列表見各[模型文件](https://apixo.ai/docs/zh-hant/models.md)，通用欄位見[參數規範](https://apixo.ai/docs/zh-hant/api-reference/parameters.md)。

## 回應

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789"
  }
}
```

**code** `integer`

HTTP 狀態碼。

**message** `string`

狀態說明。

**data** `object`

**屬性**

**taskId** `string`

用於跟蹤任務的唯一識別符號。可用此值[查詢狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)。

> [!TIP]
>
> 請儲存 `taskId`，以便稍後查詢狀態或排查問題。

## 示例

### 非同步模式（輪詢）

> [tab] cURL
>
> ```bash theme={null}
> curl -X POST https://api.apixo.ai/api/v1/generateTask/nano-banana \
>   -H "Authorization: Bearer YOUR_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "request_type": "async",
>     "input": {
>       "mode": "text-to-image",
>       "prompt": "A futuristic city at sunset",
>       "aspect_ratio": "16:9"
>     }
>   }'
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const response = await fetch('https://api.apixo.ai/api/v1/generateTask/nano-banana', {
>   method: 'POST',
>   headers: {
>     'Authorization': 'Bearer YOUR_API_KEY',
>     'Content-Type': 'application/json',
>   },
>   body: JSON.stringify({
>     request_type: 'async',
>     input: {
>       mode: 'text-to-image',
>       prompt: 'A futuristic city at sunset',
>       aspect_ratio: '16:9',
>     },
>   }),
> });
>
> const { data } = await response.json();
> console.log('Task ID:', data.taskId);
> ```

> [tab] Python
>
> ```python theme={null}
> import requests
>
> response = requests.post(
>     'https://api.apixo.ai/api/v1/generateTask/nano-banana',
>     headers={
>         'Authorization': 'Bearer YOUR_API_KEY',
>         'Content-Type': 'application/json',
>     },
>     json={
>         'request_type': 'async',
>         'input': {
>             'mode': 'text-to-image',
>             'prompt': 'A futuristic city at sunset',
>             'aspect_ratio': '16:9',
>         },
>     }
> )
>
> task_id = response.json()['data']['taskId']
> print(f'Task ID: {task_id}')
> ```

### 回呼模式（Webhook）

> [tab] cURL
>
> ```bash theme={null}
> curl -X POST https://api.apixo.ai/api/v1/generateTask/nano-banana \
>   -H "Authorization: Bearer YOUR_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "request_type": "callback",
>     "callback_url": "https://your-server.com/webhook/apixo",
>     "input": {
>       "mode": "text-to-image",
>       "prompt": "A futuristic city at sunset",
>       "aspect_ratio": "16:9"
>     }
>   }'
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const response = await fetch('https://api.apixo.ai/api/v1/generateTask/nano-banana', {
>   method: 'POST',
>   headers: {
>     'Authorization': 'Bearer YOUR_API_KEY',
>     'Content-Type': 'application/json',
>   },
>   body: JSON.stringify({
>     request_type: 'callback',
>     callback_url: 'https://your-server.com/webhook/apixo',
>     input: {
>       mode: 'text-to-image',
>       prompt: 'A futuristic city at sunset',
>       aspect_ratio: '16:9',
>     },
>   }),
> });
> ```

> [tab] Python
>
> ```python theme={null}
> response = requests.post(
>     'https://api.apixo.ai/api/v1/generateTask/nano-banana',
>     headers={
>         'Authorization': 'Bearer YOUR_API_KEY',
>         'Content-Type': 'application/json',
>     },
>     json={
>         'request_type': 'callback',
>         'callback_url': 'https://your-server.com/webhook/apixo',
>         'input': {
>             'mode': 'text-to-image',
>             'prompt': 'A futuristic city at sunset',
>             'aspect_ratio': '16:9',
>         },
>     }
> )
> ```

## 錯誤回應

| 代碼 | 說明 |
| - | - |
| `400` | 請求參數無效 |
| `401` | API 金鑰無效或缺失 |
| `403` | 權限不足 |
| `429` | 超出速率限制 |
| `500` | 伺服器錯誤 |

詳細的錯誤處理方法見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.