From: =?utf-8?q?Antoine_Beaupr=C3=A9?= Date: Tue, 6 Jan 2026 14:12:20 -0500 Subject: make jiter optional --- src/anthropic/lib/streaming/_beta_messages.py | 5 ++++- src/anthropic/lib/streaming/_beta_types.py | 7 +++++-- src/anthropic/lib/streaming/_messages.py | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) Index: b/src/anthropic/lib/streaming/_beta_messages.py =================================================================== --- a/src/anthropic/lib/streaming/_beta_messages.py 2026-09-25 22:16:42.322730367 -0400 +++ b/src/anthropic/lib/streaming/_beta_messages.py 2026-09-25 22:16:42.314730365 -0400 @@ -502,7 +502,10 @@ def accumulate_event( content.text += event.delta.text elif event.delta.type == "input_json_delta": if isinstance(content, TRACKS_TOOL_INPUT): - from jiter import from_json + try: + from jiter import from_json + except ImportError: + from pydantic_core import from_json json_buf = json_bufs.get(event.index, b"") json_buf += bytes(event.delta.partial_json, "utf-8") Index: b/src/anthropic/lib/streaming/_beta_types.py =================================================================== --- a/src/anthropic/lib/streaming/_beta_types.py 2026-09-25 22:16:42.322730367 -0400 +++ b/src/anthropic/lib/streaming/_beta_types.py 2026-09-25 22:16:42.314730365 -0400 @@ -1,7 +1,10 @@ from typing import TYPE_CHECKING, Any, Dict, Union, Generic, cast from typing_extensions import List, Literal, Annotated -import jiter +try: + from jiter import from_json +except ImportError: + from pydantic_core import from_json from ..._models import BaseModel, GenericModel, UnionDiscriminator from ...types.beta import ( @@ -27,7 +30,7 @@ class ParsedBetaTextEvent(BaseModel): """The entire accumulated text""" def parsed_snapshot(self) -> Dict[str, Any]: - return cast(Dict[str, Any], jiter.from_json(self.snapshot.encode("utf-8"), partial_mode="trailing-strings")) + return cast(Dict[str, Any], from_json(self.snapshot.encode("utf-8"), partial_mode="trailing-strings")) class BetaCitationEvent(BaseModel): Index: b/src/anthropic/lib/streaming/_messages.py =================================================================== --- a/src/anthropic/lib/streaming/_messages.py 2026-09-25 22:16:42.322730367 -0400 +++ b/src/anthropic/lib/streaming/_messages.py 2026-09-25 22:16:42.314730365 -0400 @@ -477,7 +477,10 @@ def accumulate_event( content.text += event.delta.text elif event.delta.type == "input_json_delta": if isinstance(content, TRACKS_TOOL_INPUT): - from jiter import from_json + try: + from jiter import from_json + except ImportError: + from pydantic_core import from_json json_buf = json_bufs.get(event.index, b"") json_buf += bytes(event.delta.partial_json, "utf-8") Index: b/src/anthropic/lib/streaming/_types.py =================================================================== --- a/src/anthropic/lib/streaming/_types.py 2026-09-25 22:16:42.322730367 -0400 +++ b/src/anthropic/lib/streaming/_types.py 2026-09-25 22:16:42.314730365 -0400 @@ -1,7 +1,10 @@ from typing import TYPE_CHECKING, Any, Dict, Union, Generic, cast from typing_extensions import List, Literal, Annotated -import jiter +try: + from jiter import from_json +except ImportError: + from pydantic_core import from_json from ...types import ( Message,