feat: allow custom API base URL for Anthropic provider#683
Open
aminsaedi wants to merge 1 commit into
Open
Conversation
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>
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 & 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
https://api.anthropic.com/v1/messages./v1/messagespath, so users can enter any of:https://proxy.example.com→https://proxy.example.com/v1/messageshttps://proxy.example.com/v1→https://proxy.example.com/v1/messageshttps://proxy.example.com/v1/messages(used as-is)Changes
const.py: addCONF_ANTHROPIC_BASE_URLproviders.py:Anthropicaccepts anendpointand resolves the request URL via a new_get_request_url()helper, used in both_make_requestandvalidate;ProviderFactorywires the configured base URL throughconfig_flow.py: optional base URL field in the Anthropic step (setup + reconfigure)__init__.py: persist the field into the per-entry provider configstrings.json/translations/en.json: document the new field (other languages are generated viatranslator.py)Tests
_get_request_url) across bare host //v1/ full-endpoint / trailing-slash / blank inputsProviderFactorypasses a custom base URL and falls back to the default🤖 Generated with Claude Code