From 9dbb06ca297dd3e9fcf1cf961f8f3ec2c47b712a Mon Sep 17 00:00:00 2001 From: Saleh Alghusson Date: Thu, 27 Aug 2026 18:26:53 -0400 Subject: [PATCH] fix: preserve case-insensitive Perplexity header overrides --- litellm/llms/perplexity/chat/transformation.py | 3 ++- .../chat/test_perplexity_chat_transformation.py | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/litellm/llms/perplexity/chat/transformation.py b/litellm/llms/perplexity/chat/transformation.py index c29f35dece9..085c7644566 100644 --- a/litellm/llms/perplexity/chat/transformation.py +++ b/litellm/llms/perplexity/chat/transformation.py @@ -37,7 +37,8 @@ class PerplexityChatConfig(OpenAIGPTConfig): api_key: str | None = None, api_base: str | None = None, ) -> dict: # mutable-ok: matches the base chat transform signature - headers.setdefault("X-Pplx-Integration", "litellm") + if not any(name.lower() == "x-pplx-integration" for name in headers): + headers["X-Pplx-Integration"] = "litellm" return super().validate_environment( headers, model, messages, optional_params, litellm_params, api_key, api_base ) diff --git a/tests/test_litellm/llms/perplexity/chat/test_perplexity_chat_transformation.py b/tests/test_litellm/llms/perplexity/chat/test_perplexity_chat_transformation.py index b679aa330fb..7966f60d683 100644 --- a/tests/test_litellm/llms/perplexity/chat/test_perplexity_chat_transformation.py +++ b/tests/test_litellm/llms/perplexity/chat/test_perplexity_chat_transformation.py @@ -5,12 +5,10 @@ Tests the response transformation to extract citation tokens and search queries from Perplexity API responses. """ -from unittest.mock import Mock - +import httpx import pytest # Add the project root to Python path - from litellm import ModelResponse from litellm.llms.perplexity.chat.transformation import PerplexityChatConfig from litellm.types.utils import Usage @@ -21,18 +19,19 @@ class TestPerplexityChatTransformation: @pytest.mark.parametrize( ("headers", "expected"), - [({}, "litellm"), ({"X-Pplx-Integration": "custom"}, "custom")], + [({}, "litellm"), ({"x-pplx-integration": "custom"}, "custom")], ) def test_integration_header_default_is_caller_overridable(self, headers, expected): - result = PerplexityChatConfig().validate_environment( + headers = PerplexityChatConfig().validate_environment( headers=headers, model="sonar", messages=[], optional_params={}, litellm_params={}, ) + request = httpx.Request("POST", "https://api.perplexity.ai/chat/completions", headers=headers) - assert result["X-Pplx-Integration"] == expected + assert request.headers.get_list("x-pplx-integration") == [expected] def test_enhance_usage_with_citation_tokens(self): """Test extraction of citation tokens from API response."""