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
fix(anthropic): skip the derived prompt_cache_key for litellm_proxy deployments
mateo-berri8e1c8c1c62b9
diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.pyindex 5c72fee25a0..974a3b4bb73 100644--- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py+++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py@@ -15,6 +15,7 @@ from litellm.llms.anthropic.experimental_pass_through.utils import (OPENAI_MAX_TOOL_NAME_LENGTH: Final = 64TOOL_NAME_HASH_LENGTH: Final = 8TOOL_NAME_PREFIX_LENGTH: Final = OPENAI_MAX_TOOL_NAME_LENGTH - TOOL_NAME_HASH_LENGTH - 1 # 55+PROVIDERS_PROXYING_AN_UNKNOWN_BACKEND: Final = frozenset({"litellm_proxy"})def truncate_tool_name(name: str) -> str:@@ -916,6 +917,8 @@ class LiteLLMAnthropicMessagesAdapter:def _supports_prompt_cache_key(model: str | None, custom_llm_provider: str | None) -> bool:if not model or not custom_llm_provider:return False+ if custom_llm_provider in PROVIDERS_PROXYING_AN_UNKNOWN_BACKEND:+ return Falsesupported_params: Final = litellm.get_supported_openai_params(model=model, custom_llm_provider=custom_llm_provider)diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.pyindex dd1e8a93280..6edb3610bab 100644--- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py+++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py@@ -4,6 +4,8 @@ from typing import Any, castimport pytest+import litellm+sys.path.insert(0, os.path.abspath("../../../../.."))@@ -688,6 +690,15 @@ def test_translate_anthropic_to_openai_skips_prompt_cache_key_when_provider_lackassert "prompt_cache_key" not in openai_request+def test_translate_anthropic_to_openai_skips_prompt_cache_key_for_chained_litellm_proxy():+ assert "prompt_cache_key" in litellm.get_supported_openai_params(+ model="xai", custom_llm_provider="litellm_proxy"+ )+ openai_request = _translate_with_metadata("litellm_proxy/xai", {"user_id": "session-abc"}, "litellm_proxy")+ assert openai_request["user"] == "session-abc"+ assert "prompt_cache_key" not in openai_request++def test_translate_anthropic_to_openai_skips_prompt_cache_key_without_provider():openai_request = _translate_with_metadata("openai/gpt-5.6-luna", {"user_id": "session-abc"}, None)assert openai_request["user"] == "session-abc"diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.pyindex ad6fc04217f..5b7f2a60f68 100644--- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.py+++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_prompt_cache_key.py@@ -54,6 +54,12 @@ def test_prepare_completion_kwargs_skips_prompt_cache_key_without_provider_suppoassert "prompt_cache_key" not in completion_kwargs+def test_prepare_completion_kwargs_skips_prompt_cache_key_for_chained_litellm_proxy():+ completion_kwargs = _prepare("litellm_proxy/xai", {"custom_llm_provider": "litellm_proxy"})+ assert completion_kwargs["user"] == "session-abc"+ assert "prompt_cache_key" not in completion_kwargs++def test_prepare_completion_kwargs_keeps_prompt_cache_key_through_responses_reroute():completion_kwargs = _prepare("openai/gpt-5.6-luna",