POST /predictions
Makes a single prediction.Request
A JSON object with the same keys as the arguments to the
predict() function. Any File or Path inputs are passed as URLs.URL to receive webhook notifications about prediction status updates. See Webhooks for details.
Array of event types to trigger webhook notifications. Valid values:
start, output, logs, completed. Defaults to all events if not specified.Base URL to upload output files to instead of returning them as base64-encoded data URLs. See File Uploads for details.
Response (200 OK)
Synchronous prediction completed successfully.Either
succeeded or failed.The return value of the
predict() function. Type depends on your model’s output schema.If
status is failed, contains the error message.An object containing prediction metrics.
Response (202 Accepted)
Asynchronous prediction started (whenPrefer: respond-async header is set).
Prediction status. Value will be
starting when the prediction is first created.PUT /predictions/<prediction_id>
Makes a single prediction. This is the idempotent version of thePOST /predictions endpoint.
If a client calls this endpoint more than once with the same ID (for example, due to a network interruption) while the prediction is still running, no new prediction is created. Instead, the client receives a 202 Accepted response with the initial state of the prediction.
Generating Prediction IDs
Clients are responsible for providing unique prediction IDs. We recommend generating a UUIDv4 or UUIDv7, base32-encoding that value, and removing padding characters (==). This produces a random identifier that is 26 ASCII characters long.
Request
Unique identifier for the prediction. Must be provided by the client.
A JSON object with the same keys as the arguments to the
predict() function. Any File or Path inputs are passed as URLs.URL to receive webhook notifications about prediction status updates. See Webhooks for details.
Array of event types to trigger webhook notifications. Valid values:
start, output, logs, completed. Defaults to all events if not specified.Base URL to upload output files to instead of returning them as base64-encoded data URLs. See File Uploads for details.
Response (200 OK)
Synchronous prediction completed successfully.Either
succeeded or failed.The return value of the
predict() function. Type depends on your model’s output schema.If
status is failed, contains the error message.Response (202 Accepted)
Asynchronous prediction started (whenPrefer: respond-async header is set).
The prediction ID provided in the request.
Prediction status. Value will be
starting when the prediction is first created.POST /predictions/<prediction_id>/cancel
Cancels an asynchronous prediction. A client can cancel an asynchronous prediction by making aPOST /predictions/<prediction_id>/cancel request using the prediction id provided when the prediction was created.
Request
The ID of the prediction to cancel.
Response
200 OK - If a prediction exists with the providedid.
404 Not Found - If no prediction exists with the provided id.
Handling Cancellation in Your Model
When a prediction is canceled, Cog raisesCancelationException in sync predictors (or asyncio.CancelledError in async predictors). This exception may be caught by the model to perform necessary cleanup.
The cleanup should be brief, ideally completing within a few seconds. After cleanup, the exception must be re-raised using a bare raise statement. Failure to re-raise the exception may result in the termination of the container.