> ## 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.

# Status Task

> Query the status of a generation task

Query the status and results of a generation task.

## Endpoint

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

## Parameters

<ParamField path="model" type="string" required>
  Model ID used when the task was submitted (e.g., `nano-banana`, `flux-2`).
</ParamField>

<ParamField query="taskId" type="string" required>
  Task ID returned from the [Generate Task](/api-reference/generate-task) endpoint.
</ParamField>

## Headers

<ParamField header="Authorization" type="string" required>
  Bearer token for API authentication. Format: `Bearer YOUR_API_KEY`
</ParamField>

## Response

```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
  }
}
```

### Task States

| State        | Description                             |
| ------------ | --------------------------------------- |
| `pending`    | Task received, waiting to be processed  |
| `processing` | Task is being processed by the AI model |
| `success`    | Generation completed successfully       |
| `failed`     | Generation failed (see error details)   |

### Response Fields

<ResponseField name="taskId" type="string">
  Unique task identifier.
</ResponseField>

<ResponseField name="state" type="string">
  Current task state: `pending`, `processing`, `success`, or `failed`.
</ResponseField>

<ResponseField name="resultJson" type="string">
  JSON string containing `resultUrls` array. Only present when `state` is `success`. Parse with `JSON.parse()`.
</ResponseField>

<ResponseField name="costTime" type="integer">
  Processing time in milliseconds. Only present on completion.
</ResponseField>

<ResponseField name="createTime" type="integer">
  Task creation timestamp (Unix milliseconds).
</ResponseField>

<ResponseField name="completeTime" type="integer">
  Task completion timestamp (Unix milliseconds). Only present on completion.
</ResponseField>

<ResponseField name="failCode" type="string">
  Error code. Only present when `state` is `failed`.
</ResponseField>

<ResponseField name="failMsg" type="string">
  Human-readable error message. Only present when `state` is `failed`.
</ResponseField>

## State-Specific Responses

### Pending / Processing

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

### Success

```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
  }
}
```

**Parsing resultJson:**

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

### Failed

```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` with `state: "failed"` means the API request succeeded but the task itself failed. Check `failCode` and `failMsg` for the reason. See [Errors](/api-reference/errors) for all failure codes.
</Note>

## Result URLs

The `resultUrls` array contains direct links to generated content:

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

<Warning>
  Result URLs expire after 24 hours. Download and store important outputs promptly.
</Warning>

## Examples

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

  <Tab title="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>

  <Tab title="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>
</Tabs>

## Polling Example

<Tabs>
  <Tab title="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>

  <Tab title="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')
    ```
  </Tab>
</Tabs>

## Error Responses

| Code  | Description                |
| ----- | -------------------------- |
| `401` | Invalid or missing API key |
| `404` | Task not found             |
| `429` | Rate limit exceeded        |

See [Errors](/api-reference/errors) for detailed error handling.
