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.Documentation Index
Fetch the complete documentation index at: https://docs.xhuoapi.ai/llms.txt
Use this file to discover all available pages before exploring further.
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.callback_url does not disable manual polling.
Creating a task
A POST returns200 synchronously with a task_id:
- 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
Client polling
General pattern (using Midjourney/midjourney/tasks as an example):
/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
Addcallback_url to the request body:
Webhook receiver requirements
- The endpoint must be publicly reachable, HTTPS recommended
- Return
2xxquickly; 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_idagainst tasks your service previously created
- Include an unguessable token segment in your
Minimal Flask example
Choosing between them
| Aspect | Polling | Webhook |
|---|---|---|
| Setup | Trivial | Requires a public HTTPS endpoint |
| Latency | Bound by poll interval | Lowest (pushed immediately) |
| Request count | Each poll is a request | 0 (you only receive) |
| Crash recovery | Restart and resume | You must handle “missed callbacks” |
| Best for | Scripts, local tools, debugging | Production services, batch jobs |
Failure handling
Either path can deliver a failed result. Theerror.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

