Skip to content

Add configurable Anthropic API base URL#589

Merged
crmne merged 2 commits intocrmne:mainfrom
ericproulx:feature/anthropic-custom-endpoint
Mar 1, 2026
Merged

Add configurable Anthropic API base URL#589
crmne merged 2 commits intocrmne:mainfrom
ericproulx:feature/anthropic-custom-endpoint

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

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

@ericproulx ericproulx mentioned this pull request Feb 3, 2026
6 tasks
@michaelwapp
Copy link
Copy Markdown

Is there an ETA when this feature will be merged?

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.
@ericproulx ericproulx force-pushed the feature/anthropic-custom-endpoint branch from 280acc7 to 4c2e17c Compare February 17, 2026 13:14
@ericproulx
Copy link
Copy Markdown
Contributor Author

@michaelwapp I've just rebased it. Hopefully, someone will pick it up.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 1, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.89%. Comparing base (18c6e13) to head (f6d1925).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lib/ruby_llm/providers/anthropic/models.rb 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #589   +/-   ##
=======================================
  Coverage   80.89%   80.89%           
=======================================
  Files         113      113           
  Lines        5098     5098           
  Branches     1309     1309           
=======================================
  Hits         4124     4124           
  Misses        974      974           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@crmne
Copy link
Copy Markdown
Owner

crmne commented Mar 1, 2026

Thanks for the contribution. I’m going to move this forward to keep momentum and handle the small docs/process follow-up on maintainer side.

For your next PR, please use the repository PR template and include the required new-feature process items (especially linked pre-approved issue + checklist completion) so review can proceed without back-and-forth.

@crmne crmne merged commit 28dcfd3 into crmne:main Mar 1, 2026
22 checks passed
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.

3 participants