From 330a7035187e98c2ec12e1bd3974f4acce5fdfad Mon Sep 17 00:00:00 2001 From: SwiftWinds <12981958+SwiftWinds@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:05:16 -0700 Subject: [PATCH] feat: always use our own compaction --- litellm/responses/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/litellm/responses/main.py b/litellm/responses/main.py index c82574278ba..7d7a6e4d572 100644 --- a/litellm/responses/main.py +++ b/litellm/responses/main.py @@ -919,7 +919,16 @@ def responses( **emulated_kwargs, ) - if responses_api_provider_config is None: + # If the user enables compaction context_management, always use our compaction handler, never the provider's native compaction + _has_compaction = False + _ctx_mgmt = response_api_optional_params.get("context_management") + if _ctx_mgmt and isinstance(_ctx_mgmt, list): + _has_compaction = any( + isinstance(e, dict) and e.get("type") == "compaction" + for e in _ctx_mgmt + ) + + if responses_api_provider_config is None or _has_compaction: return litellm_completion_transformation_handler.response_api_handler( model=model, input=input,