From 82409e2c46d8ece084fbaabef4a90013ec4ac322 Mon Sep 17 00:00:00 2001 From: Rajas Bansal Date: Wed, 13 Aug 2025 10:01:45 -0700 Subject: [PATCH 1/2] Add API to cancel a batch --- src/together/resources/batch.py | 16 ++++++++++++++++ src/together/types/batch.py | 1 + 2 files changed, 17 insertions(+) diff --git a/src/together/resources/batch.py b/src/together/resources/batch.py index e9f30653..f148c0e1 100644 --- a/src/together/resources/batch.py +++ b/src/together/resources/batch.py @@ -72,6 +72,22 @@ def list_batches(self) -> List[BatchJob]: jobs = response.data or [] return [BatchJob(**job) for job in jobs] + def cancel_batch(self, batch_job_id: str) -> BatchJob: + requestor = api_requestor.APIRequestor( + client=self._client, + ) + + response, _, _ = requestor.request( + options=TogetherRequest( + method="POST", + url=f"batches/{batch_job_id}/cancel", + ), + stream=False, + ) + + assert isinstance(response, TogetherResponse) + return BatchJob(**response.data) + class AsyncBatches: def __init__(self, client: TogetherClient) -> None: diff --git a/src/together/types/batch.py b/src/together/types/batch.py index 3bd5ead5..aaec0e99 100644 --- a/src/together/types/batch.py +++ b/src/together/types/batch.py @@ -20,6 +20,7 @@ class BatchJobStatus(str, Enum): FAILED = "FAILED" EXPIRED = "EXPIRED" CANCELLED = "CANCELLED" + CANCELING = "CANCELING" class BatchEndpoint(str, Enum): From 305bdc7062db7e6436a92ce5047651cecf05f92b Mon Sep 17 00:00:00 2001 From: Rajas Bansal Date: Thu, 14 Aug 2025 16:39:12 -0700 Subject: [PATCH 2/2] Address comments --- src/together/resources/batch.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/together/resources/batch.py b/src/together/resources/batch.py index f148c0e1..ab8a9009 100644 --- a/src/together/resources/batch.py +++ b/src/together/resources/batch.py @@ -85,7 +85,6 @@ def cancel_batch(self, batch_job_id: str) -> BatchJob: stream=False, ) - assert isinstance(response, TogetherResponse) return BatchJob(**response.data) @@ -149,3 +148,18 @@ async def list_batches(self) -> List[BatchJob]: assert isinstance(response, TogetherResponse) jobs = response.data or [] return [BatchJob(**job) for job in jobs] + + async def cancel_batch(self, batch_job_id: str) -> BatchJob: + requestor = api_requestor.APIRequestor( + client=self._client, + ) + + response, _, _ = await requestor.arequest( + options=TogetherRequest( + method="POST", + url=f"batches/{batch_job_id}/cancel", + ), + stream=False, + ) + + return BatchJob(**response.data)