diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index fe87cd9..26548ff 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.43.0"
+ ".": "0.43.1"
}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5030db8..2ffc506 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,21 @@
# Changelog
+## 0.43.1 (2025-01-17)
+
+Full Changelog: [v0.43.0...v0.43.1](https://github.com/anthropics/anthropic-sdk-python/compare/v0.43.0...v0.43.1)
+
+### Bug Fixes
+
+* **docs:** correct results return type ([69ad511](https://github.com/anthropics/anthropic-sdk-python/commit/69ad5112596f6e9aaf5cd2d495cb57516f2afbd4))
+
+
+### Chores
+
+* **internal:** bump pyright dependency ([#822](https://github.com/anthropics/anthropic-sdk-python/issues/822)) ([f8ddb90](https://github.com/anthropics/anthropic-sdk-python/commit/f8ddb90112a432a750fd4123c747ca581cff54ab))
+* **internal:** fix lint ([483cc27](https://github.com/anthropics/anthropic-sdk-python/commit/483cc277b66cb5b1a767e9d91347f22bcf69dc28))
+* **streaming:** add runtime type check for better error messages ([#826](https://github.com/anthropics/anthropic-sdk-python/issues/826)) ([cf69e09](https://github.com/anthropics/anthropic-sdk-python/commit/cf69e091d230aa0befb6ace74e64357b1cf2e4cd))
+* **types:** add more discriminator metadata ([#825](https://github.com/anthropics/anthropic-sdk-python/issues/825)) ([d0de8e5](https://github.com/anthropics/anthropic-sdk-python/commit/d0de8e564038cc6f801dc663b1938ac571ab47be))
+
## 0.43.0 (2025-01-14)
Full Changelog: [v0.42.0...v0.43.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.42.0...v0.43.0)
diff --git a/api.md b/api.md
index 7f5698f..44f97ac 100644
--- a/api.md
+++ b/api.md
@@ -95,7 +95,7 @@ Methods:
- client.messages.batches.list(\*\*params) -> SyncPage[MessageBatch]
- client.messages.batches.delete(message_batch_id) -> DeletedMessageBatch
- client.messages.batches.cancel(message_batch_id) -> MessageBatch
-- client.messages.batches.results(message_batch_id) -> BinaryAPIResponse
+- client.messages.batches.results(message_batch_id) -> JSONLDecoder[MessageBatchIndividualResponse]
# Models
@@ -218,4 +218,4 @@ Methods:
- client.beta.messages.batches.list(\*\*params) -> SyncPage[BetaMessageBatch]
- client.beta.messages.batches.delete(message_batch_id) -> BetaDeletedMessageBatch
- client.beta.messages.batches.cancel(message_batch_id) -> BetaMessageBatch
-- client.beta.messages.batches.results(message_batch_id) -> BinaryAPIResponse
+- client.beta.messages.batches.results(message_batch_id) -> JSONLDecoder[MessageBatchIndividualResponse]
diff --git a/pyproject.toml b/pyproject.toml
index aca83df..8c21200 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "anthropic"
-version = "0.43.0"
+version = "0.43.1"
description = "The official Python library for the anthropic API"
dynamic = ["readme"]
license = "MIT"
diff --git a/requirements-dev.lock b/requirements-dev.lock
index e57c739..2aba34e 100644
--- a/requirements-dev.lock
+++ b/requirements-dev.lock
@@ -91,7 +91,7 @@ pydantic-core==2.27.1
# via pydantic
pygments==2.18.0
# via rich
-pyright==1.1.391
+pyright==1.1.392.post0
pytest==8.3.3
# via pytest-asyncio
pytest-asyncio==0.24.0
diff --git a/src/anthropic/_legacy_response.py b/src/anthropic/_legacy_response.py
index 98ce297..dd1db8e 100644
--- a/src/anthropic/_legacy_response.py
+++ b/src/anthropic/_legacy_response.py
@@ -294,7 +294,9 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
if origin == LegacyAPIResponse:
raise RuntimeError("Unexpected state - cast_to is `APIResponse`")
- if inspect.isclass(origin) and issubclass(origin, httpx.Response):
+ if inspect.isclass(
+ origin # pyright: ignore[reportUnknownArgumentType]
+ ) and issubclass(origin, httpx.Response):
# Because of the invariance of our ResponseT TypeVar, users can subclass httpx.Response
# and pass that class to our request functions. We cannot change the variance to be either
# covariant or contravariant as that makes our usage of ResponseT illegal. We could construct
@@ -304,7 +306,13 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
raise ValueError(f"Subclasses of httpx.Response cannot be passed to `cast_to`")
return cast(R, response)
- if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel):
+ if (
+ inspect.isclass(
+ origin # pyright: ignore[reportUnknownArgumentType]
+ )
+ and not issubclass(origin, BaseModel)
+ and issubclass(origin, pydantic.BaseModel)
+ ):
raise TypeError("Pydantic models must subclass our base model type, e.g. `from anthropic import BaseModel`")
if (
diff --git a/src/anthropic/_response.py b/src/anthropic/_response.py
index 8734b1d..830bee5 100644
--- a/src/anthropic/_response.py
+++ b/src/anthropic/_response.py
@@ -226,7 +226,9 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
if origin == APIResponse:
raise RuntimeError("Unexpected state - cast_to is `APIResponse`")
- if inspect.isclass(origin) and issubclass(origin, httpx.Response):
+ if inspect.isclass(
+ origin # pyright: ignore[reportUnknownArgumentType]
+ ) and issubclass(origin, httpx.Response):
# Because of the invariance of our ResponseT TypeVar, users can subclass httpx.Response
# and pass that class to our request functions. We cannot change the variance to be either
# covariant or contravariant as that makes our usage of ResponseT illegal. We could construct
@@ -236,7 +238,13 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
raise ValueError(f"Subclasses of httpx.Response cannot be passed to `cast_to`")
return cast(R, response)
- if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel):
+ if (
+ inspect.isclass(
+ origin # pyright: ignore[reportUnknownArgumentType]
+ )
+ and not issubclass(origin, BaseModel)
+ and issubclass(origin, pydantic.BaseModel)
+ ):
raise TypeError("Pydantic models must subclass our base model type, e.g. `from anthropic import BaseModel`")
if (
diff --git a/src/anthropic/_version.py b/src/anthropic/_version.py
index 6b3c484..7b3b007 100644
--- a/src/anthropic/_version.py
+++ b/src/anthropic/_version.py
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
__title__ = "anthropic"
-__version__ = "0.43.0" # x-release-please-version
+__version__ = "0.43.1" # x-release-please-version
diff --git a/src/anthropic/lib/streaming/_beta_types.py b/src/anthropic/lib/streaming/_beta_types.py
index a2a0bf6..c3ee61f 100644
--- a/src/anthropic/lib/streaming/_beta_types.py
+++ b/src/anthropic/lib/streaming/_beta_types.py
@@ -1,5 +1,5 @@
from typing import Union
-from typing_extensions import Literal
+from typing_extensions import Literal, Annotated
from ..._models import BaseModel
from ...types.beta import (
@@ -12,6 +12,7 @@
BetaRawContentBlockDeltaEvent,
BetaRawContentBlockStartEvent,
)
+from ..._utils._transform import PropertyInfo
class BetaTextEvent(BaseModel):
@@ -53,13 +54,16 @@ class BetaContentBlockStopEvent(BetaRawContentBlockStopEvent):
content_block: BetaContentBlock
-BetaMessageStreamEvent = Union[
- BetaTextEvent,
- BetaInputJsonEvent,
- BetaRawMessageStartEvent,
- BetaRawMessageDeltaEvent,
- BetaMessageStopEvent,
- BetaRawContentBlockStartEvent,
- BetaRawContentBlockDeltaEvent,
- BetaContentBlockStopEvent,
+BetaMessageStreamEvent = Annotated[
+ Union[
+ BetaTextEvent,
+ BetaInputJsonEvent,
+ BetaRawMessageStartEvent,
+ BetaRawMessageDeltaEvent,
+ BetaMessageStopEvent,
+ BetaRawContentBlockStartEvent,
+ BetaRawContentBlockDeltaEvent,
+ BetaContentBlockStopEvent,
+ ],
+ PropertyInfo(discriminator="type"),
]
diff --git a/src/anthropic/lib/streaming/_messages.py b/src/anthropic/lib/streaming/_messages.py
index 590a99d..67fe8f0 100644
--- a/src/anthropic/lib/streaming/_messages.py
+++ b/src/anthropic/lib/streaming/_messages.py
@@ -5,6 +5,7 @@
from typing_extensions import Self, Iterator, Awaitable, AsyncIterator, assert_never
import httpx
+from pydantic import BaseModel
from ._types import (
TextEvent,
@@ -346,6 +347,9 @@ def accumulate_event(
event: RawMessageStreamEvent,
current_snapshot: Message | None,
) -> Message:
+ if not isinstance(event, BaseModel): # pyright: ignore[reportUnnecessaryIsInstance]
+ raise TypeError(f'Unexpected event runtime type - {event}')
+
if current_snapshot is None:
if event.type == "message_start":
return Message.construct(**cast(Any, event.message.to_dict()))
diff --git a/src/anthropic/lib/streaming/_types.py b/src/anthropic/lib/streaming/_types.py
index ab3fa11..59ee779 100644
--- a/src/anthropic/lib/streaming/_types.py
+++ b/src/anthropic/lib/streaming/_types.py
@@ -1,5 +1,5 @@
from typing import Union
-from typing_extensions import Literal
+from typing_extensions import Literal, Annotated
from ...types import (
Message,
@@ -12,6 +12,7 @@
RawContentBlockStopEvent,
)
from ..._models import BaseModel
+from ..._utils._transform import PropertyInfo
class TextEvent(BaseModel):
@@ -53,13 +54,16 @@ class ContentBlockStopEvent(RawContentBlockStopEvent):
content_block: ContentBlock
-MessageStreamEvent = Union[
- TextEvent,
- InputJsonEvent,
- RawMessageStartEvent,
- RawMessageDeltaEvent,
- MessageStopEvent,
- RawContentBlockStartEvent,
- RawContentBlockDeltaEvent,
- ContentBlockStopEvent,
+MessageStreamEvent = Annotated[
+ Union[
+ TextEvent,
+ InputJsonEvent,
+ RawMessageStartEvent,
+ RawMessageDeltaEvent,
+ MessageStopEvent,
+ RawContentBlockStartEvent,
+ RawContentBlockDeltaEvent,
+ ContentBlockStopEvent,
+ ],
+ PropertyInfo(discriminator="type"),
]
diff --git a/src/anthropic/resources/beta/messages/messages.py b/src/anthropic/resources/beta/messages/messages.py
index 7aa8918..3c18dda 100644
--- a/src/anthropic/resources/beta/messages/messages.py
+++ b/src/anthropic/resources/beta/messages/messages.py
@@ -983,7 +983,6 @@ def stream(
stream_cls=Stream[BetaRawMessageStreamEvent],
)
return BetaMessageStreamManager(make_request)
-
def count_tokens(
self,
diff --git a/src/anthropic/types/tool_param.py b/src/anthropic/types/tool_param.py
index 4ad2491..3df6819 100644
--- a/src/anthropic/types/tool_param.py
+++ b/src/anthropic/types/tool_param.py
@@ -16,6 +16,7 @@ class InputSchemaTyped(TypedDict, total=False):
properties: Optional[object]
+
set_pydantic_config(InputSchemaTyped, {"extra": "allow"})
InputSchema: TypeAlias = Union[InputSchemaTyped, Dict[str, object]]