Predictions
A guide on how to work with predictions using the WriftAI Python client
This section demonstrates common prediction operations you can perform with the WriftAI Python client. These examples are not exhaustive — check the client reference for all options.
Get a Prediction by ID
prediction = wriftai.predictions.get("your-prediction-id")Cancel a Prediction by ID
wriftai.predictions.cancel("your-prediction-id")Create a Prediction
With the latest version of a model
prediction = wriftai.predictions.create(
model="deepseek-ai/deepseek-r1",
input={
"prompt": "Summarize quantum computing.",
},
)With a specific version of a model
prediction = wriftai.predictions.create(
model="deepseek-ai/deepseek-r1:2",
input={
"prompt": "Summarize quantum computing.",
},
)With a webhook for prediction updates
prediction = wriftai.predictions.create(
model="deepseek-ai/deepseek-r1",
input={
"prompt": "Summarize quantum computing.",
},
webhook={
"url": "https://example.com/webhooks/wriftai",
"secret": "top-secret", # This is optional
},
)With file inputs
File inputs are automatically uploaded when you create a prediction. Wrap bytes,
file paths, or file-like objects in File, and no need to call wriftai.files.upload() separately.
Files can be nested anywhere in input, including inside lists, dicts, or combinations of
both, and you can include as many as you need. They'll all be uploaded concurrently.
With file paths:
from pathlib import Path
from wriftai import File
prediction = wriftai.predictions.create(
model="pyannote/speaker-diarization-community-1",
input={"audio": File(Path("/path/to/audio.wav"))},
)With raw bytes:
from wriftai import File
prediction = wriftai.predictions.create(
model="pyannote/speaker-diarization-community-1",
input={"audio": File(content=b"some audio bytes", mime_type="audio/wav")},
)With file-like objects:
from wriftai import File
with open("audio.wav", "rb") as f:
prediction = wriftai.predictions.create(
model="pyannote/speaker-diarization-community-1",
input={"audio": File(f)},
)For more details on working with files, see the Files guide.
With input validation enabled
Enable early input validation against the model’s input schema before a prediction is created. This catches invalid inputs upfront and prevents unnecessary model execution and cost.
prediction = wriftai.predictions.create(
model="deepseek-ai/deepseek-r1",
input={
"prompt": "Summarize quantum computing.",
},
validate_input=True,
)Create and wait for completion
prediction = wriftai.predictions.create(
model="deepseek-ai/deepseek-r1",
input={
"prompt": "Summarize quantum computing.",
},
wait=True,
)Create and wait with custom options
from wriftai.predictions import PredictionWithIO, WaitOptions
def on_poll(prediction: PredictionWithIO) -> None:
# your custom logic
return
prediction = wriftai.predictions.create(
model="deepseek-ai/deepseek-r1",
input={
"prompt": "Summarize quantum computing.",
},
wait=True,
wait_options=WaitOptions(poll_interval=500, on_poll=on_poll),
)Wait for an existing prediction to complete
prediction = wriftai.predictions.wait("your-prediction-id")List Predictions
predictions = wriftai.predictions.list()Filter by status
from wriftai.predictions import PredictionPaginationOptions, Status
predictions = wriftai.predictions.list(
PredictionPaginationOptions(
statuses=[Status.cancelled, Status.failed],
)
)