> ## 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 で結果を取得します。

このエンドポイントでは、1 回のリクエストで**生成タスクを 1 件**送信します。モデル ID はパス、モデルのパラメーターは `input` に指定します。非同期リクエストの送信に成功すると、`data.taskId` が返ります。モデル ID とともに保存し、両方の値を使って[タスクのステータスを確認](https://apixo.ai/docs/ja/api-reference/status-task.md)し、結果を取得します。

独立した項目を 1 回のリクエストでまとめて送る場合は、[一括生成](https://apixo.ai/docs/ja/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/ja/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/ja/models.md)、共通フィールドは[パラメーター仕様](https://apixo.ai/docs/ja/api-reference/parameters.md)を参照してください。

## レスポンス

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

**code** `integer`

HTTP ステータスコードです。

**message** `string`

状態を説明するメッセージです。

**data** `object`

**HTTP ステータスコードです。**

**taskId** `string`

タスクを追跡するための一意の ID です。この値で[ステータスを確認](https://apixo.ai/docs/ja/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/ja/api-reference/errors.md)を参照してください。


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