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 logging and encrypted content extraction
Sameer Kankutea88a17796b38
diff --git a/litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py b/litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.pyindex cdf69e4b24c..9cab59ea0e0 100644--- a/litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py+++ b/litellm/router_utils/pre_call_checks/encrypted_content_affinity_check.py@@ -76,26 +76,31 @@ class EncryptedContentAffinityCheck(CustomLogger):def _extract_item_ids_from_output(output: list,) -> List[str]:- """Extract all item IDs from a Responses API output list."""+ """Extract item IDs from output items that contain encrypted_content."""item_ids: List[str] = []for item in output:item_id: Optional[str] = None+ has_encrypted_content = False+if isinstance(item, dict):item_id = item.get("id")+ has_encrypted_content = "encrypted_content" in itemelse:item_id = getattr(item, "id", None)- if item_id and isinstance(item_id, str):+ has_encrypted_content = hasattr(item, "encrypted_content")++ if item_id and isinstance(item_id, str) and has_encrypted_content:item_ids.append(item_id)return item_ids@staticmethoddef _extract_item_ids_from_input(request_input: Any) -> List[str]:"""- Extract item IDs from the ``input`` field of a Responses API request.+ Extract item IDs from input items that contain encrypted_content.``input`` can be:- a plain string -> no item IDs- - a list of items -> each item may have an ``id`` field+ - a list of items -> only extract IDs from items with encrypted_content"""if not isinstance(request_input, list):return []@@ -104,7 +109,8 @@ class EncryptedContentAffinityCheck(CustomLogger):for item in request_input:if isinstance(item, dict):item_id = item.get("id")- if item_id and isinstance(item_id, str):+ has_encrypted_content = "encrypted_content" in item+ if item_id and isinstance(item_id, str) and has_encrypted_content:item_ids.append(item_id)return item_ids@@ -191,13 +197,13 @@ class EncryptedContentAffinityCheck(CustomLogger):ttl=self.ttl_seconds,)except Exception as e:- verbose_router_logger.debug(+ verbose_router_logger.error("EncryptedContentAffinityCheck: failed to cache item_id=%s error=%s",item_id,e,)- verbose_router_logger.info(+ verbose_router_logger.debug("EncryptedContentAffinityCheck: cached %d item IDs -> deployment=%s",len(item_ids),model_id,@@ -247,7 +253,7 @@ class EncryptedContentAffinityCheck(CustomLogger):model_id=cached_model_id,)if deployment is not None:- verbose_router_logger.info(+ verbose_router_logger.debug("EncryptedContentAffinityCheck: item_id=%s pinning -> deployment=%s",item_id,cached_model_id,@@ -257,7 +263,7 @@ class EncryptedContentAffinityCheck(CustomLogger):] = Truereturn [deployment]- verbose_router_logger.info(+ verbose_router_logger.debug("EncryptedContentAffinityCheck: cached deployment=%s for item_id=%s ""not found in healthy_deployments",cached_model_id,diff --git a/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py b/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.pyindex c70290b674d..17cd2162d99 100644--- a/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py+++ b/tests/test_litellm/router_utils/pre_call_checks/test_encrypted_content_affinity_check.py@@ -48,6 +48,7 @@ async def test_encrypted_content_affinity_tracks_and_routes():"type": "reasoning","id": "rs_encrypted_item_456","status": "completed",+ "encrypted_content": "gAAAAABpnW_yEYmSNEyOG...",},],"parallel_tool_calls": True,@@ -118,7 +119,7 @@ async def test_encrypted_content_affinity_tracks_and_routes():model=model_group,input=[{"type": "message", "id": "msg_abc123", "role": "assistant"},- {"type": "reasoning", "id": "rs_encrypted_item_456"},+ {"type": "reasoning", "id": "rs_encrypted_item_456", "encrypted_content": "gAAAAABpnW_yEYmSNEyOG..."},],)second_model_id = second_response._hidden_params["model_id"]@@ -204,6 +205,7 @@ async def test_encrypted_content_affinity_bypasses_rpm_limits():"type": "reasoning","id": "rs_encrypted_must_pin","status": "completed",+ "encrypted_content": "gAAAAABpnW_yEYmSNEyOG...",},],"usage": {"input_tokens": 5, "output_tokens": 10, "total_tokens": 15},@@ -255,7 +257,7 @@ async def test_encrypted_content_affinity_bypasses_rpm_limits():second_response = await router.aresponses(model="openai.gpt-5.1-codex",input=[- {"type": "reasoning", "id": "rs_encrypted_must_pin"},+ {"type": "reasoning", "id": "rs_encrypted_must_pin", "encrypted_content": "gAAAAABpnW_yEYmSNEyOG..."},],)second_model_id = second_response._hidden_params["model_id"]