chore: 添加虚拟环境到仓库
- 添加 backend_service/venv 虚拟环境 - 包含所有Python依赖包 - 注意:虚拟环境约393MB,包含12655个文件
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from .beta import (
|
||||
Beta,
|
||||
AsyncBeta,
|
||||
BetaWithRawResponse,
|
||||
AsyncBetaWithRawResponse,
|
||||
BetaWithStreamingResponse,
|
||||
AsyncBetaWithStreamingResponse,
|
||||
)
|
||||
from .models import (
|
||||
Models,
|
||||
AsyncModels,
|
||||
ModelsWithRawResponse,
|
||||
AsyncModelsWithRawResponse,
|
||||
ModelsWithStreamingResponse,
|
||||
AsyncModelsWithStreamingResponse,
|
||||
)
|
||||
from .messages import (
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
from .completions import (
|
||||
Completions,
|
||||
AsyncCompletions,
|
||||
CompletionsWithRawResponse,
|
||||
AsyncCompletionsWithRawResponse,
|
||||
CompletionsWithStreamingResponse,
|
||||
AsyncCompletionsWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Completions",
|
||||
"AsyncCompletions",
|
||||
"CompletionsWithRawResponse",
|
||||
"AsyncCompletionsWithRawResponse",
|
||||
"CompletionsWithStreamingResponse",
|
||||
"AsyncCompletionsWithStreamingResponse",
|
||||
"Messages",
|
||||
"AsyncMessages",
|
||||
"MessagesWithRawResponse",
|
||||
"AsyncMessagesWithRawResponse",
|
||||
"MessagesWithStreamingResponse",
|
||||
"AsyncMessagesWithStreamingResponse",
|
||||
"Models",
|
||||
"AsyncModels",
|
||||
"ModelsWithRawResponse",
|
||||
"AsyncModelsWithRawResponse",
|
||||
"ModelsWithStreamingResponse",
|
||||
"AsyncModelsWithStreamingResponse",
|
||||
"Beta",
|
||||
"AsyncBeta",
|
||||
"BetaWithRawResponse",
|
||||
"AsyncBetaWithRawResponse",
|
||||
"BetaWithStreamingResponse",
|
||||
"AsyncBetaWithStreamingResponse",
|
||||
]
|
||||
@@ -0,0 +1,75 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from .beta import (
|
||||
Beta,
|
||||
AsyncBeta,
|
||||
BetaWithRawResponse,
|
||||
AsyncBetaWithRawResponse,
|
||||
BetaWithStreamingResponse,
|
||||
AsyncBetaWithStreamingResponse,
|
||||
)
|
||||
from .files import (
|
||||
Files,
|
||||
AsyncFiles,
|
||||
FilesWithRawResponse,
|
||||
AsyncFilesWithRawResponse,
|
||||
FilesWithStreamingResponse,
|
||||
AsyncFilesWithStreamingResponse,
|
||||
)
|
||||
from .models import (
|
||||
Models,
|
||||
AsyncModels,
|
||||
ModelsWithRawResponse,
|
||||
AsyncModelsWithRawResponse,
|
||||
ModelsWithStreamingResponse,
|
||||
AsyncModelsWithStreamingResponse,
|
||||
)
|
||||
from .skills import (
|
||||
Skills,
|
||||
AsyncSkills,
|
||||
SkillsWithRawResponse,
|
||||
AsyncSkillsWithRawResponse,
|
||||
SkillsWithStreamingResponse,
|
||||
AsyncSkillsWithStreamingResponse,
|
||||
)
|
||||
from .messages import (
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Models",
|
||||
"AsyncModels",
|
||||
"ModelsWithRawResponse",
|
||||
"AsyncModelsWithRawResponse",
|
||||
"ModelsWithStreamingResponse",
|
||||
"AsyncModelsWithStreamingResponse",
|
||||
"Messages",
|
||||
"AsyncMessages",
|
||||
"MessagesWithRawResponse",
|
||||
"AsyncMessagesWithRawResponse",
|
||||
"MessagesWithStreamingResponse",
|
||||
"AsyncMessagesWithStreamingResponse",
|
||||
"Files",
|
||||
"AsyncFiles",
|
||||
"FilesWithRawResponse",
|
||||
"AsyncFilesWithRawResponse",
|
||||
"FilesWithStreamingResponse",
|
||||
"AsyncFilesWithStreamingResponse",
|
||||
"Skills",
|
||||
"AsyncSkills",
|
||||
"SkillsWithRawResponse",
|
||||
"AsyncSkillsWithRawResponse",
|
||||
"SkillsWithStreamingResponse",
|
||||
"AsyncSkillsWithStreamingResponse",
|
||||
"Beta",
|
||||
"AsyncBeta",
|
||||
"BetaWithRawResponse",
|
||||
"AsyncBetaWithRawResponse",
|
||||
"BetaWithStreamingResponse",
|
||||
"AsyncBetaWithStreamingResponse",
|
||||
]
|
||||
@@ -0,0 +1,198 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .files import (
|
||||
Files,
|
||||
AsyncFiles,
|
||||
FilesWithRawResponse,
|
||||
AsyncFilesWithRawResponse,
|
||||
FilesWithStreamingResponse,
|
||||
AsyncFilesWithStreamingResponse,
|
||||
)
|
||||
from .models import (
|
||||
Models,
|
||||
AsyncModels,
|
||||
ModelsWithRawResponse,
|
||||
AsyncModelsWithRawResponse,
|
||||
ModelsWithStreamingResponse,
|
||||
AsyncModelsWithStreamingResponse,
|
||||
)
|
||||
from ..._compat import cached_property
|
||||
from ..._resource import SyncAPIResource, AsyncAPIResource
|
||||
from .skills.skills import (
|
||||
Skills,
|
||||
AsyncSkills,
|
||||
SkillsWithRawResponse,
|
||||
AsyncSkillsWithRawResponse,
|
||||
SkillsWithStreamingResponse,
|
||||
AsyncSkillsWithStreamingResponse,
|
||||
)
|
||||
from .messages.messages import (
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = ["Beta", "AsyncBeta"]
|
||||
|
||||
|
||||
class Beta(SyncAPIResource):
|
||||
@cached_property
|
||||
def models(self) -> Models:
|
||||
return Models(self._client)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> Messages:
|
||||
return Messages(self._client)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> Files:
|
||||
return Files(self._client)
|
||||
|
||||
@cached_property
|
||||
def skills(self) -> Skills:
|
||||
return Skills(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> BetaWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return BetaWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> BetaWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return BetaWithStreamingResponse(self)
|
||||
|
||||
|
||||
class AsyncBeta(AsyncAPIResource):
|
||||
@cached_property
|
||||
def models(self) -> AsyncModels:
|
||||
return AsyncModels(self._client)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> AsyncMessages:
|
||||
return AsyncMessages(self._client)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> AsyncFiles:
|
||||
return AsyncFiles(self._client)
|
||||
|
||||
@cached_property
|
||||
def skills(self) -> AsyncSkills:
|
||||
return AsyncSkills(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncBetaWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncBetaWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncBetaWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncBetaWithStreamingResponse(self)
|
||||
|
||||
|
||||
class BetaWithRawResponse:
|
||||
def __init__(self, beta: Beta) -> None:
|
||||
self._beta = beta
|
||||
|
||||
@cached_property
|
||||
def models(self) -> ModelsWithRawResponse:
|
||||
return ModelsWithRawResponse(self._beta.models)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> MessagesWithRawResponse:
|
||||
return MessagesWithRawResponse(self._beta.messages)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> FilesWithRawResponse:
|
||||
return FilesWithRawResponse(self._beta.files)
|
||||
|
||||
@cached_property
|
||||
def skills(self) -> SkillsWithRawResponse:
|
||||
return SkillsWithRawResponse(self._beta.skills)
|
||||
|
||||
|
||||
class AsyncBetaWithRawResponse:
|
||||
def __init__(self, beta: AsyncBeta) -> None:
|
||||
self._beta = beta
|
||||
|
||||
@cached_property
|
||||
def models(self) -> AsyncModelsWithRawResponse:
|
||||
return AsyncModelsWithRawResponse(self._beta.models)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> AsyncMessagesWithRawResponse:
|
||||
return AsyncMessagesWithRawResponse(self._beta.messages)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> AsyncFilesWithRawResponse:
|
||||
return AsyncFilesWithRawResponse(self._beta.files)
|
||||
|
||||
@cached_property
|
||||
def skills(self) -> AsyncSkillsWithRawResponse:
|
||||
return AsyncSkillsWithRawResponse(self._beta.skills)
|
||||
|
||||
|
||||
class BetaWithStreamingResponse:
|
||||
def __init__(self, beta: Beta) -> None:
|
||||
self._beta = beta
|
||||
|
||||
@cached_property
|
||||
def models(self) -> ModelsWithStreamingResponse:
|
||||
return ModelsWithStreamingResponse(self._beta.models)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> MessagesWithStreamingResponse:
|
||||
return MessagesWithStreamingResponse(self._beta.messages)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> FilesWithStreamingResponse:
|
||||
return FilesWithStreamingResponse(self._beta.files)
|
||||
|
||||
@cached_property
|
||||
def skills(self) -> SkillsWithStreamingResponse:
|
||||
return SkillsWithStreamingResponse(self._beta.skills)
|
||||
|
||||
|
||||
class AsyncBetaWithStreamingResponse:
|
||||
def __init__(self, beta: AsyncBeta) -> None:
|
||||
self._beta = beta
|
||||
|
||||
@cached_property
|
||||
def models(self) -> AsyncModelsWithStreamingResponse:
|
||||
return AsyncModelsWithStreamingResponse(self._beta.models)
|
||||
|
||||
@cached_property
|
||||
def messages(self) -> AsyncMessagesWithStreamingResponse:
|
||||
return AsyncMessagesWithStreamingResponse(self._beta.messages)
|
||||
|
||||
@cached_property
|
||||
def files(self) -> AsyncFilesWithStreamingResponse:
|
||||
return AsyncFilesWithStreamingResponse(self._beta.files)
|
||||
|
||||
@cached_property
|
||||
def skills(self) -> AsyncSkillsWithStreamingResponse:
|
||||
return AsyncSkillsWithStreamingResponse(self._beta.skills)
|
||||
@@ -0,0 +1,710 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Mapping, cast
|
||||
from itertools import chain
|
||||
|
||||
import httpx
|
||||
|
||||
from ... import _legacy_response
|
||||
from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
|
||||
from ..._utils import is_given, extract_files, maybe_transform, strip_not_given, deepcopy_minimal, async_maybe_transform
|
||||
from ..._compat import cached_property
|
||||
from ..._resource import SyncAPIResource, AsyncAPIResource
|
||||
from ..._response import (
|
||||
BinaryAPIResponse,
|
||||
AsyncBinaryAPIResponse,
|
||||
StreamedBinaryAPIResponse,
|
||||
AsyncStreamedBinaryAPIResponse,
|
||||
to_streamed_response_wrapper,
|
||||
to_custom_raw_response_wrapper,
|
||||
async_to_streamed_response_wrapper,
|
||||
to_custom_streamed_response_wrapper,
|
||||
async_to_custom_raw_response_wrapper,
|
||||
async_to_custom_streamed_response_wrapper,
|
||||
)
|
||||
from ...pagination import SyncPage, AsyncPage
|
||||
from ...types.beta import file_list_params, file_upload_params
|
||||
from ..._base_client import AsyncPaginator, make_request_options
|
||||
from ...types.beta.deleted_file import DeletedFile
|
||||
from ...types.beta.file_metadata import FileMetadata
|
||||
from ...types.anthropic_beta_param import AnthropicBetaParam
|
||||
|
||||
__all__ = ["Files", "AsyncFiles"]
|
||||
|
||||
|
||||
class Files(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> FilesWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return FilesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> FilesWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return FilesWithStreamingResponse(self)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SyncPage[FileMetadata]:
|
||||
"""List Files
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination.
|
||||
|
||||
When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
"/v1/files?beta=true",
|
||||
page=SyncPage[FileMetadata],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
file_list_params.FileListParams,
|
||||
),
|
||||
),
|
||||
model=FileMetadata,
|
||||
)
|
||||
|
||||
def delete(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> DeletedFile:
|
||||
"""
|
||||
Delete File
|
||||
|
||||
Args:
|
||||
file_id: ID of the File.
|
||||
|
||||
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 file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return self._delete(
|
||||
f"/v1/files/{file_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=DeletedFile,
|
||||
)
|
||||
|
||||
def download(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BinaryAPIResponse:
|
||||
"""
|
||||
Download File
|
||||
|
||||
Args:
|
||||
file_id: ID of the File.
|
||||
|
||||
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 file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/v1/files/{file_id}/content?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=BinaryAPIResponse,
|
||||
)
|
||||
|
||||
def retrieve_metadata(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> FileMetadata:
|
||||
"""
|
||||
Get File Metadata
|
||||
|
||||
Args:
|
||||
file_id: ID of the File.
|
||||
|
||||
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 file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/v1/files/{file_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=FileMetadata,
|
||||
)
|
||||
|
||||
def upload(
|
||||
self,
|
||||
*,
|
||||
file: FileTypes,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> FileMetadata:
|
||||
"""
|
||||
Upload File
|
||||
|
||||
Args:
|
||||
file: The file to upload
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
body = deepcopy_minimal({"file": file})
|
||||
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
||||
# It should be noted that the actual Content-Type header that will be
|
||||
# sent to the server will contain a `boundary` parameter, e.g.
|
||||
# multipart/form-data; boundary=---abc--
|
||||
extra_headers["Content-Type"] = "multipart/form-data"
|
||||
return self._post(
|
||||
"/v1/files?beta=true",
|
||||
body=maybe_transform(body, file_upload_params.FileUploadParams),
|
||||
files=files,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=FileMetadata,
|
||||
)
|
||||
|
||||
|
||||
class AsyncFiles(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncFilesWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncFilesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncFilesWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncFilesWithStreamingResponse(self)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncPaginator[FileMetadata, AsyncPage[FileMetadata]]:
|
||||
"""List Files
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination.
|
||||
|
||||
When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
"/v1/files?beta=true",
|
||||
page=AsyncPage[FileMetadata],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
file_list_params.FileListParams,
|
||||
),
|
||||
),
|
||||
model=FileMetadata,
|
||||
)
|
||||
|
||||
async def delete(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> DeletedFile:
|
||||
"""
|
||||
Delete File
|
||||
|
||||
Args:
|
||||
file_id: ID of the File.
|
||||
|
||||
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 file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return await self._delete(
|
||||
f"/v1/files/{file_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=DeletedFile,
|
||||
)
|
||||
|
||||
async def download(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncBinaryAPIResponse:
|
||||
"""
|
||||
Download File
|
||||
|
||||
Args:
|
||||
file_id: ID of the File.
|
||||
|
||||
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 file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/v1/files/{file_id}/content?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=AsyncBinaryAPIResponse,
|
||||
)
|
||||
|
||||
async def retrieve_metadata(
|
||||
self,
|
||||
file_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> FileMetadata:
|
||||
"""
|
||||
Get File Metadata
|
||||
|
||||
Args:
|
||||
file_id: ID of the File.
|
||||
|
||||
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 file_id:
|
||||
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/v1/files/{file_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=FileMetadata,
|
||||
)
|
||||
|
||||
async def upload(
|
||||
self,
|
||||
*,
|
||||
file: FileTypes,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> FileMetadata:
|
||||
"""
|
||||
Upload File
|
||||
|
||||
Args:
|
||||
file: The file to upload
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["files-api-2025-04-14"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "files-api-2025-04-14", **(extra_headers or {})}
|
||||
body = deepcopy_minimal({"file": file})
|
||||
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
||||
# It should be noted that the actual Content-Type header that will be
|
||||
# sent to the server will contain a `boundary` parameter, e.g.
|
||||
# multipart/form-data; boundary=---abc--
|
||||
extra_headers["Content-Type"] = "multipart/form-data"
|
||||
return await self._post(
|
||||
"/v1/files?beta=true",
|
||||
body=await async_maybe_transform(body, file_upload_params.FileUploadParams),
|
||||
files=files,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=FileMetadata,
|
||||
)
|
||||
|
||||
|
||||
class FilesWithRawResponse:
|
||||
def __init__(self, files: Files) -> None:
|
||||
self._files = files
|
||||
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
self.delete = _legacy_response.to_raw_response_wrapper(
|
||||
files.delete,
|
||||
)
|
||||
self.download = to_custom_raw_response_wrapper(
|
||||
files.download,
|
||||
BinaryAPIResponse,
|
||||
)
|
||||
self.retrieve_metadata = _legacy_response.to_raw_response_wrapper(
|
||||
files.retrieve_metadata,
|
||||
)
|
||||
self.upload = _legacy_response.to_raw_response_wrapper(
|
||||
files.upload,
|
||||
)
|
||||
|
||||
|
||||
class AsyncFilesWithRawResponse:
|
||||
def __init__(self, files: AsyncFiles) -> None:
|
||||
self._files = files
|
||||
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
self.delete = _legacy_response.async_to_raw_response_wrapper(
|
||||
files.delete,
|
||||
)
|
||||
self.download = async_to_custom_raw_response_wrapper(
|
||||
files.download,
|
||||
AsyncBinaryAPIResponse,
|
||||
)
|
||||
self.retrieve_metadata = _legacy_response.async_to_raw_response_wrapper(
|
||||
files.retrieve_metadata,
|
||||
)
|
||||
self.upload = _legacy_response.async_to_raw_response_wrapper(
|
||||
files.upload,
|
||||
)
|
||||
|
||||
|
||||
class FilesWithStreamingResponse:
|
||||
def __init__(self, files: Files) -> None:
|
||||
self._files = files
|
||||
|
||||
self.list = to_streamed_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
self.delete = to_streamed_response_wrapper(
|
||||
files.delete,
|
||||
)
|
||||
self.download = to_custom_streamed_response_wrapper(
|
||||
files.download,
|
||||
StreamedBinaryAPIResponse,
|
||||
)
|
||||
self.retrieve_metadata = to_streamed_response_wrapper(
|
||||
files.retrieve_metadata,
|
||||
)
|
||||
self.upload = to_streamed_response_wrapper(
|
||||
files.upload,
|
||||
)
|
||||
|
||||
|
||||
class AsyncFilesWithStreamingResponse:
|
||||
def __init__(self, files: AsyncFiles) -> None:
|
||||
self._files = files
|
||||
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
files.list,
|
||||
)
|
||||
self.delete = async_to_streamed_response_wrapper(
|
||||
files.delete,
|
||||
)
|
||||
self.download = async_to_custom_streamed_response_wrapper(
|
||||
files.download,
|
||||
AsyncStreamedBinaryAPIResponse,
|
||||
)
|
||||
self.retrieve_metadata = async_to_streamed_response_wrapper(
|
||||
files.retrieve_metadata,
|
||||
)
|
||||
self.upload = async_to_streamed_response_wrapper(
|
||||
files.upload,
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from .batches import (
|
||||
Batches,
|
||||
AsyncBatches,
|
||||
BatchesWithRawResponse,
|
||||
AsyncBatchesWithRawResponse,
|
||||
BatchesWithStreamingResponse,
|
||||
AsyncBatchesWithStreamingResponse,
|
||||
)
|
||||
from .messages import (
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Batches",
|
||||
"AsyncBatches",
|
||||
"BatchesWithRawResponse",
|
||||
"AsyncBatchesWithRawResponse",
|
||||
"BatchesWithStreamingResponse",
|
||||
"AsyncBatchesWithStreamingResponse",
|
||||
"Messages",
|
||||
"AsyncMessages",
|
||||
"MessagesWithRawResponse",
|
||||
"AsyncMessagesWithRawResponse",
|
||||
"MessagesWithStreamingResponse",
|
||||
"AsyncMessagesWithStreamingResponse",
|
||||
]
|
||||
@@ -0,0 +1,884 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Iterable
|
||||
from itertools import chain
|
||||
|
||||
import httpx
|
||||
|
||||
from .... import _legacy_response
|
||||
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
|
||||
from ...._utils import is_given, maybe_transform, strip_not_given, async_maybe_transform
|
||||
from ...._compat import cached_property
|
||||
from ...._resource import SyncAPIResource, AsyncAPIResource
|
||||
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from ....pagination import SyncPage, AsyncPage
|
||||
from ...._exceptions import AnthropicError
|
||||
from ...._base_client import AsyncPaginator, make_request_options
|
||||
from ...._decoders.jsonl import JSONLDecoder, AsyncJSONLDecoder
|
||||
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"]
|
||||
|
||||
|
||||
class Batches(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> BatchesWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return BatchesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> BatchesWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return BatchesWithStreamingResponse(self)
|
||||
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
requests: Iterable[batch_create_params.Request],
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaMessageBatch:
|
||||
"""
|
||||
Send a batch of Message creation requests.
|
||||
|
||||
The Message Batches API can be used to process multiple Messages API requests at
|
||||
once. Once a Message Batch is created, it begins processing immediately. Batches
|
||||
can take up to 24 hours to complete.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
requests: List of requests for prompt completion. Each is an individual request to create
|
||||
a Message.
|
||||
|
||||
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
|
||||
"""
|
||||
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._post(
|
||||
"/v1/messages/batches?beta=true",
|
||||
body=maybe_transform({"requests": requests}, batch_create_params.BatchCreateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=BetaMessageBatch,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
message_batch_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaMessageBatch:
|
||||
"""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.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._get(
|
||||
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=BetaMessageBatch,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SyncPage[BetaMessageBatch]:
|
||||
"""List all Message Batches within a Workspace.
|
||||
|
||||
Most recently created batches are
|
||||
returned first.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
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._get_api_list(
|
||||
"/v1/messages/batches?beta=true",
|
||||
page=SyncPage[BetaMessageBatch],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
batch_list_params.BatchListParams,
|
||||
),
|
||||
),
|
||||
model=BetaMessageBatch,
|
||||
)
|
||||
|
||||
def delete(
|
||||
self,
|
||||
message_batch_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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:
|
||||
"""
|
||||
Delete a Message Batch.
|
||||
|
||||
Message Batches can only be deleted once they've finished processing. If you'd
|
||||
like to delete an in-progress batch, you must first cancel it.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaMessageBatch:
|
||||
"""Batches may be canceled any time before processing ends.
|
||||
|
||||
Once cancellation is
|
||||
initiated, the batch enters a `canceling` state, at which time the system may
|
||||
complete any in-progress, non-interruptible requests before finalizing
|
||||
cancellation.
|
||||
|
||||
The number of canceled requests is specified in `request_counts`. To determine
|
||||
which requests were canceled, check the individual results within the batch.
|
||||
Note that cancellation may not result in any canceled requests if they were
|
||||
non-interruptible.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._post(
|
||||
f"/v1/messages/batches/{message_batch_id}/cancel?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=BetaMessageBatch,
|
||||
)
|
||||
|
||||
def results(
|
||||
self,
|
||||
message_batch_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> JSONLDecoder[BetaMessageBatchIndividualResponse]:
|
||||
"""
|
||||
Streams the results of a Message Batch as a `.jsonl` file.
|
||||
|
||||
Each line in the file is a JSON object containing the result of a single request
|
||||
in the Message Batch. Results are not guaranteed to be in the same order as
|
||||
requests. Use the `custom_id` field to match results to requests.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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}")
|
||||
|
||||
batch = self.retrieve(message_batch_id=message_batch_id)
|
||||
if not batch.results_url:
|
||||
raise AnthropicError(
|
||||
f"No `results_url` for the given batch; Has it finished processing? {batch.processing_status}"
|
||||
)
|
||||
|
||||
extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
|
||||
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._get(
|
||||
batch.results_url,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=JSONLDecoder[BetaMessageBatchIndividualResponse],
|
||||
stream=True,
|
||||
)
|
||||
|
||||
|
||||
class AsyncBatches(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncBatchesWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncBatchesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncBatchesWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncBatchesWithStreamingResponse(self)
|
||||
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
requests: Iterable[batch_create_params.Request],
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaMessageBatch:
|
||||
"""
|
||||
Send a batch of Message creation requests.
|
||||
|
||||
The Message Batches API can be used to process multiple Messages API requests at
|
||||
once. Once a Message Batch is created, it begins processing immediately. Batches
|
||||
can take up to 24 hours to complete.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
requests: List of requests for prompt completion. Each is an individual request to create
|
||||
a Message.
|
||||
|
||||
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
|
||||
"""
|
||||
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._post(
|
||||
"/v1/messages/batches?beta=true",
|
||||
body=await async_maybe_transform({"requests": requests}, batch_create_params.BatchCreateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=BetaMessageBatch,
|
||||
)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
message_batch_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaMessageBatch:
|
||||
"""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.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._get(
|
||||
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=BetaMessageBatch,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncPaginator[BetaMessageBatch, AsyncPage[BetaMessageBatch]]:
|
||||
"""List all Message Batches within a Workspace.
|
||||
|
||||
Most recently created batches are
|
||||
returned first.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
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._get_api_list(
|
||||
"/v1/messages/batches?beta=true",
|
||||
page=AsyncPage[BetaMessageBatch],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
batch_list_params.BatchListParams,
|
||||
),
|
||||
),
|
||||
model=BetaMessageBatch,
|
||||
)
|
||||
|
||||
async def delete(
|
||||
self,
|
||||
message_batch_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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:
|
||||
"""
|
||||
Delete a Message Batch.
|
||||
|
||||
Message Batches can only be deleted once they've finished processing. If you'd
|
||||
like to delete an in-progress batch, you must first cancel it.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaMessageBatch:
|
||||
"""Batches may be canceled any time before processing ends.
|
||||
|
||||
Once cancellation is
|
||||
initiated, the batch enters a `canceling` state, at which time the system may
|
||||
complete any in-progress, non-interruptible requests before finalizing
|
||||
cancellation.
|
||||
|
||||
The number of canceled requests is specified in `request_counts`. To determine
|
||||
which requests were canceled, check the individual results within the batch.
|
||||
Note that cancellation may not result in any canceled requests if they were
|
||||
non-interruptible.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._post(
|
||||
f"/v1/messages/batches/{message_batch_id}/cancel?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=BetaMessageBatch,
|
||||
)
|
||||
|
||||
async def results(
|
||||
self,
|
||||
message_batch_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncJSONLDecoder[BetaMessageBatchIndividualResponse]:
|
||||
"""
|
||||
Streams the results of a Message Batch as a `.jsonl` file.
|
||||
|
||||
Each line in the file is a JSON object containing the result of a single request
|
||||
in the Message Batch. Results are not guaranteed to be in the same order as
|
||||
requests. Use the `custom_id` field to match results to requests.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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}")
|
||||
|
||||
batch = await self.retrieve(message_batch_id=message_batch_id)
|
||||
if not batch.results_url:
|
||||
raise AnthropicError(
|
||||
f"No `results_url` for the given batch; Has it finished processing? {batch.processing_status}"
|
||||
)
|
||||
|
||||
extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
|
||||
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._get(
|
||||
batch.results_url,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=AsyncJSONLDecoder[BetaMessageBatchIndividualResponse],
|
||||
stream=True,
|
||||
)
|
||||
|
||||
|
||||
class BatchesWithRawResponse:
|
||||
def __init__(self, batches: Batches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
class AsyncBatchesWithRawResponse:
|
||||
def __init__(self, batches: AsyncBatches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
class BatchesWithStreamingResponse:
|
||||
def __init__(self, batches: Batches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
batches.list,
|
||||
)
|
||||
self.delete = to_streamed_response_wrapper(
|
||||
batches.delete,
|
||||
)
|
||||
self.cancel = to_streamed_response_wrapper(
|
||||
batches.cancel,
|
||||
)
|
||||
|
||||
|
||||
class AsyncBatchesWithStreamingResponse:
|
||||
def __init__(self, batches: AsyncBatches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
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,
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,331 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
|
||||
import httpx
|
||||
|
||||
from ... import _legacy_response
|
||||
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
|
||||
from ..._utils import is_given, maybe_transform, strip_not_given
|
||||
from ..._compat import cached_property
|
||||
from ..._resource import SyncAPIResource, AsyncAPIResource
|
||||
from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from ...pagination import SyncPage, AsyncPage
|
||||
from ...types.beta import model_list_params
|
||||
from ..._base_client import AsyncPaginator, make_request_options
|
||||
from ...types.anthropic_beta_param import AnthropicBetaParam
|
||||
from ...types.beta.beta_model_info import BetaModelInfo
|
||||
|
||||
__all__ = ["Models", "AsyncModels"]
|
||||
|
||||
|
||||
class Models(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> ModelsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return ModelsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> ModelsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return ModelsWithStreamingResponse(self)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
model_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaModelInfo:
|
||||
"""
|
||||
Get a specific model.
|
||||
|
||||
The Models API response can be used to determine information about a specific
|
||||
model or resolve a model alias to a model ID.
|
||||
|
||||
Args:
|
||||
model_id: Model identifier or alias.
|
||||
|
||||
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 model_id:
|
||||
raise ValueError(f"Expected a non-empty value for `model_id` but received {model_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return self._get(
|
||||
f"/v1/models/{model_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=BetaModelInfo,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SyncPage[BetaModelInfo]:
|
||||
"""
|
||||
List available models.
|
||||
|
||||
The Models API response can be used to determine which models are available for
|
||||
use in the API. More recently released models are listed first.
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return self._get_api_list(
|
||||
"/v1/models?beta=true",
|
||||
page=SyncPage[BetaModelInfo],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
model_list_params.ModelListParams,
|
||||
),
|
||||
),
|
||||
model=BetaModelInfo,
|
||||
)
|
||||
|
||||
|
||||
class AsyncModels(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncModelsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncModelsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncModelsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncModelsWithStreamingResponse(self)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
model_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> BetaModelInfo:
|
||||
"""
|
||||
Get a specific model.
|
||||
|
||||
The Models API response can be used to determine information about a specific
|
||||
model or resolve a model alias to a model ID.
|
||||
|
||||
Args:
|
||||
model_id: Model identifier or alias.
|
||||
|
||||
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 model_id:
|
||||
raise ValueError(f"Expected a non-empty value for `model_id` but received {model_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return await self._get(
|
||||
f"/v1/models/{model_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=BetaModelInfo,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncPaginator[BetaModelInfo, AsyncPage[BetaModelInfo]]:
|
||||
"""
|
||||
List available models.
|
||||
|
||||
The Models API response can be used to determine which models are available for
|
||||
use in the API. More recently released models are listed first.
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return self._get_api_list(
|
||||
"/v1/models?beta=true",
|
||||
page=AsyncPage[BetaModelInfo],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
model_list_params.ModelListParams,
|
||||
),
|
||||
),
|
||||
model=BetaModelInfo,
|
||||
)
|
||||
|
||||
|
||||
class ModelsWithRawResponse:
|
||||
def __init__(self, models: Models) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncModelsWithRawResponse:
|
||||
def __init__(self, models: AsyncModels) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
|
||||
|
||||
class ModelsWithStreamingResponse:
|
||||
def __init__(self, models: Models) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncModelsWithStreamingResponse:
|
||||
def __init__(self, models: AsyncModels) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from .skills import (
|
||||
Skills,
|
||||
AsyncSkills,
|
||||
SkillsWithRawResponse,
|
||||
AsyncSkillsWithRawResponse,
|
||||
SkillsWithStreamingResponse,
|
||||
AsyncSkillsWithStreamingResponse,
|
||||
)
|
||||
from .versions import (
|
||||
Versions,
|
||||
AsyncVersions,
|
||||
VersionsWithRawResponse,
|
||||
AsyncVersionsWithRawResponse,
|
||||
VersionsWithStreamingResponse,
|
||||
AsyncVersionsWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Versions",
|
||||
"AsyncVersions",
|
||||
"VersionsWithRawResponse",
|
||||
"AsyncVersionsWithRawResponse",
|
||||
"VersionsWithStreamingResponse",
|
||||
"AsyncVersionsWithStreamingResponse",
|
||||
"Skills",
|
||||
"AsyncSkills",
|
||||
"SkillsWithRawResponse",
|
||||
"AsyncSkillsWithRawResponse",
|
||||
"SkillsWithStreamingResponse",
|
||||
"AsyncSkillsWithStreamingResponse",
|
||||
]
|
||||
@@ -0,0 +1,680 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Mapping, Optional, cast
|
||||
from itertools import chain
|
||||
|
||||
import httpx
|
||||
|
||||
from .... import _legacy_response
|
||||
from .versions import (
|
||||
Versions,
|
||||
AsyncVersions,
|
||||
VersionsWithRawResponse,
|
||||
AsyncVersionsWithRawResponse,
|
||||
VersionsWithStreamingResponse,
|
||||
AsyncVersionsWithStreamingResponse,
|
||||
)
|
||||
from ...._types import (
|
||||
Body,
|
||||
Omit,
|
||||
Query,
|
||||
Headers,
|
||||
NotGiven,
|
||||
FileTypes,
|
||||
SequenceNotStr,
|
||||
omit,
|
||||
not_given,
|
||||
)
|
||||
from ...._utils import (
|
||||
is_given,
|
||||
extract_files,
|
||||
maybe_transform,
|
||||
strip_not_given,
|
||||
deepcopy_minimal,
|
||||
async_maybe_transform,
|
||||
)
|
||||
from ...._compat import cached_property
|
||||
from ...._resource import SyncAPIResource, AsyncAPIResource
|
||||
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from ....pagination import SyncPageCursor, AsyncPageCursor
|
||||
from ....types.beta import skill_list_params, skill_create_params
|
||||
from ...._base_client import AsyncPaginator, make_request_options
|
||||
from ....types.anthropic_beta_param import AnthropicBetaParam
|
||||
from ....types.beta.skill_list_response import SkillListResponse
|
||||
from ....types.beta.skill_create_response import SkillCreateResponse
|
||||
from ....types.beta.skill_delete_response import SkillDeleteResponse
|
||||
from ....types.beta.skill_retrieve_response import SkillRetrieveResponse
|
||||
|
||||
__all__ = ["Skills", "AsyncSkills"]
|
||||
|
||||
|
||||
class Skills(SyncAPIResource):
|
||||
@cached_property
|
||||
def versions(self) -> Versions:
|
||||
return Versions(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> SkillsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return SkillsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> SkillsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return SkillsWithStreamingResponse(self)
|
||||
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
display_title: Optional[str] | Omit = omit,
|
||||
files: Optional[SequenceNotStr[FileTypes]] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SkillCreateResponse:
|
||||
"""
|
||||
Create Skill
|
||||
|
||||
Args:
|
||||
display_title: Display title for the skill.
|
||||
|
||||
This is a human-readable label that is not included in the prompt sent to the
|
||||
model.
|
||||
|
||||
files: Files to upload for the skill.
|
||||
|
||||
All files must be in the same top-level directory and must include a SKILL.md
|
||||
file at the root of that directory.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"display_title": display_title,
|
||||
"files": files,
|
||||
}
|
||||
)
|
||||
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
|
||||
# It should be noted that the actual Content-Type header that will be
|
||||
# sent to the server will contain a `boundary` parameter, e.g.
|
||||
# multipart/form-data; boundary=---abc--
|
||||
extra_headers["Content-Type"] = "multipart/form-data"
|
||||
return self._post(
|
||||
"/v1/skills?beta=true",
|
||||
body=maybe_transform(body, skill_create_params.SkillCreateParams),
|
||||
files=extracted_files,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=SkillCreateResponse,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SkillRetrieveResponse:
|
||||
"""
|
||||
Get Skill
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/v1/skills/{skill_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=SkillRetrieveResponse,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
limit: int | Omit = omit,
|
||||
page: Optional[str] | Omit = omit,
|
||||
source: Optional[str] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SyncPageCursor[SkillListResponse]:
|
||||
"""
|
||||
List Skills
|
||||
|
||||
Args:
|
||||
limit: Number of results to return per page.
|
||||
|
||||
Maximum value is 100. Defaults to 20.
|
||||
|
||||
page: Pagination token for fetching a specific page of results.
|
||||
|
||||
Pass the value from a previous response's `next_page` field to get the next page
|
||||
of results.
|
||||
|
||||
source: Filter skills by source.
|
||||
|
||||
If provided, only skills from the specified source will be returned:
|
||||
|
||||
- `"custom"`: only return user-created skills
|
||||
- `"anthropic"`: only return Anthropic-created skills
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
"/v1/skills?beta=true",
|
||||
page=SyncPageCursor[SkillListResponse],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"limit": limit,
|
||||
"page": page,
|
||||
"source": source,
|
||||
},
|
||||
skill_list_params.SkillListParams,
|
||||
),
|
||||
),
|
||||
model=SkillListResponse,
|
||||
)
|
||||
|
||||
def delete(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SkillDeleteResponse:
|
||||
"""
|
||||
Delete Skill
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._delete(
|
||||
f"/v1/skills/{skill_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=SkillDeleteResponse,
|
||||
)
|
||||
|
||||
|
||||
class AsyncSkills(AsyncAPIResource):
|
||||
@cached_property
|
||||
def versions(self) -> AsyncVersions:
|
||||
return AsyncVersions(self._client)
|
||||
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncSkillsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncSkillsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncSkillsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncSkillsWithStreamingResponse(self)
|
||||
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
display_title: Optional[str] | Omit = omit,
|
||||
files: Optional[SequenceNotStr[FileTypes]] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SkillCreateResponse:
|
||||
"""
|
||||
Create Skill
|
||||
|
||||
Args:
|
||||
display_title: Display title for the skill.
|
||||
|
||||
This is a human-readable label that is not included in the prompt sent to the
|
||||
model.
|
||||
|
||||
files: Files to upload for the skill.
|
||||
|
||||
All files must be in the same top-level directory and must include a SKILL.md
|
||||
file at the root of that directory.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
body = deepcopy_minimal(
|
||||
{
|
||||
"display_title": display_title,
|
||||
"files": files,
|
||||
}
|
||||
)
|
||||
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
|
||||
# It should be noted that the actual Content-Type header that will be
|
||||
# sent to the server will contain a `boundary` parameter, e.g.
|
||||
# multipart/form-data; boundary=---abc--
|
||||
extra_headers["Content-Type"] = "multipart/form-data"
|
||||
return await self._post(
|
||||
"/v1/skills?beta=true",
|
||||
body=await async_maybe_transform(body, skill_create_params.SkillCreateParams),
|
||||
files=extracted_files,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=SkillCreateResponse,
|
||||
)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SkillRetrieveResponse:
|
||||
"""
|
||||
Get Skill
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/v1/skills/{skill_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=SkillRetrieveResponse,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
limit: int | Omit = omit,
|
||||
page: Optional[str] | Omit = omit,
|
||||
source: Optional[str] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncPaginator[SkillListResponse, AsyncPageCursor[SkillListResponse]]:
|
||||
"""
|
||||
List Skills
|
||||
|
||||
Args:
|
||||
limit: Number of results to return per page.
|
||||
|
||||
Maximum value is 100. Defaults to 20.
|
||||
|
||||
page: Pagination token for fetching a specific page of results.
|
||||
|
||||
Pass the value from a previous response's `next_page` field to get the next page
|
||||
of results.
|
||||
|
||||
source: Filter skills by source.
|
||||
|
||||
If provided, only skills from the specified source will be returned:
|
||||
|
||||
- `"custom"`: only return user-created skills
|
||||
- `"anthropic"`: only return Anthropic-created skills
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
"/v1/skills?beta=true",
|
||||
page=AsyncPageCursor[SkillListResponse],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"limit": limit,
|
||||
"page": page,
|
||||
"source": source,
|
||||
},
|
||||
skill_list_params.SkillListParams,
|
||||
),
|
||||
),
|
||||
model=SkillListResponse,
|
||||
)
|
||||
|
||||
async def delete(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SkillDeleteResponse:
|
||||
"""
|
||||
Delete Skill
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return await self._delete(
|
||||
f"/v1/skills/{skill_id}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=SkillDeleteResponse,
|
||||
)
|
||||
|
||||
|
||||
class SkillsWithRawResponse:
|
||||
def __init__(self, skills: Skills) -> None:
|
||||
self._skills = skills
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
skills.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
skills.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
skills.list,
|
||||
)
|
||||
self.delete = _legacy_response.to_raw_response_wrapper(
|
||||
skills.delete,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def versions(self) -> VersionsWithRawResponse:
|
||||
return VersionsWithRawResponse(self._skills.versions)
|
||||
|
||||
|
||||
class AsyncSkillsWithRawResponse:
|
||||
def __init__(self, skills: AsyncSkills) -> None:
|
||||
self._skills = skills
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
skills.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
skills.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
skills.list,
|
||||
)
|
||||
self.delete = _legacy_response.async_to_raw_response_wrapper(
|
||||
skills.delete,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def versions(self) -> AsyncVersionsWithRawResponse:
|
||||
return AsyncVersionsWithRawResponse(self._skills.versions)
|
||||
|
||||
|
||||
class SkillsWithStreamingResponse:
|
||||
def __init__(self, skills: Skills) -> None:
|
||||
self._skills = skills
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
skills.create,
|
||||
)
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
skills.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
skills.list,
|
||||
)
|
||||
self.delete = to_streamed_response_wrapper(
|
||||
skills.delete,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def versions(self) -> VersionsWithStreamingResponse:
|
||||
return VersionsWithStreamingResponse(self._skills.versions)
|
||||
|
||||
|
||||
class AsyncSkillsWithStreamingResponse:
|
||||
def __init__(self, skills: AsyncSkills) -> None:
|
||||
self._skills = skills
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
skills.create,
|
||||
)
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
skills.retrieve,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
skills.list,
|
||||
)
|
||||
self.delete = async_to_streamed_response_wrapper(
|
||||
skills.delete,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def versions(self) -> AsyncVersionsWithStreamingResponse:
|
||||
return AsyncVersionsWithStreamingResponse(self._skills.versions)
|
||||
@@ -0,0 +1,658 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List, Mapping, Optional, cast
|
||||
from itertools import chain
|
||||
|
||||
import httpx
|
||||
|
||||
from .... import _legacy_response
|
||||
from ...._types import (
|
||||
Body,
|
||||
Omit,
|
||||
Query,
|
||||
Headers,
|
||||
NotGiven,
|
||||
FileTypes,
|
||||
SequenceNotStr,
|
||||
omit,
|
||||
not_given,
|
||||
)
|
||||
from ...._utils import (
|
||||
is_given,
|
||||
extract_files,
|
||||
maybe_transform,
|
||||
strip_not_given,
|
||||
deepcopy_minimal,
|
||||
async_maybe_transform,
|
||||
)
|
||||
from ...._compat import cached_property
|
||||
from ...._resource import SyncAPIResource, AsyncAPIResource
|
||||
from ...._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from ....pagination import SyncPageCursor, AsyncPageCursor
|
||||
from ...._base_client import AsyncPaginator, make_request_options
|
||||
from ....types.beta.skills import version_list_params, version_create_params
|
||||
from ....types.anthropic_beta_param import AnthropicBetaParam
|
||||
from ....types.beta.skills.version_list_response import VersionListResponse
|
||||
from ....types.beta.skills.version_create_response import VersionCreateResponse
|
||||
from ....types.beta.skills.version_delete_response import VersionDeleteResponse
|
||||
from ....types.beta.skills.version_retrieve_response import VersionRetrieveResponse
|
||||
|
||||
__all__ = ["Versions", "AsyncVersions"]
|
||||
|
||||
|
||||
class Versions(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> VersionsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return VersionsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> VersionsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return VersionsWithStreamingResponse(self)
|
||||
|
||||
def create(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
files: Optional[SequenceNotStr[FileTypes]] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> VersionCreateResponse:
|
||||
"""
|
||||
Create Skill Version
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
files: Files to upload for the skill.
|
||||
|
||||
All files must be in the same top-level directory and must include a SKILL.md
|
||||
file at the root of that directory.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
body = deepcopy_minimal({"files": files})
|
||||
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
|
||||
# It should be noted that the actual Content-Type header that will be
|
||||
# sent to the server will contain a `boundary` parameter, e.g.
|
||||
# multipart/form-data; boundary=---abc--
|
||||
extra_headers["Content-Type"] = "multipart/form-data"
|
||||
return self._post(
|
||||
f"/v1/skills/{skill_id}/versions?beta=true",
|
||||
body=maybe_transform(body, version_create_params.VersionCreateParams),
|
||||
files=extracted_files,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=VersionCreateResponse,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
version: str,
|
||||
*,
|
||||
skill_id: str,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> VersionRetrieveResponse:
|
||||
"""
|
||||
Get Skill Version
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
version: Version identifier for the skill.
|
||||
|
||||
Each version is identified by a Unix epoch timestamp (e.g., "1759178010641129").
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
if not version:
|
||||
raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._get(
|
||||
f"/v1/skills/{skill_id}/versions/{version}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=VersionRetrieveResponse,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
limit: Optional[int] | Omit = omit,
|
||||
page: Optional[str] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SyncPageCursor[VersionListResponse]:
|
||||
"""
|
||||
List Skill Versions
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
page: Optionally set to the `next_page` token from the previous response.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/v1/skills/{skill_id}/versions?beta=true",
|
||||
page=SyncPageCursor[VersionListResponse],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"limit": limit,
|
||||
"page": page,
|
||||
},
|
||||
version_list_params.VersionListParams,
|
||||
),
|
||||
),
|
||||
model=VersionListResponse,
|
||||
)
|
||||
|
||||
def delete(
|
||||
self,
|
||||
version: str,
|
||||
*,
|
||||
skill_id: str,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> VersionDeleteResponse:
|
||||
"""
|
||||
Delete Skill Version
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
version: Version identifier for the skill.
|
||||
|
||||
Each version is identified by a Unix epoch timestamp (e.g., "1759178010641129").
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
if not version:
|
||||
raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._delete(
|
||||
f"/v1/skills/{skill_id}/versions/{version}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=VersionDeleteResponse,
|
||||
)
|
||||
|
||||
|
||||
class AsyncVersions(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncVersionsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncVersionsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncVersionsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncVersionsWithStreamingResponse(self)
|
||||
|
||||
async def create(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
files: Optional[SequenceNotStr[FileTypes]] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> VersionCreateResponse:
|
||||
"""
|
||||
Create Skill Version
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
files: Files to upload for the skill.
|
||||
|
||||
All files must be in the same top-level directory and must include a SKILL.md
|
||||
file at the root of that directory.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
body = deepcopy_minimal({"files": files})
|
||||
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
|
||||
# It should be noted that the actual Content-Type header that will be
|
||||
# sent to the server will contain a `boundary` parameter, e.g.
|
||||
# multipart/form-data; boundary=---abc--
|
||||
extra_headers["Content-Type"] = "multipart/form-data"
|
||||
return await self._post(
|
||||
f"/v1/skills/{skill_id}/versions?beta=true",
|
||||
body=await async_maybe_transform(body, version_create_params.VersionCreateParams),
|
||||
files=extracted_files,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=VersionCreateResponse,
|
||||
)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
version: str,
|
||||
*,
|
||||
skill_id: str,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> VersionRetrieveResponse:
|
||||
"""
|
||||
Get Skill Version
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
version: Version identifier for the skill.
|
||||
|
||||
Each version is identified by a Unix epoch timestamp (e.g., "1759178010641129").
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
if not version:
|
||||
raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
f"/v1/skills/{skill_id}/versions/{version}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=VersionRetrieveResponse,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
skill_id: str,
|
||||
*,
|
||||
limit: Optional[int] | Omit = omit,
|
||||
page: Optional[str] | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncPaginator[VersionListResponse, AsyncPageCursor[VersionListResponse]]:
|
||||
"""
|
||||
List Skill Versions
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
page: Optionally set to the `next_page` token from the previous response.
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return self._get_api_list(
|
||||
f"/v1/skills/{skill_id}/versions?beta=true",
|
||||
page=AsyncPageCursor[VersionListResponse],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"limit": limit,
|
||||
"page": page,
|
||||
},
|
||||
version_list_params.VersionListParams,
|
||||
),
|
||||
),
|
||||
model=VersionListResponse,
|
||||
)
|
||||
|
||||
async def delete(
|
||||
self,
|
||||
version: str,
|
||||
*,
|
||||
skill_id: str,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> VersionDeleteResponse:
|
||||
"""
|
||||
Delete Skill Version
|
||||
|
||||
Args:
|
||||
skill_id: Unique identifier for the skill.
|
||||
|
||||
The format and length of IDs may change over time.
|
||||
|
||||
version: Version identifier for the skill.
|
||||
|
||||
Each version is identified by a Unix epoch timestamp (e.g., "1759178010641129").
|
||||
|
||||
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 skill_id:
|
||||
raise ValueError(f"Expected a non-empty value for `skill_id` but received {skill_id!r}")
|
||||
if not version:
|
||||
raise ValueError(f"Expected a non-empty value for `version` but received {version!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given(
|
||||
{
|
||||
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["skills-2025-10-02"]))
|
||||
if is_given(betas)
|
||||
else not_given
|
||||
}
|
||||
),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
extra_headers = {"anthropic-beta": "skills-2025-10-02", **(extra_headers or {})}
|
||||
return await self._delete(
|
||||
f"/v1/skills/{skill_id}/versions/{version}?beta=true",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=VersionDeleteResponse,
|
||||
)
|
||||
|
||||
|
||||
class VersionsWithRawResponse:
|
||||
def __init__(self, versions: Versions) -> None:
|
||||
self._versions = versions
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
versions.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
versions.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
versions.list,
|
||||
)
|
||||
self.delete = _legacy_response.to_raw_response_wrapper(
|
||||
versions.delete,
|
||||
)
|
||||
|
||||
|
||||
class AsyncVersionsWithRawResponse:
|
||||
def __init__(self, versions: AsyncVersions) -> None:
|
||||
self._versions = versions
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
versions.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
versions.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
versions.list,
|
||||
)
|
||||
self.delete = _legacy_response.async_to_raw_response_wrapper(
|
||||
versions.delete,
|
||||
)
|
||||
|
||||
|
||||
class VersionsWithStreamingResponse:
|
||||
def __init__(self, versions: Versions) -> None:
|
||||
self._versions = versions
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
versions.create,
|
||||
)
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
versions.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
versions.list,
|
||||
)
|
||||
self.delete = to_streamed_response_wrapper(
|
||||
versions.delete,
|
||||
)
|
||||
|
||||
|
||||
class AsyncVersionsWithStreamingResponse:
|
||||
def __init__(self, versions: AsyncVersions) -> None:
|
||||
self._versions = versions
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
versions.create,
|
||||
)
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
versions.retrieve,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
versions.list,
|
||||
)
|
||||
self.delete = async_to_streamed_response_wrapper(
|
||||
versions.delete,
|
||||
)
|
||||
@@ -0,0 +1,845 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
from typing_extensions import Literal, overload
|
||||
|
||||
import httpx
|
||||
|
||||
from .. import _legacy_response
|
||||
from ..types import completion_create_params
|
||||
from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
|
||||
from .._utils import is_given, required_args, maybe_transform, strip_not_given, async_maybe_transform
|
||||
from .._compat import cached_property
|
||||
from .._resource import SyncAPIResource, AsyncAPIResource
|
||||
from .._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from .._constants import DEFAULT_TIMEOUT
|
||||
from .._streaming import Stream, AsyncStream
|
||||
from .._base_client import make_request_options
|
||||
from ..types.completion import Completion
|
||||
from ..types.model_param import ModelParam
|
||||
from ..types.metadata_param import MetadataParam
|
||||
from ..types.anthropic_beta_param import AnthropicBetaParam
|
||||
|
||||
__all__ = ["Completions", "AsyncCompletions"]
|
||||
|
||||
|
||||
class Completions(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> CompletionsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return CompletionsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> CompletionsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return CompletionsWithStreamingResponse(self)
|
||||
|
||||
@overload
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
stream: Literal[False] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> Completion:
|
||||
"""[Legacy] Create a Text Completion.
|
||||
|
||||
The Text Completions API is a legacy API.
|
||||
|
||||
We recommend using the
|
||||
[Messages API](https://docs.claude.com/en/api/messages) going forward.
|
||||
|
||||
Future models and features will not be compatible with Text Completions. See our
|
||||
[migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-messages)
|
||||
for guidance in migrating from Text Completions to Messages.
|
||||
|
||||
Args:
|
||||
max_tokens_to_sample: The maximum number of tokens to generate before stopping.
|
||||
|
||||
Note that our models may stop _before_ reaching this maximum. This parameter
|
||||
only specifies the absolute maximum number of tokens to generate.
|
||||
|
||||
model: The model that will complete your prompt.\n\nSee
|
||||
[models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
||||
details and options.
|
||||
|
||||
prompt: The prompt that you want Claude to complete.
|
||||
|
||||
For proper response generation you will need to format your prompt using
|
||||
alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
||||
|
||||
```
|
||||
"\n\nHuman: {userQuestion}\n\nAssistant:"
|
||||
```
|
||||
|
||||
See [prompt validation](https://docs.claude.com/en/api/prompt-validation) and
|
||||
our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting)
|
||||
for more details.
|
||||
|
||||
metadata: An object describing metadata about the request.
|
||||
|
||||
stop_sequences: Sequences that will cause the model to stop generating.
|
||||
|
||||
Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
||||
sequences in the future. By providing the stop_sequences parameter, you may
|
||||
include additional strings that will cause the model to stop generating.
|
||||
|
||||
stream: Whether to incrementally stream the response using server-sent events.
|
||||
|
||||
See [streaming](https://docs.claude.com/en/api/streaming) for details.
|
||||
|
||||
temperature: Amount of randomness injected into the response.
|
||||
|
||||
Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
||||
for analytical / multiple choice, and closer to `1.0` for creative and
|
||||
generative tasks.
|
||||
|
||||
Note that even with `temperature` of `0.0`, the results will not be fully
|
||||
deterministic.
|
||||
|
||||
top_k: Only sample from the top K options for each subsequent token.
|
||||
|
||||
Used to remove "long tail" low probability responses.
|
||||
[Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
top_p: Use nucleus sampling.
|
||||
|
||||
In nucleus sampling, we compute the cumulative distribution over all the options
|
||||
for each subsequent token in decreasing probability order and cut it off once it
|
||||
reaches a particular probability specified by `top_p`. You should either alter
|
||||
`temperature` or `top_p`, but not both.
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
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
|
||||
"""
|
||||
...
|
||||
|
||||
@overload
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
stream: Literal[True],
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> Stream[Completion]:
|
||||
"""[Legacy] Create a Text Completion.
|
||||
|
||||
The Text Completions API is a legacy API.
|
||||
|
||||
We recommend using the
|
||||
[Messages API](https://docs.claude.com/en/api/messages) going forward.
|
||||
|
||||
Future models and features will not be compatible with Text Completions. See our
|
||||
[migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-messages)
|
||||
for guidance in migrating from Text Completions to Messages.
|
||||
|
||||
Args:
|
||||
max_tokens_to_sample: The maximum number of tokens to generate before stopping.
|
||||
|
||||
Note that our models may stop _before_ reaching this maximum. This parameter
|
||||
only specifies the absolute maximum number of tokens to generate.
|
||||
|
||||
model: The model that will complete your prompt.\n\nSee
|
||||
[models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
||||
details and options.
|
||||
|
||||
prompt: The prompt that you want Claude to complete.
|
||||
|
||||
For proper response generation you will need to format your prompt using
|
||||
alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
||||
|
||||
```
|
||||
"\n\nHuman: {userQuestion}\n\nAssistant:"
|
||||
```
|
||||
|
||||
See [prompt validation](https://docs.claude.com/en/api/prompt-validation) and
|
||||
our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting)
|
||||
for more details.
|
||||
|
||||
stream: Whether to incrementally stream the response using server-sent events.
|
||||
|
||||
See [streaming](https://docs.claude.com/en/api/streaming) for details.
|
||||
|
||||
metadata: An object describing metadata about the request.
|
||||
|
||||
stop_sequences: Sequences that will cause the model to stop generating.
|
||||
|
||||
Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
||||
sequences in the future. By providing the stop_sequences parameter, you may
|
||||
include additional strings that will cause the model to stop generating.
|
||||
|
||||
temperature: Amount of randomness injected into the response.
|
||||
|
||||
Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
||||
for analytical / multiple choice, and closer to `1.0` for creative and
|
||||
generative tasks.
|
||||
|
||||
Note that even with `temperature` of `0.0`, the results will not be fully
|
||||
deterministic.
|
||||
|
||||
top_k: Only sample from the top K options for each subsequent token.
|
||||
|
||||
Used to remove "long tail" low probability responses.
|
||||
[Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
top_p: Use nucleus sampling.
|
||||
|
||||
In nucleus sampling, we compute the cumulative distribution over all the options
|
||||
for each subsequent token in decreasing probability order and cut it off once it
|
||||
reaches a particular probability specified by `top_p`. You should either alter
|
||||
`temperature` or `top_p`, but not both.
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
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
|
||||
"""
|
||||
...
|
||||
|
||||
@overload
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
stream: bool,
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> Completion | Stream[Completion]:
|
||||
"""[Legacy] Create a Text Completion.
|
||||
|
||||
The Text Completions API is a legacy API.
|
||||
|
||||
We recommend using the
|
||||
[Messages API](https://docs.claude.com/en/api/messages) going forward.
|
||||
|
||||
Future models and features will not be compatible with Text Completions. See our
|
||||
[migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-messages)
|
||||
for guidance in migrating from Text Completions to Messages.
|
||||
|
||||
Args:
|
||||
max_tokens_to_sample: The maximum number of tokens to generate before stopping.
|
||||
|
||||
Note that our models may stop _before_ reaching this maximum. This parameter
|
||||
only specifies the absolute maximum number of tokens to generate.
|
||||
|
||||
model: The model that will complete your prompt.\n\nSee
|
||||
[models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
||||
details and options.
|
||||
|
||||
prompt: The prompt that you want Claude to complete.
|
||||
|
||||
For proper response generation you will need to format your prompt using
|
||||
alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
||||
|
||||
```
|
||||
"\n\nHuman: {userQuestion}\n\nAssistant:"
|
||||
```
|
||||
|
||||
See [prompt validation](https://docs.claude.com/en/api/prompt-validation) and
|
||||
our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting)
|
||||
for more details.
|
||||
|
||||
stream: Whether to incrementally stream the response using server-sent events.
|
||||
|
||||
See [streaming](https://docs.claude.com/en/api/streaming) for details.
|
||||
|
||||
metadata: An object describing metadata about the request.
|
||||
|
||||
stop_sequences: Sequences that will cause the model to stop generating.
|
||||
|
||||
Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
||||
sequences in the future. By providing the stop_sequences parameter, you may
|
||||
include additional strings that will cause the model to stop generating.
|
||||
|
||||
temperature: Amount of randomness injected into the response.
|
||||
|
||||
Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
||||
for analytical / multiple choice, and closer to `1.0` for creative and
|
||||
generative tasks.
|
||||
|
||||
Note that even with `temperature` of `0.0`, the results will not be fully
|
||||
deterministic.
|
||||
|
||||
top_k: Only sample from the top K options for each subsequent token.
|
||||
|
||||
Used to remove "long tail" low probability responses.
|
||||
[Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
top_p: Use nucleus sampling.
|
||||
|
||||
In nucleus sampling, we compute the cumulative distribution over all the options
|
||||
for each subsequent token in decreasing probability order and cut it off once it
|
||||
reaches a particular probability specified by `top_p`. You should either alter
|
||||
`temperature` or `top_p`, but not both.
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
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
|
||||
"""
|
||||
...
|
||||
|
||||
@required_args(["max_tokens_to_sample", "model", "prompt"], ["max_tokens_to_sample", "model", "prompt", "stream"])
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
stream: Literal[False] | Literal[True] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> Completion | Stream[Completion]:
|
||||
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
|
||||
timeout = 600
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return self._post(
|
||||
"/v1/complete",
|
||||
body=maybe_transform(
|
||||
{
|
||||
"max_tokens_to_sample": max_tokens_to_sample,
|
||||
"model": model,
|
||||
"prompt": prompt,
|
||||
"metadata": metadata,
|
||||
"stop_sequences": stop_sequences,
|
||||
"stream": stream,
|
||||
"temperature": temperature,
|
||||
"top_k": top_k,
|
||||
"top_p": top_p,
|
||||
},
|
||||
completion_create_params.CompletionCreateParamsStreaming
|
||||
if stream
|
||||
else completion_create_params.CompletionCreateParamsNonStreaming,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Completion,
|
||||
stream=stream or False,
|
||||
stream_cls=Stream[Completion],
|
||||
)
|
||||
|
||||
|
||||
class AsyncCompletions(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncCompletionsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncCompletionsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncCompletionsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncCompletionsWithStreamingResponse(self)
|
||||
|
||||
@overload
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
stream: Literal[False] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> Completion:
|
||||
"""[Legacy] Create a Text Completion.
|
||||
|
||||
The Text Completions API is a legacy API.
|
||||
|
||||
We recommend using the
|
||||
[Messages API](https://docs.claude.com/en/api/messages) going forward.
|
||||
|
||||
Future models and features will not be compatible with Text Completions. See our
|
||||
[migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-messages)
|
||||
for guidance in migrating from Text Completions to Messages.
|
||||
|
||||
Args:
|
||||
max_tokens_to_sample: The maximum number of tokens to generate before stopping.
|
||||
|
||||
Note that our models may stop _before_ reaching this maximum. This parameter
|
||||
only specifies the absolute maximum number of tokens to generate.
|
||||
|
||||
model: The model that will complete your prompt.\n\nSee
|
||||
[models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
||||
details and options.
|
||||
|
||||
prompt: The prompt that you want Claude to complete.
|
||||
|
||||
For proper response generation you will need to format your prompt using
|
||||
alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
||||
|
||||
```
|
||||
"\n\nHuman: {userQuestion}\n\nAssistant:"
|
||||
```
|
||||
|
||||
See [prompt validation](https://docs.claude.com/en/api/prompt-validation) and
|
||||
our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting)
|
||||
for more details.
|
||||
|
||||
metadata: An object describing metadata about the request.
|
||||
|
||||
stop_sequences: Sequences that will cause the model to stop generating.
|
||||
|
||||
Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
||||
sequences in the future. By providing the stop_sequences parameter, you may
|
||||
include additional strings that will cause the model to stop generating.
|
||||
|
||||
stream: Whether to incrementally stream the response using server-sent events.
|
||||
|
||||
See [streaming](https://docs.claude.com/en/api/streaming) for details.
|
||||
|
||||
temperature: Amount of randomness injected into the response.
|
||||
|
||||
Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
||||
for analytical / multiple choice, and closer to `1.0` for creative and
|
||||
generative tasks.
|
||||
|
||||
Note that even with `temperature` of `0.0`, the results will not be fully
|
||||
deterministic.
|
||||
|
||||
top_k: Only sample from the top K options for each subsequent token.
|
||||
|
||||
Used to remove "long tail" low probability responses.
|
||||
[Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
top_p: Use nucleus sampling.
|
||||
|
||||
In nucleus sampling, we compute the cumulative distribution over all the options
|
||||
for each subsequent token in decreasing probability order and cut it off once it
|
||||
reaches a particular probability specified by `top_p`. You should either alter
|
||||
`temperature` or `top_p`, but not both.
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
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
|
||||
"""
|
||||
...
|
||||
|
||||
@overload
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
stream: Literal[True],
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncStream[Completion]:
|
||||
"""[Legacy] Create a Text Completion.
|
||||
|
||||
The Text Completions API is a legacy API.
|
||||
|
||||
We recommend using the
|
||||
[Messages API](https://docs.claude.com/en/api/messages) going forward.
|
||||
|
||||
Future models and features will not be compatible with Text Completions. See our
|
||||
[migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-messages)
|
||||
for guidance in migrating from Text Completions to Messages.
|
||||
|
||||
Args:
|
||||
max_tokens_to_sample: The maximum number of tokens to generate before stopping.
|
||||
|
||||
Note that our models may stop _before_ reaching this maximum. This parameter
|
||||
only specifies the absolute maximum number of tokens to generate.
|
||||
|
||||
model: The model that will complete your prompt.\n\nSee
|
||||
[models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
||||
details and options.
|
||||
|
||||
prompt: The prompt that you want Claude to complete.
|
||||
|
||||
For proper response generation you will need to format your prompt using
|
||||
alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
||||
|
||||
```
|
||||
"\n\nHuman: {userQuestion}\n\nAssistant:"
|
||||
```
|
||||
|
||||
See [prompt validation](https://docs.claude.com/en/api/prompt-validation) and
|
||||
our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting)
|
||||
for more details.
|
||||
|
||||
stream: Whether to incrementally stream the response using server-sent events.
|
||||
|
||||
See [streaming](https://docs.claude.com/en/api/streaming) for details.
|
||||
|
||||
metadata: An object describing metadata about the request.
|
||||
|
||||
stop_sequences: Sequences that will cause the model to stop generating.
|
||||
|
||||
Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
||||
sequences in the future. By providing the stop_sequences parameter, you may
|
||||
include additional strings that will cause the model to stop generating.
|
||||
|
||||
temperature: Amount of randomness injected into the response.
|
||||
|
||||
Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
||||
for analytical / multiple choice, and closer to `1.0` for creative and
|
||||
generative tasks.
|
||||
|
||||
Note that even with `temperature` of `0.0`, the results will not be fully
|
||||
deterministic.
|
||||
|
||||
top_k: Only sample from the top K options for each subsequent token.
|
||||
|
||||
Used to remove "long tail" low probability responses.
|
||||
[Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
top_p: Use nucleus sampling.
|
||||
|
||||
In nucleus sampling, we compute the cumulative distribution over all the options
|
||||
for each subsequent token in decreasing probability order and cut it off once it
|
||||
reaches a particular probability specified by `top_p`. You should either alter
|
||||
`temperature` or `top_p`, but not both.
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
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
|
||||
"""
|
||||
...
|
||||
|
||||
@overload
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
stream: bool,
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> Completion | AsyncStream[Completion]:
|
||||
"""[Legacy] Create a Text Completion.
|
||||
|
||||
The Text Completions API is a legacy API.
|
||||
|
||||
We recommend using the
|
||||
[Messages API](https://docs.claude.com/en/api/messages) going forward.
|
||||
|
||||
Future models and features will not be compatible with Text Completions. See our
|
||||
[migration guide](https://docs.claude.com/en/api/migrating-from-text-completions-to-messages)
|
||||
for guidance in migrating from Text Completions to Messages.
|
||||
|
||||
Args:
|
||||
max_tokens_to_sample: The maximum number of tokens to generate before stopping.
|
||||
|
||||
Note that our models may stop _before_ reaching this maximum. This parameter
|
||||
only specifies the absolute maximum number of tokens to generate.
|
||||
|
||||
model: The model that will complete your prompt.\n\nSee
|
||||
[models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
||||
details and options.
|
||||
|
||||
prompt: The prompt that you want Claude to complete.
|
||||
|
||||
For proper response generation you will need to format your prompt using
|
||||
alternating `\n\nHuman:` and `\n\nAssistant:` conversational turns. For example:
|
||||
|
||||
```
|
||||
"\n\nHuman: {userQuestion}\n\nAssistant:"
|
||||
```
|
||||
|
||||
See [prompt validation](https://docs.claude.com/en/api/prompt-validation) and
|
||||
our guide to [prompt design](https://docs.claude.com/en/docs/intro-to-prompting)
|
||||
for more details.
|
||||
|
||||
stream: Whether to incrementally stream the response using server-sent events.
|
||||
|
||||
See [streaming](https://docs.claude.com/en/api/streaming) for details.
|
||||
|
||||
metadata: An object describing metadata about the request.
|
||||
|
||||
stop_sequences: Sequences that will cause the model to stop generating.
|
||||
|
||||
Our models stop on `"\n\nHuman:"`, and may include additional built-in stop
|
||||
sequences in the future. By providing the stop_sequences parameter, you may
|
||||
include additional strings that will cause the model to stop generating.
|
||||
|
||||
temperature: Amount of randomness injected into the response.
|
||||
|
||||
Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
||||
for analytical / multiple choice, and closer to `1.0` for creative and
|
||||
generative tasks.
|
||||
|
||||
Note that even with `temperature` of `0.0`, the results will not be fully
|
||||
deterministic.
|
||||
|
||||
top_k: Only sample from the top K options for each subsequent token.
|
||||
|
||||
Used to remove "long tail" low probability responses.
|
||||
[Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
top_p: Use nucleus sampling.
|
||||
|
||||
In nucleus sampling, we compute the cumulative distribution over all the options
|
||||
for each subsequent token in decreasing probability order and cut it off once it
|
||||
reaches a particular probability specified by `top_p`. You should either alter
|
||||
`temperature` or `top_p`, but not both.
|
||||
|
||||
Recommended for advanced use cases only. You usually only need to use
|
||||
`temperature`.
|
||||
|
||||
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
|
||||
"""
|
||||
...
|
||||
|
||||
@required_args(["max_tokens_to_sample", "model", "prompt"], ["max_tokens_to_sample", "model", "prompt", "stream"])
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
max_tokens_to_sample: int,
|
||||
model: ModelParam,
|
||||
prompt: str,
|
||||
metadata: MetadataParam | Omit = omit,
|
||||
stop_sequences: SequenceNotStr[str] | Omit = omit,
|
||||
stream: Literal[False] | Literal[True] | Omit = omit,
|
||||
temperature: float | Omit = omit,
|
||||
top_k: int | Omit = omit,
|
||||
top_p: float | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> Completion | AsyncStream[Completion]:
|
||||
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
|
||||
timeout = 600
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return await self._post(
|
||||
"/v1/complete",
|
||||
body=await async_maybe_transform(
|
||||
{
|
||||
"max_tokens_to_sample": max_tokens_to_sample,
|
||||
"model": model,
|
||||
"prompt": prompt,
|
||||
"metadata": metadata,
|
||||
"stop_sequences": stop_sequences,
|
||||
"stream": stream,
|
||||
"temperature": temperature,
|
||||
"top_k": top_k,
|
||||
"top_p": top_p,
|
||||
},
|
||||
completion_create_params.CompletionCreateParamsStreaming
|
||||
if stream
|
||||
else completion_create_params.CompletionCreateParamsNonStreaming,
|
||||
),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=Completion,
|
||||
stream=stream or False,
|
||||
stream_cls=AsyncStream[Completion],
|
||||
)
|
||||
|
||||
|
||||
class CompletionsWithRawResponse:
|
||||
def __init__(self, completions: Completions) -> None:
|
||||
self._completions = completions
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
completions.create,
|
||||
)
|
||||
|
||||
|
||||
class AsyncCompletionsWithRawResponse:
|
||||
def __init__(self, completions: AsyncCompletions) -> None:
|
||||
self._completions = completions
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
completions.create,
|
||||
)
|
||||
|
||||
|
||||
class CompletionsWithStreamingResponse:
|
||||
def __init__(self, completions: Completions) -> None:
|
||||
self._completions = completions
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
completions.create,
|
||||
)
|
||||
|
||||
|
||||
class AsyncCompletionsWithStreamingResponse:
|
||||
def __init__(self, completions: AsyncCompletions) -> None:
|
||||
self._completions = completions
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
completions.create,
|
||||
)
|
||||
@@ -0,0 +1,35 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from .batches import (
|
||||
Batches,
|
||||
AsyncBatches,
|
||||
BatchesWithRawResponse,
|
||||
AsyncBatchesWithRawResponse,
|
||||
BatchesWithStreamingResponse,
|
||||
AsyncBatchesWithStreamingResponse,
|
||||
)
|
||||
from .messages import (
|
||||
DEPRECATED_MODELS,
|
||||
Messages,
|
||||
AsyncMessages,
|
||||
MessagesWithRawResponse,
|
||||
AsyncMessagesWithRawResponse,
|
||||
MessagesWithStreamingResponse,
|
||||
AsyncMessagesWithStreamingResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Batches",
|
||||
"AsyncBatches",
|
||||
"BatchesWithRawResponse",
|
||||
"AsyncBatchesWithRawResponse",
|
||||
"BatchesWithStreamingResponse",
|
||||
"AsyncBatchesWithStreamingResponse",
|
||||
"Messages",
|
||||
"AsyncMessages",
|
||||
"MessagesWithRawResponse",
|
||||
"AsyncMessagesWithRawResponse",
|
||||
"MessagesWithStreamingResponse",
|
||||
"AsyncMessagesWithStreamingResponse",
|
||||
"DEPRECATED_MODELS",
|
||||
]
|
||||
@@ -0,0 +1,714 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable
|
||||
|
||||
import httpx
|
||||
|
||||
from ... import _legacy_response
|
||||
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
|
||||
from ..._utils import maybe_transform, async_maybe_transform
|
||||
from ..._compat import cached_property
|
||||
from ..._resource import SyncAPIResource, AsyncAPIResource
|
||||
from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from ...pagination import SyncPage, AsyncPage
|
||||
from ..._exceptions import AnthropicError
|
||||
from ..._base_client import AsyncPaginator, make_request_options
|
||||
from ...types.messages import 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
|
||||
from ...types.messages.message_batch_individual_response import MessageBatchIndividualResponse
|
||||
|
||||
__all__ = ["Batches", "AsyncBatches"]
|
||||
|
||||
|
||||
class Batches(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> BatchesWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return BatchesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> BatchesWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return BatchesWithStreamingResponse(self)
|
||||
|
||||
def create(
|
||||
self,
|
||||
*,
|
||||
requests: Iterable[batch_create_params.Request],
|
||||
# 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,
|
||||
) -> MessageBatch:
|
||||
"""
|
||||
Send a batch of Message creation requests.
|
||||
|
||||
The Message Batches API can be used to process multiple Messages API requests at
|
||||
once. Once a Message Batch is created, it begins processing immediately. Batches
|
||||
can take up to 24 hours to complete.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
requests: List of requests for prompt completion. Each is an individual request to create
|
||||
a Message.
|
||||
|
||||
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
|
||||
"""
|
||||
return self._post(
|
||||
"/v1/messages/batches",
|
||||
body=maybe_transform({"requests": requests}, batch_create_params.BatchCreateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=MessageBatch,
|
||||
)
|
||||
|
||||
def retrieve(
|
||||
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,
|
||||
) -> MessageBatch:
|
||||
"""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.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._get(
|
||||
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=MessageBatch,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
# 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,
|
||||
) -> SyncPage[MessageBatch]:
|
||||
"""List all Message Batches within a Workspace.
|
||||
|
||||
Most recently created batches are
|
||||
returned first.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
return self._get_api_list(
|
||||
"/v1/messages/batches",
|
||||
page=SyncPage[MessageBatch],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
batch_list_params.BatchListParams,
|
||||
),
|
||||
),
|
||||
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:
|
||||
"""
|
||||
Delete a Message Batch.
|
||||
|
||||
Message Batches can only be deleted once they've finished processing. If you'd
|
||||
like to delete an in-progress batch, you must first cancel it.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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,
|
||||
*,
|
||||
# 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,
|
||||
) -> MessageBatch:
|
||||
"""Batches may be canceled any time before processing ends.
|
||||
|
||||
Once cancellation is
|
||||
initiated, the batch enters a `canceling` state, at which time the system may
|
||||
complete any in-progress, non-interruptible requests before finalizing
|
||||
cancellation.
|
||||
|
||||
The number of canceled requests is specified in `request_counts`. To determine
|
||||
which requests were canceled, check the individual results within the batch.
|
||||
Note that cancellation may not result in any canceled requests if they were
|
||||
non-interruptible.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._post(
|
||||
f"/v1/messages/batches/{message_batch_id}/cancel",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=MessageBatch,
|
||||
)
|
||||
|
||||
def results(
|
||||
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,
|
||||
) -> JSONLDecoder[MessageBatchIndividualResponse]:
|
||||
"""
|
||||
Streams the results of a Message Batch as a `.jsonl` file.
|
||||
|
||||
Each line in the file is a JSON object containing the result of a single request
|
||||
in the Message Batch. Results are not guaranteed to be in the same order as
|
||||
requests. Use the `custom_id` field to match results to requests.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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}")
|
||||
|
||||
batch = self.retrieve(message_batch_id=message_batch_id)
|
||||
if not batch.results_url:
|
||||
raise AnthropicError(
|
||||
f"No `results_url` for the given batch; Has it finished processing? {batch.processing_status}"
|
||||
)
|
||||
|
||||
extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
|
||||
return self._get(
|
||||
batch.results_url,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=JSONLDecoder[MessageBatchIndividualResponse],
|
||||
stream=True,
|
||||
)
|
||||
|
||||
|
||||
class AsyncBatches(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncBatchesWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncBatchesWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncBatchesWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncBatchesWithStreamingResponse(self)
|
||||
|
||||
async def create(
|
||||
self,
|
||||
*,
|
||||
requests: Iterable[batch_create_params.Request],
|
||||
# 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,
|
||||
) -> MessageBatch:
|
||||
"""
|
||||
Send a batch of Message creation requests.
|
||||
|
||||
The Message Batches API can be used to process multiple Messages API requests at
|
||||
once. Once a Message Batch is created, it begins processing immediately. Batches
|
||||
can take up to 24 hours to complete.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
requests: List of requests for prompt completion. Each is an individual request to create
|
||||
a Message.
|
||||
|
||||
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
|
||||
"""
|
||||
return await self._post(
|
||||
"/v1/messages/batches",
|
||||
body=await async_maybe_transform({"requests": requests}, batch_create_params.BatchCreateParams),
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=MessageBatch,
|
||||
)
|
||||
|
||||
async def retrieve(
|
||||
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,
|
||||
) -> MessageBatch:
|
||||
"""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.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._get(
|
||||
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=MessageBatch,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncPaginator[MessageBatch, AsyncPage[MessageBatch]]:
|
||||
"""List all Message Batches within a Workspace.
|
||||
|
||||
Most recently created batches are
|
||||
returned first.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
return self._get_api_list(
|
||||
"/v1/messages/batches",
|
||||
page=AsyncPage[MessageBatch],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
batch_list_params.BatchListParams,
|
||||
),
|
||||
),
|
||||
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:
|
||||
"""
|
||||
Delete a Message Batch.
|
||||
|
||||
Message Batches can only be deleted once they've finished processing. If you'd
|
||||
like to delete an in-progress batch, you must first cancel it.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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,
|
||||
*,
|
||||
# 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,
|
||||
) -> MessageBatch:
|
||||
"""Batches may be canceled any time before processing ends.
|
||||
|
||||
Once cancellation is
|
||||
initiated, the batch enters a `canceling` state, at which time the system may
|
||||
complete any in-progress, non-interruptible requests before finalizing
|
||||
cancellation.
|
||||
|
||||
The number of canceled requests is specified in `request_counts`. To determine
|
||||
which requests were canceled, check the individual results within the batch.
|
||||
Note that cancellation may not result in any canceled requests if they were
|
||||
non-interruptible.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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._post(
|
||||
f"/v1/messages/batches/{message_batch_id}/cancel",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=MessageBatch,
|
||||
)
|
||||
|
||||
async def results(
|
||||
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,
|
||||
) -> AsyncJSONLDecoder[MessageBatchIndividualResponse]:
|
||||
"""
|
||||
Streams the results of a Message Batch as a `.jsonl` file.
|
||||
|
||||
Each line in the file is a JSON object containing the result of a single request
|
||||
in the Message Batch. Results are not guaranteed to be in the same order as
|
||||
requests. Use the `custom_id` field to match results to requests.
|
||||
|
||||
Learn more about the Message Batches API in our
|
||||
[user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
|
||||
|
||||
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}")
|
||||
|
||||
batch = await self.retrieve(message_batch_id=message_batch_id)
|
||||
if not batch.results_url:
|
||||
raise AnthropicError(
|
||||
f"No `results_url` for the given batch; Has it finished processing? {batch.processing_status}"
|
||||
)
|
||||
|
||||
extra_headers = {"Accept": "application/binary", **(extra_headers or {})}
|
||||
return await self._get(
|
||||
batch.results_url,
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=AsyncJSONLDecoder[MessageBatchIndividualResponse],
|
||||
stream=True,
|
||||
)
|
||||
|
||||
|
||||
class BatchesWithRawResponse:
|
||||
def __init__(self, batches: Batches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = _legacy_response.to_raw_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
class AsyncBatchesWithRawResponse:
|
||||
def __init__(self, batches: AsyncBatches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = _legacy_response.async_to_raw_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
class BatchesWithStreamingResponse:
|
||||
def __init__(self, batches: Batches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = to_streamed_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
batches.list,
|
||||
)
|
||||
self.delete = to_streamed_response_wrapper(
|
||||
batches.delete,
|
||||
)
|
||||
self.cancel = to_streamed_response_wrapper(
|
||||
batches.cancel,
|
||||
)
|
||||
|
||||
|
||||
class AsyncBatchesWithStreamingResponse:
|
||||
def __init__(self, batches: AsyncBatches) -> None:
|
||||
self._batches = batches
|
||||
|
||||
self.create = async_to_streamed_response_wrapper(
|
||||
batches.create,
|
||||
)
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
batches.retrieve,
|
||||
)
|
||||
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,
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,331 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
|
||||
import httpx
|
||||
|
||||
from .. import _legacy_response
|
||||
from ..types import model_list_params
|
||||
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
|
||||
from .._utils import is_given, maybe_transform, strip_not_given
|
||||
from .._compat import cached_property
|
||||
from .._resource import SyncAPIResource, AsyncAPIResource
|
||||
from .._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
||||
from ..pagination import SyncPage, AsyncPage
|
||||
from .._base_client import AsyncPaginator, make_request_options
|
||||
from ..types.model_info import ModelInfo
|
||||
from ..types.anthropic_beta_param import AnthropicBetaParam
|
||||
|
||||
__all__ = ["Models", "AsyncModels"]
|
||||
|
||||
|
||||
class Models(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> ModelsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return ModelsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> ModelsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return ModelsWithStreamingResponse(self)
|
||||
|
||||
def retrieve(
|
||||
self,
|
||||
model_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> ModelInfo:
|
||||
"""
|
||||
Get a specific model.
|
||||
|
||||
The Models API response can be used to determine information about a specific
|
||||
model or resolve a model alias to a model ID.
|
||||
|
||||
Args:
|
||||
model_id: Model identifier or alias.
|
||||
|
||||
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 model_id:
|
||||
raise ValueError(f"Expected a non-empty value for `model_id` but received {model_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return self._get(
|
||||
f"/v1/models/{model_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ModelInfo,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> SyncPage[ModelInfo]:
|
||||
"""
|
||||
List available models.
|
||||
|
||||
The Models API response can be used to determine which models are available for
|
||||
use in the API. More recently released models are listed first.
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return self._get_api_list(
|
||||
"/v1/models",
|
||||
page=SyncPage[ModelInfo],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
model_list_params.ModelListParams,
|
||||
),
|
||||
),
|
||||
model=ModelInfo,
|
||||
)
|
||||
|
||||
|
||||
class AsyncModels(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncModelsWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncModelsWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncModelsWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
||||
"""
|
||||
return AsyncModelsWithStreamingResponse(self)
|
||||
|
||||
async def retrieve(
|
||||
self,
|
||||
model_id: str,
|
||||
*,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> ModelInfo:
|
||||
"""
|
||||
Get a specific model.
|
||||
|
||||
The Models API response can be used to determine information about a specific
|
||||
model or resolve a model alias to a model ID.
|
||||
|
||||
Args:
|
||||
model_id: Model identifier or alias.
|
||||
|
||||
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 model_id:
|
||||
raise ValueError(f"Expected a non-empty value for `model_id` but received {model_id!r}")
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return await self._get(
|
||||
f"/v1/models/{model_id}",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
||||
),
|
||||
cast_to=ModelInfo,
|
||||
)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
after_id: str | Omit = omit,
|
||||
before_id: str | Omit = omit,
|
||||
limit: int | Omit = omit,
|
||||
betas: List[AnthropicBetaParam] | Omit = omit,
|
||||
# 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,
|
||||
) -> AsyncPaginator[ModelInfo, AsyncPage[ModelInfo]]:
|
||||
"""
|
||||
List available models.
|
||||
|
||||
The Models API response can be used to determine which models are available for
|
||||
use in the API. More recently released models are listed first.
|
||||
|
||||
Args:
|
||||
after_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately after this object.
|
||||
|
||||
before_id: ID of the object to use as a cursor for pagination. When provided, returns the
|
||||
page of results immediately before this object.
|
||||
|
||||
limit: Number of items to return per page.
|
||||
|
||||
Defaults to `20`. Ranges from `1` to `1000`.
|
||||
|
||||
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
|
||||
"""
|
||||
extra_headers = {
|
||||
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else not_given}),
|
||||
**(extra_headers or {}),
|
||||
}
|
||||
return self._get_api_list(
|
||||
"/v1/models",
|
||||
page=AsyncPage[ModelInfo],
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform(
|
||||
{
|
||||
"after_id": after_id,
|
||||
"before_id": before_id,
|
||||
"limit": limit,
|
||||
},
|
||||
model_list_params.ModelListParams,
|
||||
),
|
||||
),
|
||||
model=ModelInfo,
|
||||
)
|
||||
|
||||
|
||||
class ModelsWithRawResponse:
|
||||
def __init__(self, models: Models) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = _legacy_response.to_raw_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.to_raw_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncModelsWithRawResponse:
|
||||
def __init__(self, models: AsyncModels) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = _legacy_response.async_to_raw_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
|
||||
|
||||
class ModelsWithStreamingResponse:
|
||||
def __init__(self, models: Models) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = to_streamed_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = to_streamed_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncModelsWithStreamingResponse:
|
||||
def __init__(self, models: AsyncModels) -> None:
|
||||
self._models = models
|
||||
|
||||
self.retrieve = async_to_streamed_response_wrapper(
|
||||
models.retrieve,
|
||||
)
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
models.list,
|
||||
)
|
||||
Reference in New Issue
Block a user