diff --git a/litellm/llms/openrouter/chat/transformation.py b/litellm/llms/openrouter/chat/transformation.py index 77a902149d9..cba391c9ba2 100644 --- a/litellm/llms/openrouter/chat/transformation.py +++ b/litellm/llms/openrouter/chat/transformation.py @@ -36,6 +36,7 @@ class CacheControlSupportedModels(str, Enum): MINIMAX = "minimax" GLM = "glm" ZAI = "z-ai" + QWEN = "qwen" class OpenrouterConfig(OpenAIGPTConfig): @@ -50,6 +51,11 @@ class OpenrouterConfig(OpenAIGPTConfig): ): supported_params.append("reasoning_effort") supported_params.append("thinking") + + if self._supports_cache_control_in_content(model): + 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 8ecf9b4a8a2..2cd294ed9ac 100644 --- a/tests/llm_translation/test_openrouter.py +++ b/tests/llm_translation/test_openrouter.py @@ -40,3 +40,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!") + +