fix(anthropic): strip trailing /v1 from base_url in build_anthropic_client (#24833) - #37656
Closed
rodboev wants to merge 4 commits into
Closed
fix(anthropic): strip trailing /v1 from base_url in build_anthropic_client (#24833)#37656rodboev wants to merge 4 commits into
rodboev wants to merge 4 commits into
Conversation
14 tasks
rodboev
force-pushed
the
pr/anthropic-strip-v1-base-url
branch
from
June 28, 2026 16:31
a6c9cf1 to
a42017d
Compare
rodboev
force-pushed
the
pr/anthropic-strip-v1-base-url
branch
from
June 28, 2026 20:00
916a06f to
40723c9
Compare
Contributor
Author
|
Withdrawing this in favor of #45842, which already landed with the overlapping Anthropic base URL fix. Closing to keep the queue clean. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Anthropic SDK appends
/v1tobase_urlwhen constructing request URLs. When a user configuresmodel.base_urlorANTHROPIC_BASE_URLwith a trailing/v1(the value the older setup guidance suggested), the SDK produces/v1/v1/messagesand every request 404s.The bearer-hook constructor
_build_anthropic_client_with_bearer_hookalready strips a trailing/v1at line 612, but its siblingbuild_anthropic_client— the path used for OAuth, x-api-key, and plain Bearer auth (the common case) — forwarded the value verbatim. This applies the same strip in the main constructor, aligning the two paths.Fixes #24833
Changes
agent/anthropic_adapter.py: strip trailing/v1or/v1/fromnormalized_base_urlinbuild_anthropic_client(), immediately after_normalize_base_url_text(), mirroring the existing idiom in the bearer-hook constructor (+4 lines)tests/agent/test_anthropic_adapter.py: two new tests covering/v1and/v1/suffix stripping (+13 lines)Validation
base_url: https://api.anthropic.com/v1/v1/v1/messages→ 404https://api.anthropic.com→ correctbase_url: https://proxy.example.com/anthropic/v1//v1/v1/messages→ 404https://proxy.example.com/anthropic→ correctbase_url: https://custom.api.com(no /v1)*.azure.com/models/anthropic)Test plan
pytest tests/agent/test_anthropic_adapter.py -v --timeout=0— 156 passed, 1 skippedtest_custom_base_urlpasses (non-/v1URLs untouched)test_azure_anthropic_endpoint_keeps_context_1m_betapasses (Azure unaffected)test_azure_foundry_anthropic_endpoint_uses_bearer_authpasses (Foundry unaffected)model.base_url: https://api.anthropic.com/v1no longer 404s