Predictions API
Theclient.predictions
component provides methods to retrieve, list, and manage predictions across all content types. This is the central hub for tracking the status of all processing jobs in the platform.
Quick Examples
Get a Prediction
List Predictions
Wait for Completion
Core Operations
Retrieving Predictions
Get details about a specific prediction:Listing Predictions
List predictions you’ve created (with pagination):Waiting for Completion
Wait for long-running predictions to complete:wait()
method will raise a TimeoutError
if the prediction doesn’t complete within the specified timeout.
Prediction Statuses
Predictions can have the following statuses:Status | Description |
---|---|
enqueued | The prediction is waiting to be processed |
pending | The prediction is preparing to start |
running | The prediction is actively being processed |
completed | The prediction has completed successfully |
failed | The prediction encountered an error |
paused | The prediction has been paused |
Media-Specific APIs
The basePredictions
class is extended by specialized prediction classes for different media types:
Image Predictions
Document, Audio, and Video Predictions
These specialized APIs follow a consistent pattern:Response Structure
ThePredictionResponse
object includes these key fields:
usage
field contains a CreditUsage
object:
Auto-casting Responses
All specialized prediction classes support auto-casting responses to their appropriate schema types:Common Patterns
Process and Wait
A common pattern is to start a prediction and wait for it to complete:Batch Processing
For batch operations, use the batch parameter and track multiple predictions:Error Handling
Implement robust error handling:Best Practices
Efficient Polling
Use appropriate intervals when waiting for predictions:Using Appropriate Timeouts
Set timeouts based on the expected processing time:Progress Reporting with tqdm
For better user experience, use thetqdm
library for progress reporting: