feat(perplexity): add integration attribution header

This commit is contained in:
saleh alghusson 2026-08-27 15:53:11 -04:00 committed by Saleh Alghusson
parent de53283356
commit dbb0a5f97c
No known key found for this signature in database
2 changed files with 30 additions and 0 deletions

View file

@ -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

View file

@ -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()