Skip to content

fix(vertex): async client missing us/eu multi-region base_url branches#1406

Closed
atob1 wants to merge 1 commit intoanthropics:mainfrom
atob1:fix/async-vertex-us-eu-multi-region
Closed

fix(vertex): async client missing us/eu multi-region base_url branches#1406
atob1 wants to merge 1 commit intoanthropics:mainfrom
atob1:fix/async-vertex-us-eu-multi-region

Conversation

@atob1
Copy link
Copy Markdown

@atob1 atob1 commented Apr 17, 2026

Summary

AnthropicVertex.__init__ (sync) maps region="us" to https://aiplatform.us.rep.googleapis.com/v1 and region="eu" to the .eu.rep.googleapis.com hostname (added in 0.89.0). Those branches were never added to AsyncAnthropicVertex.__init__, so passing region="us" / "eu" to the async client falls through to the generic fallback and builds {region}-aiplatform.googleapis.com, which is not a valid endpoint and returns 404 from the GCP URL router.

This PR mirrors the two elif branches from the sync class into the async class. 4 lines added, no other changes.

Repro (SDK 0.96.0, before fix)

import anthropic, asyncio

async def main():
    c = anthropic.AsyncAnthropicVertex(project_id="YOUR_PROJECT", region="us")
    print(c.base_url)
    # https://us-aiplatform.googleapis.com/v1/   <-- wrong hostname
    await c.messages.create(
        model="claude-opus-4-7",
        max_tokens=16,
        messages=[{"role": "user", "content": "hi"}],
    )
    # anthropic.NotFoundError: Error code: 404 (HTML page from GCP URL router)

asyncio.run(main())

After fix

c.base_url becomes https://aiplatform.us.rep.googleapis.com/v1/ — matches the sync client and the working US multi-region endpoint, and the request succeeds.

Test plan

  • Unit: add a test that AsyncAnthropicVertex(region="us").base_url ends with aiplatform.us.rep.googleapis.com/v1/ (mirror whatever the sync test does)
  • Manual: verified messages.create now returns 200 against region="us" with claude-opus-4-7

The sync `AnthropicVertex.__init__` maps `region="us"` to
`https://aiplatform.us.rep.googleapis.com/v1` and `region="eu"` to the
`.eu.rep.googleapis.com` hostname (added in 0.89.0). The matching
branches were never added to `AsyncAnthropicVertex.__init__`, so
`region="us"` / `region="eu"` falls through to the generic
`{region}-aiplatform.googleapis.com` branch and produces
`us-aiplatform.googleapis.com`, which is not a valid endpoint and
returns HTTP 404 from the GCP URL router.

Repro (SDK 0.96.0):

    import anthropic, asyncio
    async def main():
        c = anthropic.AsyncAnthropicVertex(project_id="...", region="us")
        print(c.base_url)  # https://us-aiplatform.googleapis.com/v1/  <-- wrong
        await c.messages.create(
            model="claude-opus-4-7",
            max_tokens=16,
            messages=[{"role": "user", "content": "hi"}],
        )  # NotFoundError 404

With the fix, base_url becomes `https://aiplatform.us.rep.googleapis.com/v1/`
and the request succeeds, matching the sync client's behavior.
@atob1 atob1 requested a review from a team as a code owner April 17, 2026 02:31
@aii-vtl
Copy link
Copy Markdown

aii-vtl commented Apr 29, 2026

This should fix this issue: #1471

@dtmeadows
Copy link
Copy Markdown
Collaborator

Thanks for the fix @aii-vtl ! Would you be able to add unit tests like these for the async client?

def test_global_region_base_url(self) -> None:
"""Test that global region uses the correct base URL."""
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"
def test_eu_region_base_url(self) -> None:
"""Test that us region uses the correct base URL."""
client = AnthropicVertex(region="eu", project_id="test-project", access_token="fake-token")
assert str(client.base_url).rstrip("/") == "https://aiplatform.eu.rep.googleapis.com/v1"

@aii-vtl
Copy link
Copy Markdown

aii-vtl commented Apr 29, 2026

@dtmeadows oh I'm not the author of the PR, it's @atob1. @atob1 can you please add the unit tests?

@dtmeadows
Copy link
Copy Markdown
Collaborator

Sorry about that @aii-vtl! Let me know if you're able to take @atob1, otherwise, I'm happy to take over this PR and get it over the line.

stainless-app Bot pushed a commit that referenced this pull request Apr 30, 2026
…s (#1734)

Mirrors the us/eu region branches from the sync AnthropicVertex into
AsyncAnthropicVertex.__init__. Previously these regions fell through to
the generic fallback and built {region}-aiplatform.googleapis.com, which
returns 404 from the GCP URL router.

Adds matching unit tests on TestAsyncAnthropicVertex to mirror the
existing sync test pattern.

Picked up from #1406 (Alex Toberoff).
@dtmeadows
Copy link
Copy Markdown
Collaborator

I pushed up a fix / tests for this here: 3e78f71

@dtmeadows dtmeadows closed this Apr 30, 2026
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.

3 participants