Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.88.0"
".": "0.89.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 34
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-efe26b096126c693462514b8cbd3ec3e376569232becbfb730cd26fb31c7c7e3.yml
openapi_spec_hash: cae9199aabfd7b87f0ff2dcc10760c92
config_hash: 79b43ba5cfb2877d888e0d5ecab99d41
config_hash: 7aaaa92e479b2962424ce93d7d24e004
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 0.89.0 (2026-04-03)

Full Changelog: [v0.88.0...v0.89.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.88.0...v0.89.0)

### Features

* **vertex:** add support for US multi-region endpoint ([4e732da](https://github.com/anthropics/anthropic-sdk-python/commit/4e732dada087146cfeff1f4afdf90513590e248d))


### Bug Fixes

* **client:** preserve hardcoded query params when merging with user params ([e7f4a3c](https://github.com/anthropics/anthropic-sdk-python/commit/e7f4a3cada266e9719e5c3b9ba09514c3842a638))


### Chores

* **client:** deprecate client-side compaction helpers ([e60affc](https://github.com/anthropics/anthropic-sdk-python/commit/e60affc656e4165de7cb15f73351175507b0b441))

## 0.88.0 (2026-04-01)

Full Changelog: [v0.87.0...v0.88.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.87.0...v0.88.0)
Expand Down
77 changes: 0 additions & 77 deletions examples/auto_compaction.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "anthropic"
version = "0.88.0"
version = "0.89.0"
description = "The official Python library for the anthropic API"
dynamic = ["readme"]
license = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions src/anthropic/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,12 @@ def _build_request(
files = cast(HttpxRequestFiles, ForceMultipartDict())

prepared_url = self._prepare_url(options.url)
# When the URL contains hardcoded query params (e.g. ?beta=true) and
# additional params are provided, httpx will replace the URL's query
# string with the params. Merge them to preserve both.
if params and prepared_url.query:
params = {**dict(prepared_url.params.items()), **params}
prepared_url = prepared_url.copy_with(raw_path=prepared_url.path.encode())
if "_" in prepared_url.host:
# work around https://github.com/encode/httpx/discussions/2880
kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")}
Expand Down
2 changes: 1 addition & 1 deletion src/anthropic/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "anthropic"
__version__ = "0.88.0" # x-release-please-version
__version__ = "0.89.0" # x-release-please-version
7 changes: 7 additions & 0 deletions src/anthropic/lib/tools/_beta_compaction_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@


class CompactionControl(TypedDict, total=False):
"""Client-side compaction control configuration.
.. deprecated::
Use server-side compaction instead by passing
``edits=[{"type": "compact_20260112"}]`` in the params passed to ``tool_runner()``.
See https://platform.claude.com/docs/en/build-with-claude/compaction
"""
context_token_threshold: int
"""The context token threshold at which to trigger compaction.
Expand Down
18 changes: 18 additions & 0 deletions src/anthropic/lib/tools/_beta_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ def __init__(
)
self._client = client

if compaction_control is not None and compaction_control.get("enabled"):
warnings.warn(
"The 'compaction_control' parameter is deprecated and will be removed in a future version. "
"Use server-side compaction instead by passing `edits=[{'type': 'compact_20260112'}]` in your "
"the params passed to `tool_runner()`. See https://platform.claude.com/docs/en/build-with-claude/compaction",
DeprecationWarning,
stacklevel=3,
)

self._iterator = self.__run__()
self._last_message: (
Callable[[], ParsedBetaMessage[ResponseFormatT]] | ParsedBetaMessage[ResponseFormatT] | None
Expand Down Expand Up @@ -416,6 +425,15 @@ def __init__(
)
self._client = client

if compaction_control is not None and compaction_control.get("enabled"):
warnings.warn(
"The 'compaction_control' parameter is deprecated and will be removed in a future version. "
"Use server-side compaction instead by passing `edits=[{'type': 'compact_20260112'}]` in your "
"the params passed to `tool_runner()`. See https://platform.claude.com/docs/en/build-with-claude/compaction",
DeprecationWarning,
stacklevel=3,
)

self._iterator = self.__run__()
self._last_message: (
Callable[[], Coroutine[None, None, ParsedBetaMessage[ResponseFormatT]]]
Expand Down
2 changes: 2 additions & 0 deletions src/anthropic/lib/vertex/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def __init__(
if base_url is None:
if region == "global":
base_url = "https://aiplatform.googleapis.com/v1"
elif region == "us":
base_url = "https://aiplatform.us.rep.googleapis.com/v1"
else:
base_url = f"https://{region}-aiplatform.googleapis.com/v1"

Expand Down
5 changes: 5 additions & 0 deletions tests/lib/test_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def test_global_region_base_url(self) -> None:
client = AnthropicVertex(region="global", project_id="test-project", access_token="fake-token")
assert str(client.base_url).rstrip("/") == "https://aiplatform.googleapis.com/v1"

def test_us_region_base_url(self) -> None:
"""Test that us region uses the correct base URL."""
client = AnthropicVertex(region="us", project_id="test-project", access_token="fake-token")
assert str(client.base_url).rstrip("/") == "https://aiplatform.us.rep.googleapis.com/v1"

@pytest.mark.parametrize("region", ["us-central1", "europe-west1", "asia-southeast1"])
def test_regional_base_url(self, region: str) -> None:
"""Test that regional endpoints use the correct base URL format."""
Expand Down
37 changes: 19 additions & 18 deletions tests/lib/tools/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,24 +473,25 @@ def submit_analysis(summary: str) -> str: # noqa: ARG001
"""Call this LAST with your final analysis."""
return "Analysis submitted"

runner = snapshot_client.beta.messages.tool_runner(
model="claude-sonnet-4-5",
max_tokens=4000,
tools=[submit_analysis],
messages=[
{
"role": "user",
"content": (
"Write a detailed 500 word essay about dogs, cats, and birds. "
"Call the tool submit_analysis with the information about all three animals. "
"Note that you should call it only once at the end of your essay."
),
}
],
betas=["structured-outputs-2025-12-15"],
compaction_control={"enabled": True, "context_token_threshold": 500},
max_iterations=1,
)
with pytest.warns(DeprecationWarning, match="compaction_control.*deprecated"):
runner = snapshot_client.beta.messages.tool_runner(
model="claude-sonnet-4-5",
max_tokens=4000,
tools=[submit_analysis],
messages=[
{
"role": "user",
"content": (
"Write a detailed 500 word essay about dogs, cats, and birds. "
"Call the tool submit_analysis with the information about all three animals. "
"Note that you should call it only once at the end of your essay."
),
}
],
betas=["structured-outputs-2025-12-15"],
compaction_control={"enabled": True, "context_token_threshold": 500},
max_iterations=1,
)

with caplog.at_level(logging.INFO, logger="anthropic.lib.tools._beta_runner"):
next(runner)
Expand Down
32 changes: 32 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,22 @@ def test_default_query_option(self) -> None:

client.close()

def test_hardcoded_query_params_in_url(self, client: Anthropic) -> None:
request = client._build_request(FinalRequestOptions(method="get", url="/foo?beta=true"))
url = httpx.URL(request.url)
assert dict(url.params) == {"beta": "true"}

def test_hardcoded_query_params_with_extra_params(self, client: Anthropic) -> None:
request = client._build_request(
FinalRequestOptions(
method="get",
url="/foo?beta=true",
params={"limit": "10", "page": "abc"},
)
)
url = httpx.URL(request.url)
assert dict(url.params) == {"beta": "true", "limit": "10", "page": "abc"}

def test_request_extra_json(self, client: Anthropic) -> None:
request = client._build_request(
FinalRequestOptions(
Expand Down Expand Up @@ -1458,6 +1474,22 @@ async def test_default_query_option(self) -> None:

await client.close()

def test_hardcoded_query_params_in_url(self, async_client: AsyncAnthropic) -> None:
request = async_client._build_request(FinalRequestOptions(method="get", url="/foo?beta=true"))
url = httpx.URL(request.url)
assert dict(url.params) == {"beta": "true"}

def test_hardcoded_query_params_with_extra_params(self, async_client: AsyncAnthropic) -> None:
request = async_client._build_request(
FinalRequestOptions(
method="get",
url="/foo?beta=true",
params={"limit": "10", "page": "abc"},
)
)
url = httpx.URL(request.url)
assert dict(url.params) == {"beta": "true", "limit": "10", "page": "abc"}

def test_request_extra_json(self, client: Anthropic) -> None:
request = client._build_request(
FinalRequestOptions(
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading