diff --git a/src/anthropic/_models.py b/src/anthropic/_models.py index 5d95bb4b..eb7ce3bd 100644 --- a/src/anthropic/_models.py +++ b/src/anthropic/_models.py @@ -643,6 +643,14 @@ def validate_type(*, type_: type[_T], value: object) -> _T: return cast(_T, _validate_non_model_type(type_=type_, value=value)) +def set_pydantic_config(typ: Any, config: pydantic.ConfigDict) -> None: + """Add a pydantic config for the given type. + + Note: this is a no-op on Pydantic v1. + """ + setattr(typ, "__pydantic_config__", config) # noqa: B010 + + # our use of subclasssing here causes weirdness for type checkers, # so we just pretend that we don't subclass if TYPE_CHECKING: diff --git a/src/anthropic/types/image_block_param.py b/src/anthropic/types/image_block_param.py index 45236832..d7f46fa9 100644 --- a/src/anthropic/types/image_block_param.py +++ b/src/anthropic/types/image_block_param.py @@ -7,6 +7,7 @@ from .._types import Base64FileInput from .._utils import PropertyInfo +from .._models import set_pydantic_config __all__ = ["ImageBlockParam", "Source"] @@ -19,6 +20,9 @@ class Source(TypedDict, total=False): type: Required[Literal["base64"]] +set_pydantic_config(Source, {"arbitrary_types_allowed": True}) + + class ImageBlockParam(TypedDict, total=False): source: Required[Source]