> ## Documentation Index
> Fetch the complete documentation index at: https://pikzels.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Async Requests

> Get a request ID right away & fetch the result when it's ready.

Send `"async": true` to get a `202` right away & fetch the result later. It suits long generations & clients that can't hold a connection open, such as behind a proxy or in a short-timeout serverless function. Every thumbnail & title endpoint accepts it.

## Send the Request

```bash cURL theme={"theme":"css-variables"}
curl -X POST https://api.pikzels.com/v2/thumbnail/text \
  -H "X-Api-Key: pkz_example_a1b2c3d4e5f6" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "I bought my first island",
    "model": "pkz_4_5",
    "format": "16:9",
    "async": true
  }'
```

```json Response (202) theme={"theme":"css-variables"}
{
  "request_id": "18b2ad5e-2a9e-4d3f-b9a8-9f2a1e0b1234",
  "status": "IN_QUEUE",
  "status_url": "https://api.pikzels.com/v2/requests/18b2ad5e-2a9e-4d3f-b9a8-9f2a1e0b1234/status",
  "response_url": "https://api.pikzels.com/v2/requests/18b2ad5e-2a9e-4d3f-b9a8-9f2a1e0b1234"
}
```

The request is checked & charged before the `202`, so errors such as `VALIDATION_ERROR`, `INSUFFICIENT_CREDITS` or `INVALID_IMAGE` come back on this call as usual.

## Poll the Status

`GET` the `status_url` every few seconds ([Get request status](https://pikzels.com/docs/requests/get-request-status.md)).

| `status` | HTTP | Meaning |
| - | - | - |
| `IN_QUEUE` | `202` | Waiting to start |
| `IN_PROGRESS` | `202` | Generating |
| `COMPLETED` | `200` | Done, successfully or not |

The body matches the `202` above, plus an `error` when the request failed:

```json COMPLETED with error (200) theme={"theme":"css-variables"}
{
  "request_id": "18b2ad5e-2a9e-4d3f-b9a8-9f2a1e0b1234",
  "status": "COMPLETED",
  "status_url": "https://api.pikzels.com/v2/requests/18b2ad5e-2a9e-4d3f-b9a8-9f2a1e0b1234/status",
  "response_url": "https://api.pikzels.com/v2/requests/18b2ad5e-2a9e-4d3f-b9a8-9f2a1e0b1234",
  "error": {
    "code": "GENERATION_FAILED",
    "message": "Something went wrong. Please try again."
  }
}
```

## Fetch the Result

Once the status is `COMPLETED`, `GET` the `response_url` ([Get request result](https://pikzels.com/docs/requests/get-request-result.md)). It returns exactly what the request returns without `async`: the endpoint's response, or its [error body](https://pikzels.com/docs/errors.md) with the HTTP status it failed with.

Fetching it earlier returns `400` `REQUEST_IN_PROGRESS`.

## Full Example

```python Python theme={"theme":"css-variables"}
import time
import requests

HEADERS = {"X-Api-Key": "pkz_example_a1b2c3d4e5f6"}

submitted = requests.post(
    "https://api.pikzels.com/v2/thumbnail/text",
    headers=HEADERS,
    json={"prompt": "I bought my first island", "model": "pkz_4_5", "format": "16:9", "async": True},
)
submitted.raise_for_status()
urls = submitted.json()

while True:
    status = requests.get(urls["status_url"], headers=HEADERS)
    status.raise_for_status()
    if status.json()["status"] == "COMPLETED":
        break
    time.sleep(3)

# Same body & HTTP status as without async, errors included
result = requests.get(urls["response_url"], headers=HEADERS)
print(result.status_code, result.json())
```

```javascript JavaScript theme={"theme":"css-variables"}
const headers = { "X-Api-Key": "pkz_example_a1b2c3d4e5f6" };

const submitted = await fetch("https://api.pikzels.com/v2/thumbnail/text", {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({ prompt: "I bought my first island", model: "pkz_4_5", format: "16:9", async: true }),
});
if (!submitted.ok) throw new Error(`HTTP ${submitted.status}`);
const { status_url, response_url } = await submitted.json();

while (true) {
  const status = await fetch(status_url, { headers });
  if (!status.ok) throw new Error(`HTTP ${status.status}`);
  if ((await status.json()).status === "COMPLETED") break;
  await new Promise((resolve) => setTimeout(resolve, 3000));
}

// Same body & HTTP status as without async, errors included
const result = await fetch(response_url, { headers });
console.log(result.status, await result.json());
```

## Good to Know

* A request still unfinished an hour after submit fails with `GENERATION_TIMEOUT`.
* There are no webhooks.
* Both `GET` endpoints also work for requests sent without `async`, which are always `COMPLETED`.
* The result of a request sent before October 25, 2026 returns `404` `NOT_FOUND`.


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