fix(anthropic): honor ANTHROPIC_BASE_URL env override#282
Open
psvaggelis wants to merge 1 commit into
Open
Conversation
AnthropicProvider ignored ANTHROPIC_BASE_URL and always constructed ChatAnthropic against the hardcoded https://api.anthropic.com, so proxy and gateway deployments were silently bypassed. This is inconsistent with OpenAIProvider, which already honors OPENAI_BASE_URL. Read ANTHROPIC_BASE_URL in resolve_credentials() and pass it through in create_chat_model(), falling back to api.anthropic.com when unset -- mirroring the OpenAIProvider pattern. Tests: - Add unit coverage for the base_url override and the default-endpoint fallback (resolve_credentials + create_chat_model). - Clear ANTHROPIC_BASE_URL in the provider/llm_utils env-isolation fixtures now that the provider reads it, keeping tests hermetic. - Clear ANTHROPIC_BASE_URL in the live anthropic endpoint test so it validates the default URL, mirroring the OpenAI live test. Signed-off-by: Papastavros Vaggelis <psvaggelis@gmail.com>
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.
What
AnthropicProvidernow readsANTHROPIC_BASE_URLand passes it toChatAnthropic, falling back tohttps://api.anthropic.comwhen unset — mirroring howOpenAIProviderhandlesOPENAI_BASE_URL.Fixes #281.
Why
Previously
resolve_credentials()returned(api_key, None)andcreate_chat_model()hardcodedbase_url=ANTHROPIC_BASE_URL, so a proxy/gateway set viaANTHROPIC_BASE_URLwas silently ignored and Anthropic requests went straight to the public API. This breaks egress-controlled/gateway deployments and is inconsistent with the OpenAI provider.Changes
providers/anthropic/provider.py: readANTHROPIC_BASE_URLinresolve_credentials(); usebase_url or ANTHROPIC_BASE_URLincreate_chat_model().tests/unit/test_providers.py: add override + default-endpoint coverage; clearANTHROPIC_BASE_URLin the env-isolation fixture.tests/unit/test_llm_utils.py: addANTHROPIC_BASE_URLto the env-isolation list (keeps credential-resolution tests hermetic).tests/provider/test_provider_endpoint.py: clearANTHROPIC_BASE_URLin the live anthropic test so it validates the default URL, mirroring the OpenAI live test.Testing
make lint— cleanmake format— cleanpytest -m "not integration and not provider"— 1314 passed, 12 skipped