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(main): forward store and prompt_cache_key params on chat completions (#33184)
Sujith39bd5fb8b792
diff --git a/litellm/main.py b/litellm/main.pyindex 7d457d9cdd1..81b02082abd 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -435,6 +435,8 @@ async def acompletion(verbosity: Optional[Literal["low", "medium", "high"]] = None,safety_identifier: Optional[str] = None,service_tier: Optional[str] = None,+ store: Optional[bool] = None,+ prompt_cache_key: Optional[str] = None,# set api_base, api_version, api_keybase_url: Optional[str] = None,api_version: Optional[str] = None,@@ -585,6 +587,8 @@ async def acompletion("verbosity": verbosity,"safety_identifier": safety_identifier,"service_tier": service_tier,+ "store": store,+ "prompt_cache_key": prompt_cache_key,"extra_headers": extra_headers,"acompletion": True, # assuming this is a required parameter"thinking": thinking,@@ -4828,6 +4832,8 @@ def completion( # type: ignoreextra_headers: Optional[dict] = None,safety_identifier: Optional[str] = None,service_tier: Optional[str] = None,+ store: Optional[bool] = None,+ prompt_cache_key: Optional[str] = None,# soon to be deprecated params by OpenAIfunctions: Optional[List] = None,function_call: Optional[str] = None,@@ -5249,6 +5255,8 @@ def completion( # type: ignore),"safety_identifier": safety_identifier,"service_tier": service_tier,+ "store": store,+ "prompt_cache_key": prompt_cache_key,"allowed_openai_params": kwargs.get("allowed_openai_params"),"base_model": base_model,}diff --git a/litellm/utils.py b/litellm/utils.pyindex 18b89ee0d13..b16ecdf88be 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -3791,6 +3791,8 @@ def get_optional_params(thinking: Optional[AnthropicThinkingParam] = None,web_search_options: Optional[OpenAIWebSearchOptions] = None,safety_identifier: Optional[str] = None,+ store: Optional[bool] = None,+ prompt_cache_key: Optional[str] = None,base_model: Optional[str] = None,**kwargs,):diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.pyindex 28cf4fa0744..0624b590df7 100644--- a/tests/test_litellm/test_main.py+++ b/tests/test_litellm/test_main.py@@ -2081,3 +2081,87 @@ def test_stream_chunk_builder_text_completion_combines_text_and_usage():assert response.usage.prompt_tokens > 0assert response.usage.completion_tokens > 0assert response.usage.total_tokens == response.usage.prompt_tokens + response.usage.completion_tokens+++def test_completion_forwards_store_and_prompt_cache_key_to_openai():+ """+ Regression test for https://github.com/BerriAI/litellm/issues/33184++ store and prompt_cache_key are documented OpenAI chat completion params that+ were accepted as supported but silently dropped before the provider request+ was built, because they were not named parameters of completion() and+ get_optional_params() the way safety_identifier is.+ """+ from openai import OpenAI++ client = OpenAI(api_key="fake-api-key")++ with patch.object(client.chat.completions.with_raw_response, "create") as mock_client:+ try:+ litellm.completion(+ model="openai/gpt-4o",+ messages=[{"role": "user", "content": "Hello"}],+ store=False,+ prompt_cache_key="test-cache-key",+ client=client,+ )+ except Exception as e:+ print(e)++ mock_client.assert_called_once()+ request_body = mock_client.call_args.kwargs+ assert request_body["store"] is False+ assert request_body["prompt_cache_key"] == "test-cache-key"+++async def test_acompletion_forwards_store_and_prompt_cache_key_to_openai():+ """+ Async variant of the store/prompt_cache_key forwarding regression test for+ https://github.com/BerriAI/litellm/issues/33184+ """+ from openai import AsyncOpenAI++ client = AsyncOpenAI(api_key="fake-api-key")++ with patch.object(client.chat.completions.with_raw_response, "create") as mock_client:+ try:+ await litellm.acompletion(+ model="openai/gpt-4o",+ messages=[{"role": "user", "content": "Hello"}],+ store=False,+ prompt_cache_key="test-cache-key",+ client=client,+ )+ except Exception as e:+ print(e)++ mock_client.assert_called_once()+ request_body = mock_client.call_args.kwargs+ assert request_body["store"] is False+ assert request_body["prompt_cache_key"] == "test-cache-key"+++def test_completion_omits_store_and_prompt_cache_key_when_not_passed():+ """+ When store and prompt_cache_key are not passed, they must not appear in the+ outbound request body (guards against always forwarding None defaults).+ """+ from openai import OpenAI++ client = OpenAI(api_key="fake-api-key")++ with patch.object(client.chat.completions.with_raw_response, "create") as mock_client:+ try:+ litellm.completion(+ model="openai/gpt-4o",+ messages=[{"role": "user", "content": "Hello"}],+ client=client,+ )+ except Exception as e:+ print(e)++ mock_client.assert_called_once()+ request_body = mock_client.call_args.kwargs+ assert "store" not in request_body+ assert "prompt_cache_key" not in request_body