Skip to content

feat: add ANTHROPIC_BASE_URL support for custom proxy routing#80

Open
otto-the-otter-bot[bot] wants to merge 1 commit into
mainfrom
feat/anthropic-base-url-support
Open

feat: add ANTHROPIC_BASE_URL support for custom proxy routing#80
otto-the-otter-bot[bot] wants to merge 1 commit into
mainfrom
feat/anthropic-base-url-support

Conversation

@otto-the-otter-bot

Copy link
Copy Markdown

Summary

  • Adds a new anthropic_base_url: str = "" setting to Settings in config.py, populated from the ANTHROPIC_BASE_URL environment variable.
  • Updates _make_anthropic() in llm.py to pass anthropic_api_url to ChatAnthropic when ANTHROPIC_BASE_URL is set — this is the correct langchain_anthropic parameter that maps to the underlying Anthropic SDK's base_url.
  • Documents the new variable in .env.example with 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:

ANTHROPIC_BASE_URL=https://your-proxy.example.com

When left unset (the default), behavior is identical to before — the official https://api.anthropic.com endpoint is used.

Test plan

  • Start backend with LLM_PROVIDER=anthropic and ANTHROPIC_BASE_URL unset — confirm existing behavior is unchanged
  • Start backend with ANTHROPIC_BASE_URL=https://your-proxy.example.com — confirm requests are routed to the proxy (e.g. via network capture or proxy logs)
  • Run unit tests: uv run pytest tests/unit/ -v

🤖 Generated with Claude Code

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

0 participants