The Pattern
Step 1: Submit a Task
Send aPOST request to create a generation task:
taskId. The actual generation happens in the background.
Step 2: Get Results
You have two options to receive results:Option A: Polling (Recommended for Getting Started)
Periodically check the task status:Option B: Webhooks (Recommended for Production)
Provide acallback_url when submitting:
POST the result to your URL when the task completes.
See Webhooks for implementation details.
Task States
| State | Description |
|---|---|
pending | Task queued, waiting to start |
processing | Task is being processed |
success | Task completed successfully |
failed | Task failed (check failMsg) |
Polling Best Practices
- Start with 3-5 second intervals for most tasks
- Use exponential backoff for long-running tasks (videos)
- Set a maximum timeout (e.g., 5 minutes)
- Handle failures gracefully with retry logic
When to Use Each Approach
| Approach | Best For |
|---|---|
| Polling | Simple integrations, client-side apps, testing |
| Webhooks | Production servers, real-time apps, high volume |
Next Steps
API Reference
Detailed endpoint documentation
Polling vs Webhooks
Deep dive into both approaches