From 2beaabd0ee375f7e1012c91d813c4a2567fe8fba Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 10:10:55 +0000 Subject: [PATCH 1/7] docs(raw responses): fix duplicate `the` (#828) --- src/anthropic/resources/beta/beta.py | 4 ++-- src/anthropic/resources/beta/messages/batches.py | 4 ++-- src/anthropic/resources/beta/messages/messages.py | 4 ++-- src/anthropic/resources/beta/models.py | 4 ++-- src/anthropic/resources/completions.py | 4 ++-- src/anthropic/resources/messages/batches.py | 4 ++-- src/anthropic/resources/messages/messages.py | 4 ++-- src/anthropic/resources/models.py | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/anthropic/resources/beta/beta.py b/src/anthropic/resources/beta/beta.py index 8293782..ae5c7d9 100644 --- a/src/anthropic/resources/beta/beta.py +++ b/src/anthropic/resources/beta/beta.py @@ -36,7 +36,7 @@ def messages(self) -> Messages: @cached_property def with_raw_response(self) -> BetaWithRawResponse: """ - This property can be used as a prefix for any HTTP method call to return the + 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 @@ -65,7 +65,7 @@ def messages(self) -> AsyncMessages: @cached_property def with_raw_response(self) -> AsyncBetaWithRawResponse: """ - This property can be used as a prefix for any HTTP method call to return the + 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 diff --git a/src/anthropic/resources/beta/messages/batches.py b/src/anthropic/resources/beta/messages/batches.py index 0e868f0..3a13812 100644 --- a/src/anthropic/resources/beta/messages/batches.py +++ b/src/anthropic/resources/beta/messages/batches.py @@ -35,7 +35,7 @@ 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 + 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 @@ -404,7 +404,7 @@ 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 + 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 diff --git a/src/anthropic/resources/beta/messages/messages.py b/src/anthropic/resources/beta/messages/messages.py index 3c18dda..b3da866 100644 --- a/src/anthropic/resources/beta/messages/messages.py +++ b/src/anthropic/resources/beta/messages/messages.py @@ -56,7 +56,7 @@ def batches(self) -> Batches: @cached_property def with_raw_response(self) -> MessagesWithRawResponse: """ - This property can be used as a prefix for any HTTP method call to return the + 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 @@ -1224,7 +1224,7 @@ def batches(self) -> AsyncBatches: @cached_property def with_raw_response(self) -> AsyncMessagesWithRawResponse: """ - This property can be used as a prefix for any HTTP method call to return the + 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 diff --git a/src/anthropic/resources/beta/models.py b/src/anthropic/resources/beta/models.py index fdad329..04d620c 100644 --- a/src/anthropic/resources/beta/models.py +++ b/src/anthropic/resources/beta/models.py @@ -22,7 +22,7 @@ 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 + 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 @@ -139,7 +139,7 @@ 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 + 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 diff --git a/src/anthropic/resources/completions.py b/src/anthropic/resources/completions.py index 411cc50..67e3977 100644 --- a/src/anthropic/resources/completions.py +++ b/src/anthropic/resources/completions.py @@ -33,7 +33,7 @@ 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 + 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 @@ -412,7 +412,7 @@ 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 + 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 diff --git a/src/anthropic/resources/messages/batches.py b/src/anthropic/resources/messages/batches.py index 0342a8c..7092730 100644 --- a/src/anthropic/resources/messages/batches.py +++ b/src/anthropic/resources/messages/batches.py @@ -41,7 +41,7 @@ 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 + 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 @@ -326,7 +326,7 @@ 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 + 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 diff --git a/src/anthropic/resources/messages/messages.py b/src/anthropic/resources/messages/messages.py index 88cc860..2176685 100644 --- a/src/anthropic/resources/messages/messages.py +++ b/src/anthropic/resources/messages/messages.py @@ -63,7 +63,7 @@ def batches(self) -> Batches: @cached_property def with_raw_response(self) -> MessagesWithRawResponse: """ - This property can be used as a prefix for any HTTP method call to return the + 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 @@ -1213,7 +1213,7 @@ def batches(self) -> AsyncBatches: @cached_property def with_raw_response(self) -> AsyncMessagesWithRawResponse: """ - This property can be used as a prefix for any HTTP method call to return the + 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 diff --git a/src/anthropic/resources/models.py b/src/anthropic/resources/models.py index aec102b..3469ccf 100644 --- a/src/anthropic/resources/models.py +++ b/src/anthropic/resources/models.py @@ -22,7 +22,7 @@ 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 + 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 @@ -139,7 +139,7 @@ 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 + 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 From f3d90aff0d5d9861deba2cbb7f4d334592f04a88 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 10:22:28 +0000 Subject: [PATCH 2/7] fix(tests): make test_get_platform less flaky (#830) --- tests/test_client.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 5481199..5c1f075 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -6,6 +6,7 @@ import os import sys import json +import time import asyncio import inspect import subprocess @@ -1830,10 +1831,20 @@ async def test_main() -> None: [sys.executable, "-c", test_code], text=True, ) as process: - try: - process.wait(2) - if process.returncode: - raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code") - except subprocess.TimeoutExpired as e: - process.kill() - raise AssertionError("calling get_platform using asyncify resulted in a hung process") from e + timeout = 10 # seconds + + start_time = time.monotonic() + while True: + return_code = process.poll() + if return_code is not None: + if return_code != 0: + raise AssertionError("calling get_platform using asyncify resulted in a non-zero exit code") + + # success + break + + if time.monotonic() - start_time > timeout: + process.kill() + raise AssertionError("calling get_platform using asyncify resulted in a hung process") + + time.sleep(0.1) From 972d4a0365333c219e0ba376e4e8e904d2b8ea0c Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Mon, 20 Jan 2025 11:50:05 +0000 Subject: [PATCH 3/7] feat(streaming): add request_id getter (#831) --- src/anthropic/lib/streaming/_beta_messages.py | 8 ++++++++ src/anthropic/lib/streaming/_messages.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/anthropic/lib/streaming/_beta_messages.py b/src/anthropic/lib/streaming/_beta_messages.py index 48e419e..7e6a774 100644 --- a/src/anthropic/lib/streaming/_beta_messages.py +++ b/src/anthropic/lib/streaming/_beta_messages.py @@ -40,6 +40,10 @@ def __init__(self, raw_stream: Stream[BetaRawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") # type: ignore[no-any-return] + def __next__(self) -> BetaMessageStreamEvent: return self._iterator.__next__() @@ -173,6 +177,10 @@ def __init__(self, raw_stream: AsyncStream[BetaRawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") # type: ignore[no-any-return] + async def __anext__(self) -> BetaMessageStreamEvent: return await self._iterator.__anext__() diff --git a/src/anthropic/lib/streaming/_messages.py b/src/anthropic/lib/streaming/_messages.py index 67fe8f0..8e7dbea 100644 --- a/src/anthropic/lib/streaming/_messages.py +++ b/src/anthropic/lib/streaming/_messages.py @@ -41,6 +41,10 @@ def __init__(self, raw_stream: Stream[RawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") # type: ignore[no-any-return] + def __next__(self) -> MessageStreamEvent: return self._iterator.__next__() @@ -174,6 +178,10 @@ def __init__(self, raw_stream: AsyncStream[RawMessageStreamEvent]) -> None: def response(self) -> httpx.Response: return self._raw_stream.response + @property + def request_id(self) -> str | None: + return self.response.headers.get("request-id") # type: ignore[no-any-return] + async def __anext__(self) -> MessageStreamEvent: return await self._iterator.__anext__() From 6dddfe259db18b92454f1af45b40cbbab6702cc5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 12:12:08 +0000 Subject: [PATCH 4/7] chore(internal): avoid pytest-asyncio deprecation warning (#832) --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 8c21200..bc96ea9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -135,6 +135,7 @@ testpaths = ["tests"] addopts = "--tb=short" xfail_strict = true asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "session" filterwarnings = [ "error" ] From c5fb4fc825752970395bc02d69ff334ca6448e85 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 16:31:21 +0000 Subject: [PATCH 5/7] chore(internal): minor style changes (#833) --- src/anthropic/_legacy_response.py | 6 ++---- src/anthropic/lib/streaming/_messages.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/anthropic/_legacy_response.py b/src/anthropic/_legacy_response.py index dd1db8e..0b812de 100644 --- a/src/anthropic/_legacy_response.py +++ b/src/anthropic/_legacy_response.py @@ -210,7 +210,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: origin = get_origin(cast_to) or cast_to if inspect.isclass(origin): - if issubclass(origin, (JSONLDecoder)): + if issubclass(cast(Any, origin), JSONLDecoder): return cast( R, cast("type[JSONLDecoder[Any]]", cast_to)( @@ -220,7 +220,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: ), ) - if issubclass(origin, AsyncJSONLDecoder): + if issubclass(cast(Any, origin), AsyncJSONLDecoder): return cast( R, cast("type[AsyncJSONLDecoder[Any]]", cast_to)( @@ -286,8 +286,6 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: if cast_to == bool: return cast(R, response.text.lower() == "true") - origin = get_origin(cast_to) or cast_to - if inspect.isclass(origin) and issubclass(origin, HttpxBinaryResponseContent): return cast(R, cast_to(response)) # type: ignore diff --git a/src/anthropic/lib/streaming/_messages.py b/src/anthropic/lib/streaming/_messages.py index 8e7dbea..ece0a16 100644 --- a/src/anthropic/lib/streaming/_messages.py +++ b/src/anthropic/lib/streaming/_messages.py @@ -356,7 +356,7 @@ def accumulate_event( current_snapshot: Message | None, ) -> Message: if not isinstance(event, BaseModel): # pyright: ignore[reportUnnecessaryIsInstance] - raise TypeError(f'Unexpected event runtime type - {event}') + raise TypeError(f"Unexpected event runtime type - {event}") if current_snapshot is None: if event.type == "message_start": From a97bd02c23fe3ab95f44171a93c7f29a3c536cdc Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Fri, 17 Jan 2025 10:55:47 +0000 Subject: [PATCH 6/7] chore: deprecate more models - claude-3-sonnet-20240229 - claude-2.1 - claude-2.0 --- .../resources/beta/messages/messages.py | 18 ++++++++++++++++++ src/anthropic/resources/messages/messages.py | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/anthropic/resources/beta/messages/messages.py b/src/anthropic/resources/beta/messages/messages.py index b3da866..761adef 100644 --- a/src/anthropic/resources/beta/messages/messages.py +++ b/src/anthropic/resources/beta/messages/messages.py @@ -2,6 +2,7 @@ from __future__ import annotations +import warnings from typing import List, Union, Iterable from functools import partial from itertools import chain @@ -34,6 +35,7 @@ from ....types.beta import message_create_params, message_count_tokens_params from ...._base_client import make_request_options from ....lib.streaming import BetaMessageStreamManager, BetaAsyncMessageStreamManager +from ...messages.messages import DEPRECATED_MODELS from ....types.model_param import ModelParam from ....types.beta.beta_message import BetaMessage from ....types.anthropic_beta_param import AnthropicBetaParam @@ -893,6 +895,14 @@ def create( ) -> BetaMessage | Stream[BetaRawMessageStreamEvent]: if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT: timeout = 600 + + if model in DEPRECATED_MODELS: + warnings.warn( + f"The model '{model}' is deprecated and will reach end-of-life on {DEPRECATED_MODELS[model]}.\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.", + DeprecationWarning, + stacklevel=3, + ) + extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), @@ -2061,6 +2071,14 @@ async def create( ) -> BetaMessage | AsyncStream[BetaRawMessageStreamEvent]: if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT: timeout = 600 + + if model in DEPRECATED_MODELS: + warnings.warn( + f"The model '{model}' is deprecated and will reach end-of-life on {DEPRECATED_MODELS[model]}.\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.", + DeprecationWarning, + stacklevel=3, + ) + extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), diff --git a/src/anthropic/resources/messages/messages.py b/src/anthropic/resources/messages/messages.py index 2176685..ad256ac 100644 --- a/src/anthropic/resources/messages/messages.py +++ b/src/anthropic/resources/messages/messages.py @@ -52,6 +52,9 @@ "claude-instant-1.1": "November 6th, 2024", "claude-instant-1.1-100k": "November 6th, 2024", "claude-instant-1.2": "November 6th, 2024", + "claude-3-sonnet-20240229": "July 21st, 2025", + "claude-2.1": "July 21st, 2025", + "claude-2.0": "July 21st, 2025", } From d212ec9f6d5e956f13bc0ddc3d86b5888a954383 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 16:43:26 +0000 Subject: [PATCH 7/7] release: 0.44.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 25 +++++++++++++++++++++++++ pyproject.toml | 2 +- src/anthropic/_version.py | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 26548ff..cc51f6f 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.43.1" + ".": "0.44.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ffc506..dcffb96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## 0.44.0 (2025-01-21) + +Full Changelog: [v0.43.1...v0.44.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.43.1...v0.44.0) + +### Features + +* **streaming:** add request_id getter ([#831](https://github.com/anthropics/anthropic-sdk-python/issues/831)) ([fb397e0](https://github.com/anthropics/anthropic-sdk-python/commit/fb397e0851bd874a10a69a9531483fd196fc8a55)) + + +### Bug Fixes + +* **tests:** make test_get_platform less flaky ([#830](https://github.com/anthropics/anthropic-sdk-python/issues/830)) ([f2c10ca](https://github.com/anthropics/anthropic-sdk-python/commit/f2c10cae0cbff6881bba2a41c93efdcc17e8d2ab)) + + +### Chores + +* deprecate more models ([c647e25](https://github.com/anthropics/anthropic-sdk-python/commit/c647e25c3735e4276195ee8eb0011ace3e3e0d2f)) +* **internal:** avoid pytest-asyncio deprecation warning ([#832](https://github.com/anthropics/anthropic-sdk-python/issues/832)) ([2b3ceff](https://github.com/anthropics/anthropic-sdk-python/commit/2b3ceff7ef9c953e28044442821069d7de3b0154)) +* **internal:** minor style changes ([#833](https://github.com/anthropics/anthropic-sdk-python/issues/833)) ([65cfb7b](https://github.com/anthropics/anthropic-sdk-python/commit/65cfb7b13324e52e2d2987c4de3ed9e5c122a40b)) + + +### Documentation + +* **raw responses:** fix duplicate `the` ([#828](https://github.com/anthropics/anthropic-sdk-python/issues/828)) ([ff850f8](https://github.com/anthropics/anthropic-sdk-python/commit/ff850f8081a72090eaaa31e09e560acd3ce18b09)) + ## 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) diff --git a/pyproject.toml b/pyproject.toml index bc96ea9..ba848c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "anthropic" -version = "0.43.1" +version = "0.44.0" description = "The official Python library for the anthropic API" dynamic = ["readme"] license = "MIT" diff --git a/src/anthropic/_version.py b/src/anthropic/_version.py index 7b3b007..3527ab6 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.1" # x-release-please-version +__version__ = "0.44.0" # x-release-please-version