From 28469c82cfc438d599a4f7ea41753b1179c6477c Mon Sep 17 00:00:00 2001 From: Abdullah Habib Biswas Date: Sat, 30 May 2026 16:11:45 +0000 Subject: [PATCH 1/2] fix(openrouter): support cache_control for qwen models (#29322) --- .../llms/openrouter/chat/transformation.py | 6 +++++ tests/llm_translation/test_openrouter.py | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/litellm/llms/openrouter/chat/transformation.py b/litellm/llms/openrouter/chat/transformation.py index 0d7850e8c74..996af174f10 100644 --- a/litellm/llms/openrouter/chat/transformation.py +++ b/litellm/llms/openrouter/chat/transformation.py @@ -30,6 +30,7 @@ class CacheControlSupportedModels(str, Enum): MINIMAX = "minimax" GLM = "glm" ZAI = "z-ai" + QWEN = "qwen" class OpenrouterConfig(OpenAIGPTConfig): @@ -44,6 +45,11 @@ class OpenrouterConfig(OpenAIGPTConfig): ) or litellm.supports_reasoning(model=model): supported_params.append("reasoning_effort") supported_params.append("thinking") + + if "qwen" in model.lower(): + supported_params.append("cache_control") + supported_params.append("cache_control_injection_points") + except Exception: pass return list(dict.fromkeys(supported_params)) diff --git a/tests/llm_translation/test_openrouter.py b/tests/llm_translation/test_openrouter.py index 8fbb8803d11..67a7f7233c9 100644 --- a/tests/llm_translation/test_openrouter.py +++ b/tests/llm_translation/test_openrouter.py @@ -45,3 +45,25 @@ def test_openrouter_embedding(): assert resp.data[0]["embedding"] is not None assert isinstance(resp.data[0]["embedding"], list) assert len(resp.data[0]["embedding"]) > 0 + + +def test_openrouter_qwen_cache_control_supported(): + """ + Validates that Qwen models routed through OpenRouter cleanly support + cache_control and cache_control_injection_points parameters, + resolving issue #29322. + """ + from litellm.llms.openrouter.chat.transformation import OpenrouterConfig + + config = OpenrouterConfig() + qwen_model = "openrouter/qwen/qwen3.6-flash" + + # Retrieve the dynamically mapped parameters for the Qwen endpoint + supported_params = config.get_supported_openai_params(model=qwen_model) + + # Assertions to ensure the translation layer captures the caching parameters + assert "cache_control" in supported_params, f"cache_control missing from supported parameters for {qwen_model}" + assert "cache_control_injection_points" in supported_params, f"cache_control_injection_points missing from supported parameters for {qwen_model}" + print("✅ test_openrouter_qwen_cache_control_supported passed!") + + From 52134a2602c072f0721cc2fdc24098a54a98f2a3 Mon Sep 17 00:00:00 2001 From: Abdullah Habib Biswas Date: Sat, 30 May 2026 16:38:48 +0000 Subject: [PATCH 2/2] refactor(openrouter): use _supports_cache_control_in_content helper --- litellm/llms/openrouter/chat/transformation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/llms/openrouter/chat/transformation.py b/litellm/llms/openrouter/chat/transformation.py index 996af174f10..4c35d62798c 100644 --- a/litellm/llms/openrouter/chat/transformation.py +++ b/litellm/llms/openrouter/chat/transformation.py @@ -46,7 +46,7 @@ class OpenrouterConfig(OpenAIGPTConfig): supported_params.append("reasoning_effort") supported_params.append("thinking") - if "qwen" in model.lower(): + if self._supports_cache_control_in_content(model): supported_params.append("cache_control") supported_params.append("cache_control_injection_points")