Skip to content

feat: allow custom API base URL for Anthropic provider#683

Open
aminsaedi wants to merge 1 commit into
valentinfrlch:mainfrom
aminsaedi:feat/anthropic-custom-base-url
Open

feat: allow custom API base URL for Anthropic provider#683
aminsaedi wants to merge 1 commit into
valentinfrlch:mainfrom
aminsaedi:feat/anthropic-custom-base-url

Conversation

@aminsaedi

Copy link
Copy Markdown

What & why

Adds an optional API base URL field to the Anthropic provider so it can target an Anthropic-compatible proxy or gateway (e.g. LiteLLM, a corporate gateway, or a self-hosted relay) instead of being pinned to https://api.anthropic.com.

Several providers already support a custom base URL (Custom OpenAI, OpenWebUI, OpenRouter, Azure, LocalAI, Ollama), but Anthropic was hardcoded to ENDPOINT_ANTHROPIC. This brings Anthropic in line with the existing "Custom OpenAI" pattern.

Behaviour

  • New optional field in the Anthropic Connection section, defaulting to https://api.anthropic.com/v1/messages.
  • The value is normalized to the /v1/messages path, so users can enter any of:
    • a bare host — https://proxy.example.comhttps://proxy.example.com/v1/messages
    • a versioned base — https://proxy.example.com/v1https://proxy.example.com/v1/messages
    • a full messages endpoint — https://proxy.example.com/v1/messages (used as-is)
  • Blank/empty input falls back to the official endpoint.
  • Fully backward compatible — existing configs keep using the default endpoint; nothing changes unless a custom base URL is set. Works for both initial setup and reconfigure.

Changes

  • const.py: add CONF_ANTHROPIC_BASE_URL
  • providers.py: Anthropic accepts an endpoint and resolves the request URL via a new _get_request_url() helper, used in both _make_request and validate; ProviderFactory wires the configured base URL through
  • config_flow.py: optional base URL field in the Anthropic step (setup + reconfigure)
  • __init__.py: persist the field into the per-entry provider config
  • strings.json / translations/en.json: document the new field (other languages are generated via translator.py)

Tests

  • URL normalization (_get_request_url) across bare host / /v1 / full-endpoint / trailing-slash / blank inputs
  • ProviderFactory passes a custom base URL and falls back to the default
  • Config-flow forwards the custom base URL to the provider
  • Full suite: 419 passed, 4 skipped (the 4 skipped are the credential-gated live API tests)

🤖 Generated with Claude Code

Add an optional "API base URL" field to the Anthropic provider setup so it
can target an Anthropic-compatible proxy or gateway (LiteLLM, corporate
gateway, self-hosted relay) instead of being pinned to
https://api.anthropic.com.

The base URL is normalized to the /v1/messages path, accepting a bare host,
a versioned base (.../v1), or a full messages endpoint. It defaults to the
official endpoint, so existing configurations are unaffected.

- const: add CONF_ANTHROPIC_BASE_URL
- providers: Anthropic accepts an endpoint and resolves the request URL via
  _get_request_url(); used in both _make_request and validate
- config_flow: optional base URL field in the Anthropic step (+ reconfigure)
- __init__: persist the field into the provider config
- strings/en: document the new field
- tests: URL normalization, factory wiring, and config-flow forwarding

Co-Authored-By: Claude Opus 4.8 (1M context) <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.

1 participant