99import httpx
1010
1111from ..types import prediction_list_params , prediction_create_params
12- from .._types import NOT_GIVEN , Body , Query , Headers , NoneType , NotGiven
12+ from .._types import NOT_GIVEN , Body , Query , Headers , NotGiven
1313from .._utils import maybe_transform , strip_not_given , async_maybe_transform
1414from .._compat import cached_property
1515from .._resource import SyncAPIResource , AsyncAPIResource
@@ -317,9 +317,32 @@ def cancel(
317317 extra_query : Query | None = None ,
318318 extra_body : Body | None = None ,
319319 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
320- ) -> None :
320+ ) -> Prediction :
321321 """
322- Cancel a prediction
322+ Cancel a prediction that is currently running.
323+
324+ Example cURL request that creates a prediction and then cancels it:
325+
326+ ```console
327+ # First, create a prediction
328+ PREDICTION_ID=$(curl -s -X POST \\
329+ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
330+ -H "Content-Type: application/json" \\
331+ -d '{
332+ "input": {
333+ "prompt": "a video that may take a while to generate"
334+ }
335+ }' \\
336+ https://api.replicate.com/v1/models/minimax/video-01/predictions | jq -r '.id')
337+
338+ # Echo the prediction ID
339+ echo "Created prediction with ID: $PREDICTION_ID"
340+
341+ # Cancel the prediction
342+ curl -s -X POST \\
343+ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
344+ https://api.replicate.com/v1/predictions/$PREDICTION_ID/cancel
345+ ```
323346
324347 Args:
325348 extra_headers: Send extra headers
@@ -332,13 +355,12 @@ def cancel(
332355 """
333356 if not prediction_id :
334357 raise ValueError (f"Expected a non-empty value for `prediction_id` but received { prediction_id !r} " )
335- extra_headers = {"Accept" : "*/*" , ** (extra_headers or {})}
336358 return self ._post (
337359 f"/predictions/{ prediction_id } /cancel" ,
338360 options = make_request_options (
339361 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
340362 ),
341- cast_to = NoneType ,
363+ cast_to = Prediction ,
342364 )
343365
344366 def get (
@@ -735,9 +757,32 @@ async def cancel(
735757 extra_query : Query | None = None ,
736758 extra_body : Body | None = None ,
737759 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
738- ) -> None :
760+ ) -> Prediction :
739761 """
740- Cancel a prediction
762+ Cancel a prediction that is currently running.
763+
764+ Example cURL request that creates a prediction and then cancels it:
765+
766+ ```console
767+ # First, create a prediction
768+ PREDICTION_ID=$(curl -s -X POST \\
769+ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
770+ -H "Content-Type: application/json" \\
771+ -d '{
772+ "input": {
773+ "prompt": "a video that may take a while to generate"
774+ }
775+ }' \\
776+ https://api.replicate.com/v1/models/minimax/video-01/predictions | jq -r '.id')
777+
778+ # Echo the prediction ID
779+ echo "Created prediction with ID: $PREDICTION_ID"
780+
781+ # Cancel the prediction
782+ curl -s -X POST \\
783+ -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\
784+ https://api.replicate.com/v1/predictions/$PREDICTION_ID/cancel
785+ ```
741786
742787 Args:
743788 extra_headers: Send extra headers
@@ -750,13 +795,12 @@ async def cancel(
750795 """
751796 if not prediction_id :
752797 raise ValueError (f"Expected a non-empty value for `prediction_id` but received { prediction_id !r} " )
753- extra_headers = {"Accept" : "*/*" , ** (extra_headers or {})}
754798 return await self ._post (
755799 f"/predictions/{ prediction_id } /cancel" ,
756800 options = make_request_options (
757801 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
758802 ),
759- cast_to = NoneType ,
803+ cast_to = Prediction ,
760804 )
761805
762806 async def get (
0 commit comments