Implementation:BerriAI Litellm Anthropic Beta Headers Manager
| Attribute | Value |
|---|---|
| Sources | litellm/anthropic_beta_headers_manager.py |
| Domains | Provider Integration, Anthropic, Headers, Configuration |
| last_updated | 2026-02-15 16:00 GMT |
Overview
The Anthropic Beta Headers Manager provides centralized filtering, transformation, and validation of Anthropic beta headers across multiple LLM providers (Anthropic, Bedrock, Vertex AI, Azure AI).
Description
Anthropic uses the anthropic-beta HTTP header to gate access to beta features. Different providers that expose Anthropic models (direct API, AWS Bedrock, Google Vertex AI, Azure AI) support different subsets of these headers and may use different header names. This module manages the mapping.
The configuration is loaded from a JSON file (anthropic_beta_headers_config.json) that maps each beta header to a provider-specific header name (or null if unsupported). Configuration can be fetched from:
- Remote URL (default) -- fetched from GitHub and cached in memory.
- Local file -- bundled with the package; used when
LITELLM_LOCAL_ANTHROPIC_BETA_HEADERS=True.
Key classes and functions:
GetAnthropicBetaHeadersConfig-- Static utility class for loading, fetching, and validating the configuration.filter_and_transform_beta_headers()-- The primary API: takes a list of beta header values and a provider name, returns only the supported headers with provider-specific names applied.update_headers_with_filtered_beta()-- Modifies a request headers dict in place, filtering theanthropic-betaheader value.get_provider_name()-- Resolves provider aliases to canonical names.reload_beta_headers_config()-- Clears the cache and forces a fresh load.
Usage
Import the filtering functions when constructing requests to Anthropic-compatible providers:
from litellm.anthropic_beta_headers_manager import filter_and_transform_beta_headers
Code Reference
Source Location
/litellm/anthropic_beta_headers_manager.py (377 lines)
Key Functions
| Function | Signature | Purpose |
|---|---|---|
filter_and_transform_beta_headers |
def filter_and_transform_beta_headers(beta_headers: List[str], provider: str) -> List[str] |
Filters and maps beta headers for a specific provider |
update_headers_with_filtered_beta |
def update_headers_with_filtered_beta(headers: dict, provider: str) -> dict |
Updates request headers dict in place |
is_beta_header_supported |
def is_beta_header_supported(beta_header: str, provider: str) -> bool |
Checks if a specific header is supported |
get_provider_beta_header |
def get_provider_beta_header(anthropic_beta_header: str, provider: str) -> Optional[str] |
Returns provider-specific header name |
get_unsupported_headers |
def get_unsupported_headers(provider: str) -> List[str] |
Lists all unsupported headers for a provider |
reload_beta_headers_config |
def reload_beta_headers_config() -> Dict |
Forces a cache refresh |
get_beta_headers_config |
def get_beta_headers_config(url: str) -> dict |
Public entry point to load config (remote with local fallback) |
Class: GetAnthropicBetaHeadersConfig
| Method | Purpose |
|---|---|
load_local_beta_headers_config() |
Loads bundled JSON config from package resources |
fetch_remote_beta_headers_config(url, timeout=5) |
Fetches config from a remote URL via httpx |
validate_beta_headers_config(fetched_config) |
Validates that the config is a non-empty dict with provider keys |
Import
from litellm.anthropic_beta_headers_manager import (
filter_and_transform_beta_headers,
update_headers_with_filtered_beta,
is_beta_header_supported,
)
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
beta_headers |
List[str] |
List of Anthropic beta header values (e.g., ["max-tokens-3-5-sonnet-2024-07-15"])
|
provider |
str |
Provider name (e.g., "anthropic", "bedrock", "vertex_ai")
|
headers |
dict |
Full request headers dictionary (for update_headers_with_filtered_beta)
|
Outputs
| Return | Type | Description |
|---|---|---|
| Filtered headers | List[str] |
Sorted list of provider-specific beta header values |
| Updated headers | dict |
Modified request headers dict |
| Support check | bool |
Whether a specific header is supported |
Usage Examples
from litellm.anthropic_beta_headers_manager import (
filter_and_transform_beta_headers,
update_headers_with_filtered_beta,
)
# Filter beta headers for Bedrock
filtered = filter_and_transform_beta_headers(
beta_headers=["max-tokens-3-5-sonnet-2024-07-15", "unsupported-feature"],
provider="bedrock",
)
# Returns only headers supported by Bedrock with mapped names
# Update request headers in place
headers = {
"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15,computer-use-2024-10-22",
"content-type": "application/json",
}
update_headers_with_filtered_beta(headers, provider="vertex_ai")
# headers["anthropic-beta"] now contains only Vertex AI-supported values
Related Pages
- Implementation:BerriAI_Litellm_Constants - defines
ANTHROPIC_TOKEN_COUNTING_BETA_VERSIONand related constants - Implementation:BerriAI_Litellm_Lazy_Imports_Registry - registers Anthropic config classes for lazy loading