Skip to content

Commit

Permalink
feat(api): add message batch delete endpoint (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jan 14, 2025
1 parent 151d0b5 commit cff57a2
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Types:

```python
from anthropic.types.messages import (
DeletedMessageBatch,
MessageBatch,
MessageBatchCanceledResult,
MessageBatchErroredResult,
Expand All @@ -92,6 +93,7 @@ Methods:
- <code title="post /v1/messages/batches">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">create</a>(\*\*<a href="src/anthropic/types/messages/batch_create_params.py">params</a>) -> <a href="./src/anthropic/types/messages/message_batch.py">MessageBatch</a></code>
- <code title="get /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">retrieve</a>(message_batch_id) -> <a href="./src/anthropic/types/messages/message_batch.py">MessageBatch</a></code>
- <code title="get /v1/messages/batches">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">list</a>(\*\*<a href="src/anthropic/types/messages/batch_list_params.py">params</a>) -> <a href="./src/anthropic/types/messages/message_batch.py">SyncPage[MessageBatch]</a></code>
- <code title="delete /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">delete</a>(message_batch_id) -> <a href="./src/anthropic/types/messages/deleted_message_batch.py">DeletedMessageBatch</a></code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">cancel</a>(message_batch_id) -> <a href="./src/anthropic/types/messages/message_batch.py">MessageBatch</a></code>
- <code title="get /v1/messages/batches/{message_batch_id}/results">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">results</a>(message_batch_id) -> BinaryAPIResponse</code>

Expand Down Expand Up @@ -197,6 +199,7 @@ Types:

```python
from anthropic.types.beta.messages import (
BetaDeletedMessageBatch,
BetaMessageBatch,
BetaMessageBatchCanceledResult,
BetaMessageBatchErroredResult,
Expand All @@ -213,5 +216,6 @@ Methods:
- <code title="post /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">create</a>(\*\*<a href="src/anthropic/types/beta/messages/batch_create_params.py">params</a>) -> <a href="./src/anthropic/types/beta/messages/beta_message_batch.py">BetaMessageBatch</a></code>
- <code title="get /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">retrieve</a>(message_batch_id) -> <a href="./src/anthropic/types/beta/messages/beta_message_batch.py">BetaMessageBatch</a></code>
- <code title="get /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">list</a>(\*\*<a href="src/anthropic/types/beta/messages/batch_list_params.py">params</a>) -> <a href="./src/anthropic/types/beta/messages/beta_message_batch.py">SyncPage[BetaMessageBatch]</a></code>
- <code title="delete /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">delete</a>(message_batch_id) -> <a href="./src/anthropic/types/beta/messages/beta_deleted_message_batch.py">BetaDeletedMessageBatch</a></code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">cancel</a>(message_batch_id) -> <a href="./src/anthropic/types/beta/messages/beta_message_batch.py">BetaMessageBatch</a></code>
- <code title="get /v1/messages/batches/{message_batch_id}/results?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">results</a>(message_batch_id) -> BinaryAPIResponse</code>
117 changes: 117 additions & 0 deletions src/anthropic/resources/beta/messages/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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
from ....types.beta.messages.beta_message_batch_individual_response import BetaMessageBatchIndividualResponse

__all__ = ["Batches", "AsyncBatches"]
Expand Down Expand Up @@ -226,6 +227,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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -677,6 +782,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,
)
Expand All @@ -695,6 +803,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,
)
Expand All @@ -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,
)
Expand All @@ -731,6 +845,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,
)
89 changes: 89 additions & 0 deletions src/anthropic/resources/messages/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from ...types.messages import MessageBatchIndividualResponse, batch_list_params, batch_create_params
from ..._decoders.jsonl import JSONLDecoder, AsyncJSONLDecoder
from ...types.messages.message_batch import MessageBatch
from ...types.messages.deleted_message_batch import DeletedMessageBatch

__all__ = ["Batches", "AsyncBatches"]

Expand Down Expand Up @@ -190,6 +191,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,
Expand Down Expand Up @@ -437,6 +476,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,
Expand Down Expand Up @@ -543,6 +620,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,
)
Expand All @@ -565,6 +645,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,
)
Expand All @@ -587,6 +670,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,
)
Expand All @@ -609,6 +695,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,
)
Expand Down
1 change: 1 addition & 0 deletions src/anthropic/types/beta/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/anthropic/types/beta/messages/beta_deleted_message_batch.py
Original file line number Diff line number Diff line change
@@ -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"`.
"""
1 change: 1 addition & 0 deletions src/anthropic/types/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/anthropic/types/messages/deleted_message_batch.py
Original file line number Diff line number Diff line change
@@ -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"`.
"""
Loading

0 comments on commit cff57a2

Please sign in to comment.