predictions
Predictions module.
predictions module
Predictions module.
class ErrorSource(StrEnum)
Bases: StrEnum
Enumeration of possible error sources.
internal = 'internal'
external = 'external'
class Status(StrEnum)
Bases: StrEnum
Enumeration of possible prediction statuses.
pending = 'pending'
started = 'started'
failed = 'failed'
succeeded = 'succeeded'
class TaskError
Bases: TypedDict
Represents an error that occurred during a prediction.
source : ErrorSource
message : str
detail : list[JsonValue] | Mapping[str, JsonValue] | str | bool | int | float | None
class PredictionModel
Bases: TypedDict
Represents the prediction model.
owner : str
Username of the model’s owner.
name : str
Name of the model.
version_number : int
Version number of the model.
class Prediction
Bases: TypedDict
Represents a prediction.
url : str
URL to access the prediction resource.
id : str
Unique identifier for the prediction.
created_at : str
Timestamp when the prediction was created.
status : Status
Current status of the prediction.
updated_at : str
Timestamp of the last update to the prediction.
setup_time : str | None
Time taken to set up the prediction environment.
execution_time : str | None
Time taken to execute the prediction.
model : PredictionModel
The model of the prediction.
class PredictionWithIO
Bases: Prediction
Represents a prediction with I/O details.
input : list[JsonValue] | Mapping[str, JsonValue] | str | bool | int | float | None
Input data provided for the prediction.
output : list[JsonValue] | Mapping[str, JsonValue] | str | bool | int | float | None
Output generated by the prediction.
logs : list[str] | None
Logs generated during prediction execution.
setup_logs : list[str] | None
Logs generated during setup.
error : TaskError | None
Error details if the prediction failed.
url : str
id : str
created_at : str
status : Status
updated_at : str
setup_time : str | None
execution_time : str | None
model : PredictionModel
class Webhook
Bases: TypedDict
Represents webhook details.
url : str
HTTP URL to POST updates to.
secret : NotRequired[str | None]
Secret to generate the signature for the webhook.
class CreatePredictionParams
Bases: TypedDict
Prediction creation params.
input : list[JsonValue] | Mapping[str, JsonValue] | str | bool | int | float | None
Input data provided for the prediction.
webhook : NotRequired[Webhook | None]
Details about the webhook to post prediction updates to.
validate_input : NotRequired[bool]
Enable input validation against the schema before processing.
class WaitOptions(poll_interval=1.0, on_poll=None)
Bases: _BaseWaitOptions
Options for customizing wait behaviour.
- Parameters:
- poll_interval (float)
- on_poll (Callable [ [PredictionWithIO ] , None ] | None)
on_poll : Callable[[PredictionWithIO], None] | None = None
Optional callback that receives the latest prediction after each poll.
class AsyncWaitOptions(poll_interval=1.0, on_poll=None)
Bases: _BaseWaitOptions
Options for customizing asynchronous wait behaviour.
- Parameters:
- poll_interval (float)
- on_poll (Callable [ [PredictionWithIO ] , Awaitable *[*None ] ] | None)
on_poll : Callable[[PredictionWithIO], Awaitable[None]] | None = None
Optional callback that receives the latest prediction after each poll.
DEFAULT_WAIT_OPTIONS = WaitOptions(poll_interval=1.0, on_poll=None)
Default wait options.
DEFAULT_ASYNC_WAIT_OPTIONS = AsyncWaitOptions(poll_interval=1.0, on_poll=None)
Default async wait options.
class Predictions(api)
Bases: Resource
Initializes the Resource with an API instance.
- Parameters: api (API) – An instance of the API class.
get(prediction_id)
Get a prediction by id.
- Parameters: prediction_id (str) – The unique identifier of the prediction.
- Returns: The prediction object.
- Return type: PredictionWithIO
async async_get(prediction_id)
Get a prediction by id.
- Parameters: prediction_id (str) – The unique identifier of the prediction.
- Returns: The prediction object.
- Return type: PredictionWithIO
list(pagination_options=None)
List predictions.
- Parameters: pagination_options (Optional [PaginationOptions ]) – Optional settings to control pagination behavior.
- Returns: Paginated response containing predictions : and navigation metadata.
- Return type: PaginatedResponse[Prediction]
async async_list(pagination_options=None)
List predictions.
- Parameters: pagination_options (Optional [PaginationOptions ]) – Optional settings to control pagination behavior.
- Returns: Paginated response containing predictions : and navigation metadata.
- Return type: PaginatedResponse[Prediction]
create(params, model, wait=False, wait_options=WaitOptions(poll_interval=1.0, on_poll=None))
Create a prediction.
- Parameters:
- model (str) – The model reference in either owner/name or owner/name:version-number format (for example: deepseek-ai/deepseek-r1 or deepseek-ai/deepseek-r1:1).
- params (CreatePredictionParams) – Prediction creation params.
- wait (bool) – If True, waits until the prediction reaches a terminal state. If False, returns the prediction immediately. Defaults to False.
- wait_options (WaitOptions) – Options for customizing wait behavior. If not provided, default options are used.
- Returns: The new prediction.
- Return type: PredictionWithIO
- Raises: ValueError – When the provided model reference is not in owner/name or owner/name:version-number format.
async async_create(params, model, wait=False, wait_options=AsyncWaitOptions(poll_interval=1.0, on_poll=None))
Create a prediction.
- Parameters:
- model (str) – The model reference in either owner/name or owner/name:version-number format (for example: deepseek-ai/deepseek-r1 or deepseek-ai/deepseek-r1:1).
- params (CreatePredictionParams) – Prediction creation params.
- wait (bool) – If True, waits until the prediction reaches a terminal state. If False, returns the prediction immediately. Defaults to False.
- wait_options (AsyncWaitOptions) – Options for customizing wait behavior. If not provided, default options are used.
- Returns: The new prediction.
- Return type: PredictionWithIO
- Raises: ValueError – When the provided model reference is not in owner/name or owner/name:version-number format.
wait(predictionID, options=WaitOptions(poll_interval=1.0, on_poll=None))
Wait for a prediction to complete.
This method uses short polling to check the prediction status at regular intervals until it reaches a terminal state. It blocks execution and waits until the prediction has finished processing.
- Parameters:
- predictionID (str) – Unique identifier of the prediction.
- options (WaitOptions) – Options for customizing wait behavior. If not provided, default options are used.
- Returns: Prediction after completion.
- Return type: PredictionWithIO
async async_wait(predictionID, options=AsyncWaitOptions(poll_interval=1.0, on_poll=None))
Wait for a prediction to complete.
This method uses short polling to check the prediction status at regular intervals until it reaches a terminal state. It blocks execution and waits until the prediction has finished processing.
- Parameters:
- predictionID (str) – Unique identifier of the prediction.
- options (AsyncWaitOptions) – Options for customizing wait behavior. If not provided, default options are used.
- Returns: Prediction after completion.
- Return type: PredictionWithIO