Skip to content

fix(vertex): move the region-derived base_url when copy() changes the region - #2043

Open
johnkaram02 wants to merge 1 commit into
anthropics:mainfrom
johnkaram02:fix/vertex-copy-region-base-url
Open

johnkaram02 wants to merge 1 commit into
anthropics:mainfrom
johnkaram02:fix/vertex-copy-region-base-url

Conversation

@johnkaram02

Copy link
Copy Markdown

What was wrong

AnthropicVertex.copy() and with_options() accept a new region, but they kept the original region's base_url. The request path is built from the new region, so the request went to the wrong host.

client = AnthropicVertex(region="us-east5", project_id="project", access_token="...")
client.with_options(region="europe-west1").messages.create(...)

… region

AnthropicVertex.copy() and with_options() accept a new region but kept
the base URL of the original region. A client created with
region="us-east5" and copied with region="europe-west1" sent requests
to https://us-east5-aiplatform.googleapis.com with a
locations/europe-west1 path.

When the current base URL is the one derived from the current region,
derive a new one from the new region. A custom base URL, from the
argument or from ANTHROPIC_VERTEX_BASE_URL, is kept. AnthropicAWS
already handles a region change in copy() the same way.
@johnkaram02
johnkaram02 requested a review from a team as a code owner October 28, 2026 01:43

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnkaram02 from my side this is ready to merge. It is the same guard AnthropicAWS.copy() got in f21982a, and pulling region_base_url() out also stops the sync and async branches drifting apart again, which is what 162fb21 had to fix.

# git archive 346e94ef, uv sync --all-extras --group dev, Python 3.10.21; anthropic resolves into each tree
$ python -m pytest tests/lib/test_vertex.py -q -p no:cacheprovider
43 passed                    # head 346e94ef
4 failed, 39 passed          # vertex/_client.py from base 202db72
# not run: a live Vertex call

non-blocking: AnthropicBedrock.copy(aws_region=...) keeps the old host too. At this head, AnthropicBedrock(aws_region="us-east-1", ...).copy(aws_region="eu-west-1").base_url is still https://bedrock-runtime.us-east-1.amazonaws.com, so SigV4 signs for eu-west-1 against a us-east-1 host.

I'd leave this PR to Vertex and give Bedrock its own change with its own tests. Do you plan to take that one?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants