Skip to content

fix(anthropic): honor ANTHROPIC_BASE_URL env override#282

Open
psvaggelis wants to merge 1 commit into
NVIDIA:mainfrom
psvaggelis:fix/anthropic-honor-base-url
Open

fix(anthropic): honor ANTHROPIC_BASE_URL env override#282
psvaggelis wants to merge 1 commit into
NVIDIA:mainfrom
psvaggelis:fix/anthropic-honor-base-url

Conversation

@psvaggelis

Copy link
Copy Markdown

What

AnthropicProvider now reads ANTHROPIC_BASE_URL and passes it to ChatAnthropic, falling back to https://api.anthropic.com when unset — mirroring how OpenAIProvider handles OPENAI_BASE_URL.

Fixes #281.

Why

Previously resolve_credentials() returned (api_key, None) and create_chat_model() hardcoded base_url=ANTHROPIC_BASE_URL, so a proxy/gateway set via ANTHROPIC_BASE_URL was 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: read ANTHROPIC_BASE_URL in resolve_credentials(); use base_url or ANTHROPIC_BASE_URL in create_chat_model().
  • tests/unit/test_providers.py: add override + default-endpoint coverage; clear ANTHROPIC_BASE_URL in the env-isolation fixture.
  • tests/unit/test_llm_utils.py: add ANTHROPIC_BASE_URL to the env-isolation list (keeps credential-resolution tests hermetic).
  • tests/provider/test_provider_endpoint.py: clear ANTHROPIC_BASE_URL in the live anthropic test so it validates the default URL, mirroring the OpenAI live test.

Testing

  • make lint — clean
  • make format — clean
  • pytest -m "not integration and not provider" — 1314 passed, 12 skipped

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>
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.

AnthropicProvider ignores ANTHROPIC_BASE_URL (proxy/gateway endpoints bypassed)

1 participant