The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
add context_management header for compact_20260112 for messages
Sameer Kankute285b2d2a125c
diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.pyindex 308bf367d06..52e3ca7159d 100644--- a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py+++ b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py@@ -189,8 +189,27 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):beta_values.update(b.strip() for b in existing_beta.split(","))# Check for context management- if optional_params.get("context_management") is not None:- beta_values.add(ANTHROPIC_BETA_HEADER_VALUES.CONTEXT_MANAGEMENT_2025_06_27.value)+ context_management_param = optional_params.get("context_management")+ if context_management_param is not None:+ # Check edits array for compact_20260112 type+ edits = context_management_param.get("edits", [])+ has_compact = False+ has_other = False++ for edit in edits:+ edit_type = edit.get("type", "")+ if edit_type == "compact_20260112":+ has_compact = True+ else:+ has_other = True++ # Add compact header if any compact edits exist+ if has_compact:+ beta_values.add(ANTHROPIC_BETA_HEADER_VALUES.COMPACT_2026_01_12.value)++ # Add context management header if any other edits exist+ if has_other:+ beta_values.add(ANTHROPIC_BETA_HEADER_VALUES.CONTEXT_MANAGEMENT_2025_06_27.value)# Check for structured outputsif optional_params.get("output_format") is not None: