From 4a2a94d2ef6cee99cb87fad162912e06004356d7 Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Thu, 19 Dec 2024 23:06:44 +0000 Subject: [PATCH] feat(api): add message batch delete endpoint --- .stats.yml | 4 +- api.md | 4 + .../resources/beta/messages/batches.py | 117 ++++++++++++++++++ src/anthropic/resources/messages/batches.py | 89 +++++++++++++ src/anthropic/types/beta/messages/__init__.py | 1 + .../messages/beta_deleted_message_batch.py | 18 +++ src/anthropic/types/messages/__init__.py | 1 + .../types/messages/deleted_message_batch.py | 18 +++ .../beta/messages/test_batches.py | 97 ++++++++++++++- tests/api_resources/messages/test_batches.py | 78 +++++++++++- 10 files changed, 423 insertions(+), 4 deletions(-) create mode 100644 src/anthropic/types/beta/messages/beta_deleted_message_batch.py create mode 100644 src/anthropic/types/messages/deleted_message_batch.py diff --git a/.stats.yml b/.stats.yml index 14c789bf..239e17b7 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 19 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-9563716c7b08b8936ba450ad05005d12cf5ca3b9a37fab8126ed372e422d6de6.yml +configured_endpoints: 21 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fd67aea6883f1ee9e46f31a42d3940f0acb1749e787055bd9b9f278b20fa53ec.yml diff --git a/api.md b/api.md index 773b5eb6..c520f8b4 100644 --- a/api.md +++ b/api.md @@ -75,6 +75,7 @@ Types: ```python from anthropic.types.messages import ( + DeletedMessageBatch, MessageBatch, MessageBatchCanceledResult, MessageBatchErroredResult, @@ -91,6 +92,7 @@ Methods: - client.messages.batches.create(\*\*params) -> MessageBatch - client.messages.batches.retrieve(message_batch_id) -> MessageBatch - client.messages.batches.list(\*\*params) -> SyncPage[MessageBatch] +- client.messages.batches.delete(message_batch_id) -> DeletedMessageBatch - client.messages.batches.cancel(message_batch_id) -> MessageBatch - client.messages.batches.results(message_batch_id) -> BinaryAPIResponse @@ -196,6 +198,7 @@ Types: ```python from anthropic.types.beta.messages import ( + BetaDeletedMessageBatch, BetaMessageBatch, BetaMessageBatchCanceledResult, BetaMessageBatchErroredResult, @@ -212,5 +215,6 @@ Methods: - client.beta.messages.batches.create(\*\*params) -> BetaMessageBatch - client.beta.messages.batches.retrieve(message_batch_id) -> BetaMessageBatch - client.beta.messages.batches.list(\*\*params) -> SyncPage[BetaMessageBatch] +- client.beta.messages.batches.delete(message_batch_id) -> BetaDeletedMessageBatch - client.beta.messages.batches.cancel(message_batch_id) -> BetaMessageBatch - client.beta.messages.batches.results(message_batch_id) -> BinaryAPIResponse diff --git a/src/anthropic/resources/beta/messages/batches.py b/src/anthropic/resources/beta/messages/batches.py index e0268bb5..8cd2803b 100644 --- a/src/anthropic/resources/beta/messages/batches.py +++ b/src/anthropic/resources/beta/messages/batches.py @@ -34,6 +34,7 @@ from ....types.beta.messages import batch_list_params, batch_create_params from ....types.anthropic_beta_param import AnthropicBetaParam from ....types.beta.messages.beta_message_batch import BetaMessageBatch +from ....types.beta.messages.beta_deleted_message_batch import BetaDeletedMessageBatch __all__ = ["Batches", "AsyncBatches"] @@ -234,6 +235,58 @@ def list( model=BetaMessageBatch, ) + def delete( + self, + message_batch_id: str, + *, + betas: List[AnthropicBetaParam] | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> BetaDeletedMessageBatch: + """This endpoint is idempotent and can be used to poll for Message Batch + completion. + + To access the results of a Message Batch, make a request to the + `results_url` field in the response. + + Args: + message_batch_id: ID of the Message Batch. + + betas: Optional header to specify the beta version(s) you want to use. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not message_batch_id: + raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") + extra_headers = { + **strip_not_given( + { + "anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"])) + if is_given(betas) + else NOT_GIVEN + } + ), + **(extra_headers or {}), + } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} + return self._delete( + f"/v1/messages/batches/{message_batch_id}?beta=true", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=BetaDeletedMessageBatch, + ) + def cancel( self, message_batch_id: str, @@ -543,6 +596,58 @@ def list( model=BetaMessageBatch, ) + async def delete( + self, + message_batch_id: str, + *, + betas: List[AnthropicBetaParam] | NotGiven = NOT_GIVEN, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> BetaDeletedMessageBatch: + """This endpoint is idempotent and can be used to poll for Message Batch + completion. + + To access the results of a Message Batch, make a request to the + `results_url` field in the response. + + Args: + message_batch_id: ID of the Message Batch. + + betas: Optional header to specify the beta version(s) you want to use. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not message_batch_id: + raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") + extra_headers = { + **strip_not_given( + { + "anthropic-beta": ",".join(chain((str(e) for e in betas), ["message-batches-2024-09-24"])) + if is_given(betas) + else NOT_GIVEN + } + ), + **(extra_headers or {}), + } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} + return await self._delete( + f"/v1/messages/batches/{message_batch_id}?beta=true", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=BetaDeletedMessageBatch, + ) + async def cancel( self, message_batch_id: str, @@ -669,6 +774,9 @@ def __init__(self, batches: Batches) -> None: self.list = _legacy_response.to_raw_response_wrapper( batches.list, ) + self.delete = _legacy_response.to_raw_response_wrapper( + batches.delete, + ) self.cancel = _legacy_response.to_raw_response_wrapper( batches.cancel, ) @@ -691,6 +799,9 @@ def __init__(self, batches: AsyncBatches) -> None: self.list = _legacy_response.async_to_raw_response_wrapper( batches.list, ) + self.delete = _legacy_response.async_to_raw_response_wrapper( + batches.delete, + ) self.cancel = _legacy_response.async_to_raw_response_wrapper( batches.cancel, ) @@ -713,6 +824,9 @@ def __init__(self, batches: Batches) -> None: self.list = to_streamed_response_wrapper( batches.list, ) + self.delete = to_streamed_response_wrapper( + batches.delete, + ) self.cancel = to_streamed_response_wrapper( batches.cancel, ) @@ -735,6 +849,9 @@ def __init__(self, batches: AsyncBatches) -> None: self.list = async_to_streamed_response_wrapper( batches.list, ) + self.delete = async_to_streamed_response_wrapper( + batches.delete, + ) self.cancel = async_to_streamed_response_wrapper( batches.cancel, ) diff --git a/src/anthropic/resources/messages/batches.py b/src/anthropic/resources/messages/batches.py index 8e4add91..48ee8f38 100644 --- a/src/anthropic/resources/messages/batches.py +++ b/src/anthropic/resources/messages/batches.py @@ -30,6 +30,7 @@ from ..._base_client import AsyncPaginator, make_request_options from ...types.messages import batch_list_params, batch_create_params from ...types.messages.message_batch import MessageBatch +from ...types.messages.deleted_message_batch import DeletedMessageBatch __all__ = ["Batches", "AsyncBatches"] @@ -188,6 +189,44 @@ def list( model=MessageBatch, ) + def delete( + self, + message_batch_id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> DeletedMessageBatch: + """This endpoint is idempotent and can be used to poll for Message Batch + completion. + + To access the results of a Message Batch, make a request to the + `results_url` field in the response. + + Args: + message_batch_id: ID of the Message Batch. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not message_batch_id: + raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") + return self._delete( + f"/v1/messages/batches/{message_batch_id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=DeletedMessageBatch, + ) + def cancel( self, message_batch_id: str, @@ -427,6 +466,44 @@ def list( model=MessageBatch, ) + async def delete( + self, + message_batch_id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> DeletedMessageBatch: + """This endpoint is idempotent and can be used to poll for Message Batch + completion. + + To access the results of a Message Batch, make a request to the + `results_url` field in the response. + + Args: + message_batch_id: ID of the Message Batch. + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not message_batch_id: + raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") + return await self._delete( + f"/v1/messages/batches/{message_batch_id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=DeletedMessageBatch, + ) + async def cancel( self, message_batch_id: str, @@ -525,6 +602,9 @@ def __init__(self, batches: Batches) -> None: self.list = _legacy_response.to_raw_response_wrapper( batches.list, ) + self.delete = _legacy_response.to_raw_response_wrapper( + batches.delete, + ) self.cancel = _legacy_response.to_raw_response_wrapper( batches.cancel, ) @@ -547,6 +627,9 @@ def __init__(self, batches: AsyncBatches) -> None: self.list = _legacy_response.async_to_raw_response_wrapper( batches.list, ) + self.delete = _legacy_response.async_to_raw_response_wrapper( + batches.delete, + ) self.cancel = _legacy_response.async_to_raw_response_wrapper( batches.cancel, ) @@ -569,6 +652,9 @@ def __init__(self, batches: Batches) -> None: self.list = to_streamed_response_wrapper( batches.list, ) + self.delete = to_streamed_response_wrapper( + batches.delete, + ) self.cancel = to_streamed_response_wrapper( batches.cancel, ) @@ -591,6 +677,9 @@ def __init__(self, batches: AsyncBatches) -> None: self.list = async_to_streamed_response_wrapper( batches.list, ) + self.delete = async_to_streamed_response_wrapper( + batches.delete, + ) self.cancel = async_to_streamed_response_wrapper( batches.cancel, ) diff --git a/src/anthropic/types/beta/messages/__init__.py b/src/anthropic/types/beta/messages/__init__.py index 6d6b1e10..fef14dd1 100644 --- a/src/anthropic/types/beta/messages/__init__.py +++ b/src/anthropic/types/beta/messages/__init__.py @@ -6,6 +6,7 @@ from .beta_message_batch import BetaMessageBatch as BetaMessageBatch from .batch_create_params import BatchCreateParams as BatchCreateParams from .beta_message_batch_result import BetaMessageBatchResult as BetaMessageBatchResult +from .beta_deleted_message_batch import BetaDeletedMessageBatch as BetaDeletedMessageBatch from .beta_message_batch_errored_result import BetaMessageBatchErroredResult as BetaMessageBatchErroredResult from .beta_message_batch_expired_result import BetaMessageBatchExpiredResult as BetaMessageBatchExpiredResult from .beta_message_batch_request_counts import BetaMessageBatchRequestCounts as BetaMessageBatchRequestCounts diff --git a/src/anthropic/types/beta/messages/beta_deleted_message_batch.py b/src/anthropic/types/beta/messages/beta_deleted_message_batch.py new file mode 100644 index 00000000..f7dd1d52 --- /dev/null +++ b/src/anthropic/types/beta/messages/beta_deleted_message_batch.py @@ -0,0 +1,18 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing_extensions import Literal + +from ...._models import BaseModel + +__all__ = ["BetaDeletedMessageBatch"] + + +class BetaDeletedMessageBatch(BaseModel): + id: str + """ID of the Message Batch.""" + + type: Literal["message_batch_deleted"] + """Deleted object type. + + For Message Batches, this is always `"message_batch_deleted"`. + """ diff --git a/src/anthropic/types/messages/__init__.py b/src/anthropic/types/messages/__init__.py index c316f0ec..25d311da 100644 --- a/src/anthropic/types/messages/__init__.py +++ b/src/anthropic/types/messages/__init__.py @@ -6,6 +6,7 @@ from .batch_list_params import BatchListParams as BatchListParams from .batch_create_params import BatchCreateParams as BatchCreateParams from .message_batch_result import MessageBatchResult as MessageBatchResult +from .deleted_message_batch import DeletedMessageBatch as DeletedMessageBatch from .message_batch_errored_result import MessageBatchErroredResult as MessageBatchErroredResult from .message_batch_expired_result import MessageBatchExpiredResult as MessageBatchExpiredResult from .message_batch_request_counts import MessageBatchRequestCounts as MessageBatchRequestCounts diff --git a/src/anthropic/types/messages/deleted_message_batch.py b/src/anthropic/types/messages/deleted_message_batch.py new file mode 100644 index 00000000..7a6c321e --- /dev/null +++ b/src/anthropic/types/messages/deleted_message_batch.py @@ -0,0 +1,18 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["DeletedMessageBatch"] + + +class DeletedMessageBatch(BaseModel): + id: str + """ID of the Message Batch.""" + + type: Literal["message_batch_deleted"] + """Deleted object type. + + For Message Batches, this is always `"message_batch_deleted"`. + """ diff --git a/tests/api_resources/beta/messages/test_batches.py b/tests/api_resources/beta/messages/test_batches.py index e29e6bad..48568624 100644 --- a/tests/api_resources/beta/messages/test_batches.py +++ b/tests/api_resources/beta/messages/test_batches.py @@ -18,7 +18,10 @@ AsyncStreamedBinaryAPIResponse, ) from anthropic.pagination import SyncPage, AsyncPage -from anthropic.types.beta.messages import BetaMessageBatch +from anthropic.types.beta.messages import ( + BetaMessageBatch, + BetaDeletedMessageBatch, +) # pyright: reportDeprecated=false @@ -242,6 +245,52 @@ def test_streaming_response_list(self, client: Anthropic) -> None: assert cast(Any, response.is_closed) is True + @parametrize + def test_method_delete(self, client: Anthropic) -> None: + batch = client.beta.messages.batches.delete( + message_batch_id="message_batch_id", + ) + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + @parametrize + def test_method_delete_with_all_params(self, client: Anthropic) -> None: + batch = client.beta.messages.batches.delete( + message_batch_id="message_batch_id", + betas=["string"], + ) + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + @parametrize + def test_raw_response_delete(self, client: Anthropic) -> None: + response = client.beta.messages.batches.with_raw_response.delete( + message_batch_id="message_batch_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + batch = response.parse() + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + @parametrize + def test_streaming_response_delete(self, client: Anthropic) -> None: + with client.beta.messages.batches.with_streaming_response.delete( + message_batch_id="message_batch_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + batch = response.parse() + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_delete(self, client: Anthropic) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): + client.beta.messages.batches.with_raw_response.delete( + message_batch_id="", + ) + @parametrize def test_method_cancel(self, client: Anthropic) -> None: batch = client.beta.messages.batches.cancel( @@ -577,6 +626,52 @@ async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> No assert cast(Any, response.is_closed) is True + @parametrize + async def test_method_delete(self, async_client: AsyncAnthropic) -> None: + batch = await async_client.beta.messages.batches.delete( + message_batch_id="message_batch_id", + ) + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + @parametrize + async def test_method_delete_with_all_params(self, async_client: AsyncAnthropic) -> None: + batch = await async_client.beta.messages.batches.delete( + message_batch_id="message_batch_id", + betas=["string"], + ) + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + @parametrize + async def test_raw_response_delete(self, async_client: AsyncAnthropic) -> None: + response = await async_client.beta.messages.batches.with_raw_response.delete( + message_batch_id="message_batch_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + batch = response.parse() + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + @parametrize + async def test_streaming_response_delete(self, async_client: AsyncAnthropic) -> None: + async with async_client.beta.messages.batches.with_streaming_response.delete( + message_batch_id="message_batch_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + batch = await response.parse() + assert_matches_type(BetaDeletedMessageBatch, batch, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_delete(self, async_client: AsyncAnthropic) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): + await async_client.beta.messages.batches.with_raw_response.delete( + message_batch_id="", + ) + @parametrize async def test_method_cancel(self, async_client: AsyncAnthropic) -> None: batch = await async_client.beta.messages.batches.cancel( diff --git a/tests/api_resources/messages/test_batches.py b/tests/api_resources/messages/test_batches.py index 89ec66c8..93f45a6b 100644 --- a/tests/api_resources/messages/test_batches.py +++ b/tests/api_resources/messages/test_batches.py @@ -18,7 +18,7 @@ AsyncStreamedBinaryAPIResponse, ) from anthropic.pagination import SyncPage, AsyncPage -from anthropic.types.messages import MessageBatch +from anthropic.types.messages import MessageBatch, DeletedMessageBatch # pyright: reportDeprecated=false @@ -173,6 +173,44 @@ def test_streaming_response_list(self, client: Anthropic) -> None: assert cast(Any, response.is_closed) is True + @parametrize + def test_method_delete(self, client: Anthropic) -> None: + batch = client.messages.batches.delete( + "message_batch_id", + ) + assert_matches_type(DeletedMessageBatch, batch, path=["response"]) + + @parametrize + def test_raw_response_delete(self, client: Anthropic) -> None: + response = client.messages.batches.with_raw_response.delete( + "message_batch_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + batch = response.parse() + assert_matches_type(DeletedMessageBatch, batch, path=["response"]) + + @parametrize + def test_streaming_response_delete(self, client: Anthropic) -> None: + with client.messages.batches.with_streaming_response.delete( + "message_batch_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + batch = response.parse() + assert_matches_type(DeletedMessageBatch, batch, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_delete(self, client: Anthropic) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): + client.messages.batches.with_raw_response.delete( + "", + ) + @parametrize def test_method_cancel(self, client: Anthropic) -> None: batch = client.messages.batches.cancel( @@ -416,6 +454,44 @@ async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> No assert cast(Any, response.is_closed) is True + @parametrize + async def test_method_delete(self, async_client: AsyncAnthropic) -> None: + batch = await async_client.messages.batches.delete( + "message_batch_id", + ) + assert_matches_type(DeletedMessageBatch, batch, path=["response"]) + + @parametrize + async def test_raw_response_delete(self, async_client: AsyncAnthropic) -> None: + response = await async_client.messages.batches.with_raw_response.delete( + "message_batch_id", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + batch = response.parse() + assert_matches_type(DeletedMessageBatch, batch, path=["response"]) + + @parametrize + async def test_streaming_response_delete(self, async_client: AsyncAnthropic) -> None: + async with async_client.messages.batches.with_streaming_response.delete( + "message_batch_id", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + batch = await response.parse() + assert_matches_type(DeletedMessageBatch, batch, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_delete(self, async_client: AsyncAnthropic) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): + await async_client.messages.batches.with_raw_response.delete( + "", + ) + @parametrize async def test_method_cancel(self, async_client: AsyncAnthropic) -> None: batch = await async_client.messages.batches.cancel(