Skip to content

Async image generation

Synchronous image generation (POST /v1/images/generations) has a 30-second budget. Large resolutions, high step counts, or a saturated deployment hit one of these:

ResponseMeaning
504 image_generation_timeoutThe job didn’t finish inside the 30s sync budget.
5xx upstream_errorThe GPU worker failed — most often out of GPU memory. The sync path can’t always tell you the exact cause.
429 replica_saturatedEvery replica is at its concurrency limit right now.

The async path solves all three: the request is accepted immediately, runs without the 30s limit, and if it fails you get the exact error code (e.g. vram_exceeded) on the request record.

Add ?async=true to the same images endpoint — same body, same auth. Include an Idempotency-Key header so a network retry can’t create a duplicate job:

Terminal window
curl "https://<your-deployment>.inference.meshive.ai/v1/images/generations?async=true" \
-H "Authorization: Bearer $MESHIVE_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-42-attempt-1" \
-d '{
"model": "<model-id>",
"prompt": "A sunset over the ocean, oil painting",
"size": "1024x1024",
"n": 1
}'

The response is a 202 Accepted with a request id:

{
"id": "req_9f8e7d6c5b4a3210",
"object": "inference.request",
"status": "queued",
"modality": "image",
"estimated_seconds": 30
}

All request parameters work the same as in sync mode — including the Meshive extensions negative_prompt, seed, steps, guidance_scale, storage_credential_id (output bucket), and webhook_url. See the Images API reference for the full table.

Image edits (/v1/images/edits) accept ?async=true the same way, with one exception: the mask parameter is sync-only (async returns 400 async_mask_unsupported).

Three routes — pick whichever fits your integration:

RouteHowBest for
PollingGET /v1/requests/{id} — when status is succeeded, the response includes presigned output_urlsSimple scripts
WebhookSet webhook_url on the request, or register a workspace endpointServers — no polling
ConsoleRequests (status & errors) + Artifacts (the files)Manual checks
Terminal window
curl https://<your-deployment>.inference.meshive.ai/v1/requests/req_9f8e7d6c5b4a3210 \
-H "Authorization: Bearer $MESHIVE_API_KEY"
{
"id": "req_9f8e7d6c5b4a3210",
"object": "inference.request",
"modality": "image",
"status": "succeeded",
"output_object_key": "serverless/requests/req_9f8e7d6c5b4a3210/result_0.png",
"output_bucket": "meshive-r2",
"output_urls": ["https://...presigned, valid ~1 hour..."],
"error_code": null,
"error_message": null,
"queued_at": 1780000000,
"started_at": 1780000004,
"completed_at": 1780000031
}

Statuses move queued → running → succeeded | failed | canceled. Poll every few seconds until the status is one of the three terminal values — every accepted request is guaranteed to reach one.

Pass webhook_url on the request (or register a workspace-wide endpoint) and Meshive POSTs you a signed event the moment the request finishes — request.completed, request.failed, or request.canceled. Setup, payload schema, and signature verification: Webhooks.

Serverless › Requests shows every async request with status and, on failure, the exact error code. Generated files land in Serverless › Artifacts (storage & retention).

Async failures are classified precisely from the GPU worker, and surface as error_code / error_message on the request (and in the request.failed webhook):

error_codeMeaningWhat to do
vram_exceededThe job exceeded the GPU’s memorySmaller size/steps, a more quantized model, or raise your price cap so a larger GPU can be assigned
model_timeoutThe model didn’t respond in time (images: 5 min, videos: 30 min)Retry; if persistent, reduce job size
pod_crashThe worker ran out of host memoryContact support
storage_upload_failedResult couldn’t be written to your output bucketCheck the storage credential under Settings → Integrations

Failed and canceled requests don’t add any charge — billing is per GPU-hour of your deployment, not per request.

Terminal window
curl -X POST https://<your-deployment>.inference.meshive.ai/v1/requests/req_.../cancel \
-H "Authorization: Bearer $MESHIVE_API_KEY"
  • Only queued requests can be canceledrunning means the GPU is already working; you get 409 with the current status.
  • A successful cancel fires request.canceled to your webhooks.