> ## 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：タスク ID で生成結果を確認

> モデルとタスク ID で APIXO の生成タスクをポーリングし、状態、エラーの詳細、課金情報、最終結果の URL を取得します。

URL パスにはタスク送信時のモデル ID、クエリパラメーター `taskId` には返された `data.taskId` を指定します。バッチ ID で確認する場合は、[バッチのステータス確認](https://apixo.ai/docs/ja/api-reference/batch-status.md)を使います。

| レスポンスの状態 | クライアントでの対応 |
| - | - |
| `pending` または `processing` | タスク ID を保持し、しばらく待って再度ポーリングします。 |
| `success` | ポーリングを停止し、送信時に指定したモデルの結果形式に従って `data.resultJson` をパースします。 |
| `failed` | ポーリングを停止します。`failCode` と `failMsg` を記録し、[エラーコード](https://apixo.ai/docs/ja/api-reference/errors.md)を参照して復旧方法を判断します。 |

## エンドポイント

```
GET https://api.apixo.ai/api/v1/statusTask/{model}?taskId={taskId}
```

## パラメーター

**model** `string` *required*

タスク送信時のモデル ID です。例として `nano-banana`、`flux-2` があります。

**taskId** `string` *required*

[生成タスクの送信](https://apixo.ai/docs/ja/api-reference/generate-task.md)エンドポイントが返したタスク ID です。

## リクエストヘッダー

**Authorization** `string` *required*

API 認証に使用する Bearer トークンです。`Bearer YOUR_API_KEY` の形式で指定します。

## レスポンス

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://cdn.apixo.ai/output/abc123.jpg\"]}",
    "costTime": 12500,
    "createTime": 1704067200000,
    "completeTime": 1704067212500
  }
}
```

### タスクの状態

| 状態 | 説明 |
| - | - |
| `pending` | タスクを受け付け、処理を待機中 |
| `processing` | AI モデルがタスクを処理中 |
| `success` | 生成が正常に完了 |
| `failed` | 生成に失敗。エラーの詳細を確認 |

### レスポンスのフィールド

**taskId** `string`

タスクを一意に識別する ID です。

**state** `string`

現在のタスク状態です。`pending`、`processing`、`success`、`failed` のいずれかが返されます。

**resultJson** `string`

`resultUrls` 配列を含む JSON 文字列です。`state` が `success` の場合にのみ返ります。`JSON.parse()` でパースしてください。

**costTime** `integer`

処理時間をミリ秒で示します。処理完了時にのみ返ります。

**createTime** `integer`

タスクの作成日時を Unix 時刻のミリ秒で示します。

**completeTime** `integer`

タスクの完了日時を Unix 時刻のミリ秒で示します。処理完了時にのみ返ります。

**failCode** `string`

エラーコードです。`state` が `failed` の場合にのみ返ります。

**failMsg** `string`

エラーを説明するメッセージです。`state` が `failed` の場合にのみ返ります。

**billing** `object`

確定した課金情報を示す任意の項目です。成功時の最終レスポンスで精算の詳細を公開するモデルに限り返ります。

**billing.settlementState** `string`

課金情報の精算ステータスです。精算済みのデータでは `final` になります。

**billing.unit** `string`

時間に基づく課金フィールドの単位です。例として `second` があります。

## 状態別のレスポンス

### 処理待ちまたは処理中

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

### 成功

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://cdn.apixo.ai/output/abc123.jpg\"]}",
    "costTime": 12500,
    "createTime": 1704067200000,
    "completeTime": 1704067212500
  }
}
```

**resultJson をパースする**

```javascript theme={null}
const result = JSON.parse(data.resultJson);
const urls = result.resultUrls; // Array of generated content URLs
```

### 失敗

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_abc123xyz789",
    "state": "failed",
    "failCode": "CONTENT_VIOLATION",
    "failMsg": "Content violates usage policy",
    "createTime": 1704067200000,
    "completeTime": 1704067205000
  }
}
```

> [!NOTE]
>
> HTTP `200` で `state: "failed"` が返る場合、API の問い合わせ自体は成功していますが、タスクは失敗しています。原因は `failCode` と `failMsg` で確認してください。失敗コードの一覧は[エラーコード](https://apixo.ai/docs/ja/api-reference/errors.md)を参照してください。

## 結果 URL

`resultUrls` 配列には、生成されたコンテンツへの直接リンクが含まれます。

```json theme={null}
{
  "resultUrls": [
    "https://cdn.apixo.ai/output/abc123.jpg",
    "https://cdn.apixo.ai/output/abc124.jpg"
  ]
}
```

> [!WARNING]
>
> 生成されたファイルの保存期間はデフォルトで 15 日間です。保存期間は API キーのストレージ設定によって異なる場合があります。重要な結果は早めにダウンロードして保存してください。

## サンプル

> [tab] cURL
>
> ```bash theme={null}
> curl "https://api.apixo.ai/api/v1/statusTask/nano-banana?taskId=task_abc123" \
>   -H "Authorization: Bearer YOUR_API_KEY"
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const response = await fetch(
>   'https://api.apixo.ai/api/v1/statusTask/nano-banana?taskId=task_abc123',
>   {
>     headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
>   }
> );
> const { data } = await response.json();
>
> if (data.state === 'success') {
>   const urls = JSON.parse(data.resultJson).resultUrls;
>   console.log('Generated:', urls);
> }
> ```

> [tab] Python
>
> ```python theme={null}
> import json
>
> response = requests.get(
>     'https://api.apixo.ai/api/v1/statusTask/nano-banana',
>     params={'taskId': 'task_abc123'},
>     headers={'Authorization': 'Bearer YOUR_API_KEY'},
> )
>
> data = response.json()['data']
>
> if data['state'] == 'success':
>     urls = json.loads(data['resultJson'])['resultUrls']
>     print(f'Generated: {urls}')
> ```

## ポーリングのサンプル

> [tab] JavaScript
>
> ```javascript theme={null}
> async function waitForResult(model, taskId, apiKey) {
>   const maxAttempts = 60;
>   const pollInterval = 3000; // 3 seconds
>
>   for (let i = 0; i < maxAttempts; i++) {
>     const response = await fetch(
>       `https://api.apixo.ai/api/v1/statusTask/${model}?taskId=${taskId}`,
>       { headers: { 'Authorization': `Bearer ${apiKey}` } }
>     );
>
>     const { data } = await response.json();
>
>     switch (data.state) {
>       case 'success':
>         return JSON.parse(data.resultJson).resultUrls;
>       case 'failed':
>         throw new Error(`${data.failCode}: ${data.failMsg}`);
>       default:
>         await new Promise(r => setTimeout(r, pollInterval));
>     }
>   }
>
>   throw new Error('Timeout waiting for result');
> }
> ```

> [tab] Python
>
> ```python theme={null}
> import time
> import json
>
> def wait_for_result(model: str, task_id: str, api_key: str) -> list[str]:
>     max_attempts = 60
>     poll_interval = 3  # seconds
>
>     for _ in range(max_attempts):
>         response = requests.get(
>             f'https://api.apixo.ai/api/v1/statusTask/{model}',
>             params={'taskId': task_id},
>             headers={'Authorization': f'Bearer {api_key}'},
>         )
>
>         data = response.json()['data']
>
>         if data['state'] == 'success':
>             return json.loads(data['resultJson'])['resultUrls']
>         elif data['state'] == 'failed':
>             raise Exception(f"{data['failCode']}: {data['failMsg']}")
>
>         time.sleep(poll_interval)
>
>     raise Exception('Timeout waiting for result')
> ```

## エラーレスポンス

| コード | 説明 |
| - | - |
| `401` | API キーが無効または指定されていない |
| `404` | タスクが見つからない |
| `429` | レート制限を超過 |

エラーへの対処方法は[エラーコード](https://apixo.ai/docs/ja/api-reference/errors.md)を参照してください。


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