The Task Lifecycle
Submit a Request
Send your data (text, audio, video) to a creation endpoint. The API immediately returns a
task_id.Poll for Status
Use the
task_id to check progress. The task moves through states: PENDING β SUCCESS (or ERROR).Task vs Run
| Concept | Description | ID |
|---|---|---|
| Task | A job submitted for processing | task_id |
| Run | The completed result of a task | run_id |
Task Status Types
| Status | Meaning | Action |
|---|---|---|
PENDING | Processing in progress | Continue polling |
SUCCESS | Completed successfully | Retrieve result using run_id |
ERROR | Processing failed | Check error message, retry |
TIMEOUT | Processing exceeded time limit | Break into smaller requests |
PAYMENT_REQUIRED | Insufficient credits | Add credits to account |
Example: Complete Workflow
Hereβs a complete example showing the task pattern for text-to-speech:Polling Best Practices
Use appropriate intervals
Use appropriate intervals
Start with 2-5 second intervals. Shorter tasks (TTS) complete faster than longer ones (dubbing).
Implement exponential backoff
Implement exponential backoff
For longer tasks, increase the polling interval over time to reduce API calls.
Set a maximum timeout
Set a maximum timeout
Donβt poll forever. Set a maximum wait time and handle timeouts gracefully.
Handle all status types
Handle all status types
Always handle
ERROR, TIMEOUT, and PAYMENT_REQUIRED statuses in your code.Bulk Operations
For processing multiple items, use the bulk fetch endpoints:APIs Using This Pattern
Most CAMB.AI APIs follow the task pattern:| API | Create | Status | Result |
|---|---|---|---|
| Text-to-Speech | POST /tts | GET /tts/{task_id} | GET /tts-result/{run_id} |
| Translation | POST /translation | GET /translation/{task_id} | GET /translation-result/{run_id} |
| Transcription | POST /transcription | GET /transcription/{task_id} | GET /transcription-result/{run_id} |
| Dubbing | POST /end-to-end-dubbing | GET /end-to-end-dubbing/{task_id} | GET /dubbed-run-info/{run_id} |
| Stories | POST /create-story | GET /story/{task_id} | GET /story-run/{run_id} |
Streaming Alternative
For real-time applications, some APIs offer streaming endpoints that return data immediately without the task pattern:POST /tts-stream- Streaming text-to-speechPOST /translation-stream- Streaming translation