API reference

Generations

A generation is one run of a model or template. It is asynchronous: creating it returns immediately, and you either poll it or receive a webhook when it finishes.
POST/api/v1/generationsrole: editor
Validates input, runs moderation, charges credits and dispatches the job. Responds 201 with the generation object.

Headers

Idempotency-Keystring
Optional, recommended. Up to 255 visible ASCII characters (use a UUID). Repeating it within 24 h returns the original generation instead of creating and charging a new one. See Idempotency.

Body

modelstring
Model slug. Provide this or template.
templatestring
Template slug. Overrides model.
promptstring
Up to 4000 characters. Required when the model's spec says so.
negative_promptstring
Up to 2000 characters. Used only by models with negativePrompt support.
paramsobject
Control values keyed by key from the model's params spec.Default {}
inputsobject
images (max 10), video (max 2), audio (max 2): arrays of public URLs. Use Uploads for local files.Default {}
visibilitystring
private, team or public (public shows on Explore once succeeded).Default team
webhook_urlstring
HTTPS URL that receives a POST when the generation reaches a terminal status.
curl https://<your-host>/api/v1/generations \
  -H "Authorization: Bearer $AIO_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "model": "kling-2-5-turbo",
    "prompt": "slow push-in, steam rising from the cup",
    "params": { "duration": 5 },
    "inputs": { "images": ["https://cdn…/uploads/coffee.jpg"] },
    "webhook_url": "https://example.com/hooks/pixwellai"
  }'

Idempotency#

Networks fail after the server has already charged. To retry safely, send an Idempotency-Key header with every create and reuse the same key when you retry that request:

  • First request: 201 Created, a new generation, credits charged.
  • Same key + same body within 24 h: 200 OK with header Idempotent-Replayed: true and the original generation (current status). Nothing new is created or charged. Concurrent duplicates wait for the first one.
  • Same key + different body: 400 INVALID_INPUT with field: "Idempotency-Key". Use a new key for a new request.
  • Requests that fail before a generation exists (validation, moderation, insufficient credits) are not remembered, so you can fix the input and retry with the same key.
  • Keys are scoped to your team. The MCP tool create_generation takes the same thing as idempotency_key.
KEY=$(uuidgen)
for attempt in 1 2 3; do
  curl -sf https://<your-host>/api/v1/generations \
    -H "Authorization: Bearer $AIO_KEY" -H "Content-Type: application/json" \
    -H "Idempotency-Key: $KEY" \
    -d '{ "template": "studio-headshot", "inputs": { "images": ["https://cdn…/selfie.jpg"] } }' && break
  sleep $((attempt * 2))
done

The generation object

Fields

idstring
Unique id.
statusstring
See lifecycle below.
kindstring
image, video, audio, edit, upscale or lipsync.
model / templatestring | null
Slugs used.
prompt, params, inputs
What was run, with defaults filled in.
outputsarray
Each { url, type, width?, height? }. Empty until succeeded. URLs are permanent CDN links.
errorobject | null
{ code, message, hint?, refunded?, matched? } when failed or moderated.
creditsnumber
Credits charged. 0 for moderated prompts.
sourcestring
web, api or mcp.
created_at / completed_atstring
ISO 8601.

Lifecycle#

states
queued ──► processing ──┬──► succeeded
                        ├──► failed      (credits refunded)
                        └──► moderated   (result blocked, credits refunded)

POST rejected with 422 ──► moderated   (prompt blocked, recorded privately, credits 0)
StatusMeaning
queuedAccepted and charged, waiting to be dispatched. Usually lasts milliseconds.
processingRunning on a model. Images take seconds, videos up to a few minutes.
succeededDone. outputs[] holds CDN URLs. Terminal.
failedThe model could not complete the job. Credits refunded, error explains why. Terminal.
moderatedBlocked by the safety filter. Prompt blocks are recorded with credits 0 (never charged); result blocks are refunded. Terminal.
canceledReserved for future use. Terminal.

Moderated prompts

A prompt that breaks the content policy is rejected synchronously with 422 and a MODERATION_* code. Nothing is charged; a private record with status moderated is kept in the team history. See Errors.

Polling#

GET /api/v1/generations/{id} also refreshes the job when it is still in flight, so polling is always accurate even if a webhook was missed. Poll every 2–3 s for images and every 5–10 s for video. Each poll counts toward your rate limit.

const TERMINAL = ["succeeded", "failed", "moderated", "canceled"];

async function waitFor(id, { interval = 3000, timeout = 600_000 } = {}) {
  const start = Date.now();
  while (Date.now() - start < timeout) {
    const r = await fetch(`https://<your-host>/api/v1/generations/${id}`, {
      headers: { Authorization: `Bearer ${AIO_KEY}` },
    });
    const gen = await r.json();
    if (TERMINAL.includes(gen.status)) return gen;
    await new Promise((s) => setTimeout(s, interval));
  }
  throw new Error("timed out");
}

Webhooks#

Set webhook_url and we POST to it once the generation reaches a terminal status. The body is the same generation object you get from the API, wrapped in an event envelope:

POST webhook_url
{
  "type": "generation.updated",
  "data": {
    "id": "0b6f3c1e-…",
    "object": "generation",
    "status": "succeeded",
    "outputs": [{ "url": "https://cdn…/….mp4", "type": "video" }],
    "credits": 35,
    "...": "…"
  }
}
  • Headers: Content-Type: application/json, User-Agent: PixwellAI-Webhooks/1.0.
  • Respond with any 2xx or 4xx to acknowledge. 5xx and network errors are retried 3 times with backoff (1 s, 2 s, 4 s).
  • Deliveries can arrive more than once; deduplicate on data.id + data.status.

Payloads are not signed yet

Treat the webhook as a signal, not as truth: fetch GET /api/v1/generations/{id} with your key before acting on it, and use a hard-to-guess path for webhook_url.
GET/api/v1/generations
The team's generations, newest first, including ones made in the web app. Same list envelope as every other list. Generation responses are always Cache-Control: no-store.

Query

statusstring
Filter by status.
limitinteger
1–100.Default 24
cursorstring
The next_cursor from the previous page.
200 OK
{ "object": "list", "data": [ { "id": "…", "object": "generation", "…": "…" } ],
  "has_more": true, "next_cursor": "MTc5NTA4NTM2MTAwMA" }
GET/api/v1/generations/{id}
One generation. Generations of other teams return 404 NOT_FOUND.
DELETE/api/v1/generations/{id}role: editor
Removes the generation from the team library. Credits already spent are not refunded.
200 OK
{ "id": "0b6f3c1e-…", "object": "generation", "deleted": true }