Skip to content

AnthropicClient ignores custom base_url for BYOK providers #3130

@kosmoli

Description

@kosmoli

Description

The AnthropicClient does not respect the custom base_url configured in BYOK (Bring Your Own Key) providers. Instead, it always connects to the official Anthropic API endpoint regardless of the provider configuration.

Impact

This prevents users from:

  • Using third-party Anthropic API proxies
  • Connecting to API aggregation platforms
  • Self-hosting Anthropic-compatible API endpoints
  • Using enterprise API gateways that require custom endpoints

Current Behavior

When creating an agent with a BYOK provider that has:

provider_config = {
    "provider_category": "byok",
    "provider_name": "my-custom-anthropic",
    "base_url": "https://my-custom-endpoint.example.com"
}

The AnthropicClient ignores the base_url and still connects to https://api.anthropic.com.

Expected Behavior

The client should use the base_url from the provider configuration when provider_category is "byok", similar to how other BYOK-enabled clients work in the codebase.

Root Cause

The _get_anthropic_client() and _get_anthropic_client_async() methods in letta/llm_api/anthropic_client.py do not fetch or use the provider's base_url from ProviderManager, unlike other client implementations.

Proposed Solution

Follow the same pattern used by other BYOK-enabled clients:

  1. Add get_byok_overrides() and get_byok_overrides_async() methods
  2. Fetch base_url and api_key from ProviderManager when provider_category == "byok"
  3. Pass the custom base_url to the Anthropic SDK client initialization

I have a working fix with comprehensive tests ready to submit as a PR.

Environment

  • Letta version: main branch (latest)
  • Affected component: letta/llm_api/anthropic_client.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions