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: editorValidates input, runs moderation, charges credits and dispatches the job. Responds
201 with the generation object.Headers
Idempotency-KeystringOptional, 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
modelstringModel slug. Provide this or
template.templatestringTemplate slug. Overrides
model.promptstringUp to 4000 characters. Required when the model's spec says so.
negative_promptstringUp to 2000 characters. Used only by models with negativePrompt support.
paramsobjectControl values keyed by
key from the model's params spec.Default {}inputsobjectimages (max 10), video (max 2), audio (max 2): arrays of public URLs. Use Uploads for local files.Default {}visibilitystringprivate, team or public (public shows on Explore once succeeded).Default teamwebhook_urlstringHTTPS 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 OKwith headerIdempotent-Replayed: trueand the original generation (current status). Nothing new is created or charged. Concurrent duplicates wait for the first one. - Same key + different body:
400 INVALID_INPUTwithfield: "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_generationtakes the same thing asidempotency_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))
doneThe generation object
Fields
idstringUnique id.
statusstringSee lifecycle below.
kindstringimage, video, audio, edit, upscale or lipsync.
model / templatestring | nullSlugs used.
prompt, params, inputsWhat was run, with defaults filled in.
outputsarrayEach
{ url, type, width?, height? }. Empty until succeeded. URLs are permanent CDN links.errorobject | null{ code, message, hint?, refunded?, matched? } when failed or moderated.creditsnumberCredits charged. 0 for moderated prompts.
sourcestringweb, api or mcp.
created_at / completed_atstringISO 8601.
Lifecycle#
queued ──► processing ──┬──► succeeded
├──► failed (credits refunded)
└──► moderated (result blocked, credits refunded)
POST rejected with 422 ──► moderated (prompt blocked, recorded privately, credits 0)| Status | Meaning |
|---|---|
queued | Accepted and charged, waiting to be dispatched. Usually lasts milliseconds. |
processing | Running on a model. Images take seconds, videos up to a few minutes. |
succeeded | Done. outputs[] holds CDN URLs. Terminal. |
failed | The model could not complete the job. Credits refunded, error explains why. Terminal. |
moderated | Blocked by the safety filter. Prompt blocks are recorded with credits 0 (never charged); result blocks are refunded. Terminal. |
canceled | Reserved for future use. Terminal. |
Moderated prompts
A prompt that breaks the content policy is rejected synchronously with422 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:
{
"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: fetchGET /api/v1/generations/{id} with your key before acting on it, and use a hard-to-guess path for webhook_url.GET
/api/v1/generationsThe 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
statusstringFilter by status.
limitinteger1–100.Default
24cursorstringThe
next_cursor from the previous page.{ "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: editorRemoves the generation from the team library. Credits already spent are not refunded.
{ "id": "0b6f3c1e-…", "object": "generation", "deleted": true }