Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add message batch delete endpoint #802

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -75,6 +75,7 @@ Types:

```python
from anthropic.types.messages import (
DeletedMessageBatch,
MessageBatch,
MessageBatchCanceledResult,
MessageBatchErroredResult,
Expand All @@ -91,6 +92,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 @@ -196,6 +198,7 @@ Types:

```python
from anthropic.types.beta.messages import (
BetaDeletedMessageBatch,
BetaMessageBatch,
BetaMessageBatchCanceledResult,
BetaMessageBatchErroredResult,
Expand All @@ -212,5 +215,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 @@ -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"]

Expand Down Expand Up @@ -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,
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 @@ -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,
)
Expand All @@ -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,
)
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 @@ -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,
)
Expand Down
89 changes: 89 additions & 0 deletions src/anthropic/resources/messages/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
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