> ## 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/api-reference/status-task.md)获取结果。

要在单个请求中提交多个独立任务，请使用[批量提交](https://apixo.ai/docs/zh/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/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/models.md)，通用字段见[参数规范](https://apixo.ai/docs/zh/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/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/api-reference/errors.md)。


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