feat: add ANTHROPIC_BASE_URL support for custom proxy routing#80
Open
otto-the-otter-bot[bot] wants to merge 1 commit into
Open
feat: add ANTHROPIC_BASE_URL support for custom proxy routing#80otto-the-otter-bot[bot] wants to merge 1 commit into
otto-the-otter-bot[bot] wants to merge 1 commit into
Conversation
Add an `anthropic_base_url` setting (env var: `ANTHROPIC_BASE_URL`) that, when set, is forwarded to `ChatAnthropic` as `anthropic_api_url`. This allows operators to route all Anthropic API traffic through a custom HTTP proxy or gateway (e.g. LiteLLM, a corporate egress proxy, or a regional endpoint) without patching the code. - `config.py`: new `anthropic_base_url: str = ""` field in `Settings` - `llm.py`: `_make_anthropic()` passes `anthropic_api_url` when the setting is non-empty - `.env.example`: commented-out example line documenting the variable Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
Summary
anthropic_base_url: str = ""setting toSettingsinconfig.py, populated from theANTHROPIC_BASE_URLenvironment variable._make_anthropic()inllm.pyto passanthropic_api_urltoChatAnthropicwhenANTHROPIC_BASE_URLis set — this is the correctlangchain_anthropicparameter that maps to the underlying Anthropic SDK'sbase_url..env.examplewith a commented-out example line.Motivation
Some deployments need to route Anthropic API calls through a custom HTTP proxy or gateway (e.g. a corporate egress proxy, a LiteLLM instance acting as an Anthropic-compatible gateway, or a regional endpoint). Without this setting, there was no way to override the base URL without patching the code.
Usage
Set the environment variable before starting the backend:
When left unset (the default), behavior is identical to before — the official
https://api.anthropic.comendpoint is used.Test plan
LLM_PROVIDER=anthropicandANTHROPIC_BASE_URLunset — confirm existing behavior is unchangedANTHROPIC_BASE_URL=https://your-proxy.example.com— confirm requests are routed to the proxy (e.g. via network capture or proxy logs)uv run pytest tests/unit/ -v🤖 Generated with Claude Code