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
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
Next Steps
Generation API Overview
Understand the async API pattern for image, video, and audio models
Generate Task
Submit a generation task and receive a task ID
Polling vs Webhooks
Deep dive into both approaches