Skip to content

Add configurable Anthropic API base URL#589

Open
ericproulx wants to merge 1 commit intocrmne:mainfrom
ericproulx:feature/anthropic-custom-endpoint
Open

Add configurable Anthropic API base URL#589
ericproulx wants to merge 1 commit intocrmne:mainfrom
ericproulx:feature/anthropic-custom-endpoint

Conversation

@ericproulx
Copy link

Summary

Adds support for configurable Anthropic API base URL through a new anthropic_api_base configuration option. This allows users to point to custom endpoints such as proxies, custom deployments, or alternative Anthropic-compatible services.

Changes

  • Configuration: Added anthropic_api_base configuration attribute
  • Provider: Modified Anthropic provider to use custom base URL when configured, with fallback to default https://api.anthropic.com
  • URL Fixes: Removed leading slashes from API endpoint paths in chat and models modules for proper URL construction
  • Console: Updated bin/console to support ANTHROPIC_BASE_URL environment variable
  • Tests: Added comprehensive test coverage for the new configuration option

Use Cases

This enhancement enables:

  • Using proxy servers for Anthropic API requests
  • Custom deployments of Anthropic-compatible services
  • Testing against mock servers
  • Regional or enterprise-specific endpoints

Configuration Example

RubyLLM.configure do |config|
  config.anthropic_api_key = "your-api-key"
  config.anthropic_api_base = "https://custom-anthropic-endpoint.example.com"
end

Or via environment variable:

export ANTHROPIC_BASE_URL="https://custom-anthropic-endpoint.example.com"

Backward Compatibility

✅ Fully backward compatible - defaults to official Anthropic API endpoint when not configured

Introduces anthropic_api_base configuration option to allow users to specify custom Anthropic API endpoints. This enables support for proxies, custom deployments, and alternative Anthropic-compatible services. Also fixes URL path formatting in chat and models endpoints by removing redundant leading slashes.
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