diff --git a/litellm/llms/perplexity/chat/transformation.py b/litellm/llms/perplexity/chat/transformation.py index bf33103b480..2aa894eeed5 100644 --- a/litellm/llms/perplexity/chat/transformation.py +++ b/litellm/llms/perplexity/chat/transformation.py @@ -27,6 +27,21 @@ class PerplexityChatConfig(OpenAIGPTConfig): dynamic_api_key = api_key or get_secret_str("PERPLEXITYAI_API_KEY") or get_secret_str("PERPLEXITY_API_KEY") return api_base, dynamic_api_key + def validate_environment( + self, + headers: dict, + model: str, + messages: list[AllMessageValues], + optional_params: dict, + litellm_params: dict, + api_key: str | None = None, + api_base: str | None = None, + ) -> dict: + headers.setdefault("X-Pplx-Integration", "litellm") + return super().validate_environment( + headers, model, messages, optional_params, litellm_params, api_key, api_base + ) + def get_supported_openai_params(self, model: str) -> list: """ Perplexity supports a subset of OpenAI params 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 29d185b686d..b679aa330fb 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 @@ -19,6 +19,21 @@ from litellm.types.utils import Usage class TestPerplexityChatTransformation: """Test suite for Perplexity chat transformation functionality.""" + @pytest.mark.parametrize( + ("headers", "expected"), + [({}, "litellm"), ({"X-Pplx-Integration": "custom"}, "custom")], + ) + def test_integration_header_default_is_caller_overridable(self, headers, expected): + result = PerplexityChatConfig().validate_environment( + headers=headers, + model="sonar", + messages=[], + optional_params={}, + litellm_params={}, + ) + + assert result["X-Pplx-Integration"] == expected + def test_enhance_usage_with_citation_tokens(self): """Test extraction of citation tokens from API response.""" config = PerplexityChatConfig()