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

# Generate Task

> Submit a generation task to an AI model

Submit a generation task to any supported AI model.

## Endpoint

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

Replace `{model}` with the model ID (e.g., `nano-banana`, `flux-2`, `sora-2`, `midjourney`).

## Headers

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

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`.
</ParamField>

## Request Body

<ParamField body="request_type" type="string" required default="async">
  How to receive results. `async` for polling via the status endpoint, `callback` for webhook delivery.
</ParamField>

<ParamField body="callback_url" type="string">
  Webhook URL for receiving results. Required when `request_type` is `callback`. Must be a publicly accessible HTTPS URL that responds with HTTP 200 within 30 seconds. See [Webhooks](/api-reference/webhooks) for details.
</ParamField>

<ParamField body="input" type="object" required>
  Model-specific generation parameters.

  <Expandable title="Common fields">
    <ParamField body="mode" type="string" required>
      Generation mode (e.g., `text-to-image`, `image-to-image`, `text-to-video`).
    </ParamField>

    <ParamField body="prompt" type="string" required>
      Text description of the desired output.
    </ParamField>

    <ParamField body="image_urls" type="string[]">
      Reference images for editing modes (e.g., `image-to-image`).
    </ParamField>

    <ParamField body="aspect_ratio" type="string">
      Output dimensions ratio (e.g., `1:1`, `16:9`, `9:16`).
    </ParamField>
  </Expandable>
</ParamField>

<Info>
  See individual [model documentation](/models) for complete parameter lists, or the [Parameter Specification](/api-reference/parameters) for all common fields.
</Info>

## Response

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

<ResponseField name="code" type="integer">
  HTTP status code.
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable status message.
</ResponseField>

<ResponseField name="data" type="object">
  <Expandable title="properties">
    <ResponseField name="taskId" type="string">
      Unique identifier for tracking the task. Use this to [query status](/api-reference/status-task).
    </ResponseField>
  </Expandable>
</ResponseField>

<Tip>
  Save the `taskId` — you'll need it to query status or debug issues later.
</Tip>

## Examples

### Async Mode (Polling)

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

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

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

### Callback Mode (Webhooks)

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

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

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

## Error Responses

| Code  | Description                |
| ----- | -------------------------- |
| `400` | Invalid request parameters |
| `401` | Invalid or missing API key |
| `403` | Insufficient permissions   |
| `429` | Rate limit exceeded        |
| `500` | Server error               |

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