Skip to main content
LLM chat APIs are synchronous — one request returns the full result. But image, video, and music generation takes seconds to minutes, so they run as async tasks.

Polling vs Webhook

Client polling

Create the task, then GET its status periodically until done. Simple — suits scripts, CLIs, notebooks, tests.

Webhook callback

Pass callback_url at submit time; we POST the result when done. Fewer requests — best for production services.
You can combine both — passing callback_url does not disable manual polling.

Creating a task

A POST returns 200 synchronously with a task_id:
The exact sync fields vary by endpoint:
  • Midjourney / Suno style endpoints (which can wait for the result): return the complete result inline
  • Veo / Sora style heavy video endpoints: return only task_id; the result is delivered later via polling or webhook
Refer to each API’s reference page for specifics.

Client polling

General pattern (using Midjourney /midjourney/tasks as an example):
Note: /midjourney/tasks retrieve returns {id, request, response, created_at, started_at, finished_at, ...} — there is no status field. Check for the presence of finished_at or a non-empty response to detect completion. Other services’ task-query endpoints use slightly different field names; consult each API’s docs. Use a reasonable polling cadence with backoff to avoid hitting too_many_requests (429). Prefer estimates based on each endpoint’s typical processing time documented in its API reference.

Webhook callbacks

Add callback_url to the request body:
When the task finishes, we POST the result to that URL. The payload looks like: Success:
Failure:

Webhook receiver requirements

  • The endpoint must be publicly reachable, HTTPS recommended
  • Return 2xx quickly; defer your business processing to a background queue
  • Callbacks currently carry no signature header. To guard against spoofing:
    • Include an unguessable token segment in your callback_url
    • Or verify the incoming task_id against tasks your service previously created

Minimal Flask example

Choosing between them

Failure handling

Either path can deliver a failed result. The error.code values match the synchronous error codes — see Response format. Failed tasks are generally not billed; consult each service’s detail page for the exact policy.

Next

Response format

All error codes and HTTP statuses

Gateway & auth

Tokens, endpoints, security