Skip to content

Commit 9aa85c8

Browse files
release: 0.102.0 (#1532)
* feat(internal/types): support eagerly validating pydantic iterators * ci: pin GitHub Actions to commit SHAs Pin all GitHub Actions referenced in generated workflows (both first-party `actions/*` and third-party) to immutable commit SHAs. Updating pinned actions is now a deliberate codegen-side bump rather than implicit on every workflow run. * feat(api): Add BetaManagedAgentsSearchResultBlock types * codegen metadata * chore(api): spec updates * feat(api): Add support for cache diagnostics beta * release: 0.102.0 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
1 parent e8e6f66 commit 9aa85c8

42 files changed

Lines changed: 588 additions & 30 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
runs-on: ${{ github.repository == 'stainless-sdks/anthropic-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
2222
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork)
2323
steps:
24-
- uses: actions/checkout@v6
24+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2525

2626
- name: Install uv
27-
uses: astral-sh/setup-uv@v5
27+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
2828
with:
2929
version: '0.10.2'
3030

@@ -43,10 +43,10 @@ jobs:
4343
id-token: write
4444
runs-on: ${{ github.repository == 'stainless-sdks/anthropic-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
4545
steps:
46-
- uses: actions/checkout@v6
46+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4747

4848
- name: Install uv
49-
uses: astral-sh/setup-uv@v5
49+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
5050
with:
5151
version: '0.10.2'
5252

@@ -61,7 +61,7 @@ jobs:
6161
github.repository == 'stainless-sdks/anthropic-python' &&
6262
!startsWith(github.ref, 'refs/heads/stl/')
6363
id: github-oidc
64-
uses: actions/github-script@v8
64+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
6565
with:
6666
script: core.setOutput('github_token', await core.getIDToken());
6767

@@ -81,10 +81,10 @@ jobs:
8181
runs-on: ${{ github.repository == 'stainless-sdks/anthropic-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
8282
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
8383
steps:
84-
- uses: actions/checkout@v6
84+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
8585

8686
- name: Install uv
87-
uses: astral-sh/setup-uv@v5
87+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
8888
with:
8989
version: '0.10.2'
9090

.github/workflows/create-releases.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
environment: production-release
1515

1616
steps:
17-
- uses: actions/checkout@v6
17+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1818

1919
- uses: stainless-api/trigger-release-please@bb6677c5a04578eec1ccfd9e1913b5b78ed64c61 # v1.4.0
2020
id: release
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Install uv
2626
if: ${{ steps.release.outputs.releases_created }}
27-
uses: astral-sh/setup-uv@v5
27+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
2828
with:
2929
version: '0.9.13'
3030

.github/workflows/detect-breaking-changes.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ jobs:
1515
run: |
1616
echo "FETCH_DEPTH=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_ENV
1717
18-
- uses: actions/checkout@v6
18+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1919
with:
2020
# Ensure we can check out the pull request base in the script below.
2121
fetch-depth: ${{ env.FETCH_DEPTH }}
2222

2323
- name: Install uv
24-
uses: astral-sh/setup-uv@v5
24+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
2525
with:
2626
version: '0.10.2'
2727
- name: Install dependencies

.github/workflows/publish-pypi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
environment: production-release
1212

1313
steps:
14-
- uses: actions/checkout@v6
14+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1515

1616
- name: Install uv
17-
uses: astral-sh/setup-uv@v5
17+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
1818
with:
1919
version: '0.9.13'
2020

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.101.0"
2+
".": "0.102.0"
33
}

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 97
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-0df2c793ea4c3ad955e8e488be39d7041a0a95e2fe144dd69ae4d9fb72835190.yml
3-
openapi_spec_hash: b169b786bdf1f07d7f77f18f7b94abfa
4-
config_hash: ed43b84afda7441f472a59dda6badb05
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-9bc52c052beb11ccfff68e9d96335774c8377f914bcf36278e5774c68aa84e69.yml
3+
openapi_spec_hash: 3a5f6e11b9fda1c165c6f9edbdee7d90
4+
config_hash: ed200254fa6776c7b124706c91c80475

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## 0.102.0 (2026-05-13)
4+
5+
Full Changelog: [v0.101.0...v0.102.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.101.0...v0.102.0)
6+
7+
### Features
8+
9+
* **api:** Add BetaManagedAgentsSearchResultBlock types ([3681f10](https://github.com/anthropics/anthropic-sdk-python/commit/3681f1042608b6be4e5a56e8b52e6a619b9210f4))
10+
* **api:** Add support for cache diagnostics beta ([db51c6c](https://github.com/anthropics/anthropic-sdk-python/commit/db51c6caabb1bede4c2d671a96e6ef88e90ffaba))
11+
* **internal/types:** support eagerly validating pydantic iterators ([68dabb0](https://github.com/anthropics/anthropic-sdk-python/commit/68dabb0e9b11ecd8745b231019e9bf788b72101a))
12+
13+
14+
### Chores
15+
16+
* **api:** spec updates ([d579133](https://github.com/anthropics/anthropic-sdk-python/commit/d5791337776ba9d4876d3683e6ab9419365be9d3))
17+
318
## 0.101.0 (2026-05-11)
419

520
Full Changelog: [v0.100.0...v0.101.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.100.0...v0.101.0)

api.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ from anthropic.types.beta import (
315315
BetaBashCodeExecutionToolResultErrorParam,
316316
BetaCacheControlEphemeral,
317317
BetaCacheCreation,
318+
BetaCacheMissMessagesChanged,
319+
BetaCacheMissModelChanged,
320+
BetaCacheMissPreviousMessageNotFound,
321+
BetaCacheMissSystemChanged,
322+
BetaCacheMissToolsChanged,
323+
BetaCacheMissUnavailable,
318324
BetaCitationCharLocation,
319325
BetaCitationCharLocationParam,
320326
BetaCitationConfig,
@@ -362,6 +368,8 @@ from anthropic.types.beta import (
362368
BetaContextManagementConfig,
363369
BetaContextManagementResponse,
364370
BetaCountTokensContextManagementResponse,
371+
BetaDiagnostics,
372+
BetaDiagnosticsParam,
365373
BetaDirectCaller,
366374
BetaDocumentBlock,
367375
BetaEncryptedCodeExecutionResultBlock,
@@ -689,6 +697,9 @@ from anthropic.types.beta.sessions import (
689697
BetaManagedAgentsRetryStatusExhausted,
690698
BetaManagedAgentsRetryStatusRetrying,
691699
BetaManagedAgentsRetryStatusTerminal,
700+
BetaManagedAgentsSearchResultBlock,
701+
BetaManagedAgentsSearchResultCitations,
702+
BetaManagedAgentsSearchResultContent,
692703
BetaManagedAgentsSendSessionEvents,
693704
BetaManagedAgentsSessionDeletedEvent,
694705
BetaManagedAgentsSessionEndTurn,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "anthropic"
3-
version = "0.101.0"
3+
version = "0.102.0"
44
description = "The official Python library for the anthropic API"
55
dynamic = ["readme"]
66
license = "MIT"

src/anthropic/_models.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
ClassVar,
2626
Protocol,
2727
Required,
28+
Annotated,
2829
ParamSpec,
30+
TypeAlias,
2931
TypedDict,
3032
TypeGuard,
3133
final,
@@ -79,7 +81,15 @@
7981
from ._constants import RAW_RESPONSE_HEADER
8082

8183
if TYPE_CHECKING:
84+
from pydantic import GetCoreSchemaHandler, ValidatorFunctionWrapHandler
85+
from pydantic_core import CoreSchema, core_schema
8286
from pydantic_core.core_schema import ModelField, ModelSchema, LiteralSchema, ModelFieldsSchema
87+
else:
88+
try:
89+
from pydantic_core import CoreSchema, core_schema
90+
except ImportError:
91+
CoreSchema = None
92+
core_schema = None
8393

8494
__all__ = ["BaseModel", "GenericModel"]
8595

@@ -412,6 +422,76 @@ def model_dump_json(
412422
)
413423

414424

425+
class _EagerIterable(list[_T], Generic[_T]):
426+
"""
427+
Accepts any Iterable[T] input (including generators), consumes it
428+
eagerly, and validates all items upfront.
429+
430+
Validation preserves the original container type where possible
431+
(e.g. a set[T] stays a set[T]). Serialization (model_dump / JSON)
432+
always emits a list — round-tripping through model_dump() will not
433+
restore the original container type.
434+
"""
435+
436+
@classmethod
437+
def __get_pydantic_core_schema__(
438+
cls,
439+
source_type: Any,
440+
handler: GetCoreSchemaHandler,
441+
) -> CoreSchema:
442+
(item_type,) = get_args(source_type) or (Any,)
443+
item_schema: CoreSchema = handler.generate_schema(item_type)
444+
list_of_items_schema: CoreSchema = core_schema.list_schema(item_schema)
445+
446+
return core_schema.no_info_wrap_validator_function(
447+
cls._validate,
448+
list_of_items_schema,
449+
serialization=core_schema.plain_serializer_function_ser_schema(
450+
cls._serialize,
451+
info_arg=False,
452+
),
453+
)
454+
455+
@staticmethod
456+
def _validate(v: Iterable[_T], handler: "ValidatorFunctionWrapHandler") -> Any:
457+
original_type: type[Any] = type(v)
458+
459+
# Normalize to list so list_schema can validate each item
460+
if isinstance(v, list):
461+
items: list[_T] = v
462+
else:
463+
try:
464+
items = list(v)
465+
except TypeError as e:
466+
raise TypeError("Value is not iterable") from e
467+
468+
# Validate items against the inner schema
469+
validated: list[_T] = handler(items)
470+
471+
# Reconstruct original container type
472+
if original_type is list:
473+
return validated
474+
# str(list) produces the list's repr, not a string built from items,
475+
# so skip reconstruction for str and its subclasses.
476+
if issubclass(original_type, str):
477+
return validated
478+
try:
479+
return original_type(validated)
480+
except (TypeError, ValueError):
481+
# If the type cannot be reconstructed, just return the validated list
482+
return validated
483+
484+
@staticmethod
485+
def _serialize(v: Iterable[_T]) -> list[_T]:
486+
"""Always serialize as a list so Pydantic's JSON encoder is happy."""
487+
if isinstance(v, list):
488+
return v
489+
return list(v)
490+
491+
492+
EagerIterable: TypeAlias = Annotated[Iterable[_T], _EagerIterable]
493+
494+
415495
def _construct_field(value: object, field: FieldInfo, key: str) -> object:
416496
if value is None:
417497
return field_get_default(field)

0 commit comments

Comments
 (0)