llm
Perplexity LLM service implementations.
This module provides services for Perplexity’s Agent API, which answers with web search over the OpenAI Responses protocol, and for its Sonar chat completions API, which Perplexity no longer supports.
- class pipecat.services.perplexity.llm.PerplexityAgentLLMSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, system_instruction: str | None | NotGiven = <factory>, temperature: float | None | NotGiven | NotGiven = <factory>, max_tokens: int | None | NotGiven = <factory>, top_p: float | None | NotGiven | NotGiven = <factory>, top_k: int | None | NotGiven = <factory>, frequency_penalty: float | None | NotGiven = <factory>, presence_penalty: float | None | NotGiven = <factory>, seed: int | None | NotGiven = <factory>, filter_incomplete_user_turns: bool | None | NotGiven = <factory>, user_turn_completion_config: UserTurnCompletionConfig | None | NotGiven = <factory>, use_provider_thinking_default: bool | NotGiven = <factory>, max_completion_tokens: int | NotGiven | NotGiven = <factory>, reasoning: OpenAIResponsesReasoningConfig | None | NotGiven = <factory>, preset: str | None | NotGiven = <factory>, web_search: bool | NotGiven = <factory>, max_steps: int | None | NotGiven = <factory>)[source]
Bases:
OpenAIResponsesLLMSettingsSettings for PerplexityAgentHttpLLMService.
- Parameters:
preset – Perplexity preset that sets the model, its instructions, its search budget and how much it reasons, such as
"fast","low","medium","high"or"xhigh".modelreplaces the preset’s model; setmodel=Noneto use it. WithNone, a model must be set, and a request with noreasoningeither gets the"fast"preset.web_search – Whether to offer the
web_searchtool on every request, alongside any tools from the context. A preset searches the web whatever this is set to.max_steps – Maximum number of search and reasoning steps per response.
Noneleaves Perplexity’s default.
- class pipecat.services.perplexity.llm.PerplexityAgentHttpLLMService(*, api_key: str | None = None, base_url: str = 'https://api.perplexity.ai/v1', settings: PerplexityAgentLLMSettings | None = None, **kwargs)[source]
Bases:
OpenAIResponsesHttpLLMServiceA service for Perplexity’s Agent API.
The Agent API answers questions with web search, using models from Perplexity and other providers. It speaks the OpenAI Responses protocol over HTTP, so function calling and multi-turn context work as they do with
OpenAIResponsesHttpLLMService.By default the service uses
openai/gpt-5.6-lunawith web search on. When neitherpresetnorreasoningis set, it sends Perplexity’sfastpreset, its lowest-latency configuration, with the model in place of the preset’s own. Answers can carry citation markers such as[1]. Anthropic models needmax_completion_tokensset.Example:
llm = PerplexityAgentHttpLLMService( api_key=os.getenv("PERPLEXITY_API_KEY"), settings=PerplexityAgentHttpLLMService.Settings( system_instruction="You are a helpful assistant.", ), )
- Settings
alias of
PerplexityAgentLLMSettings
- __init__(*, api_key: str | None = None, base_url: str = 'https://api.perplexity.ai/v1', settings: PerplexityAgentLLMSettings | None = None, **kwargs)[source]
Initialize the Perplexity Agent API LLM service.
- Parameters:
api_key – The API key for accessing Perplexity’s API.
base_url – The base URL for Perplexity’s API.
settings – Runtime-updatable settings.
**kwargs – Additional keyword arguments passed to OpenAIResponsesHttpLLMService.
- Raises:
ValueError – If the settings leave neither a model nor a preset.
- class pipecat.services.perplexity.llm.PerplexityLLMSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, system_instruction: str | None | NotGiven = <factory>, temperature: float | None | NotGiven | NotGiven = <factory>, max_tokens: int | None | NotGiven | NotGiven = <factory>, top_p: float | None | NotGiven | NotGiven = <factory>, top_k: int | None | NotGiven = <factory>, frequency_penalty: float | None | NotGiven | NotGiven = <factory>, presence_penalty: float | None | NotGiven | NotGiven = <factory>, seed: int | None | NotGiven | NotGiven = <factory>, filter_incomplete_user_turns: bool | None | NotGiven = <factory>, user_turn_completion_config: UserTurnCompletionConfig | None | NotGiven = <factory>, use_provider_thinking_default: bool | NotGiven = <factory>, max_completion_tokens: int | None | NotGiven | NotGiven = <factory>)[source]
Bases:
OpenAILLMSettingsSettings for PerplexityLLMService.
- class pipecat.services.perplexity.llm.PerplexityLLMService(**kwargs)[source]
Bases:
OpenAILLMServiceA service for Perplexity’s Sonar chat completions API.
This service extends OpenAILLMService to work with Perplexity’s API while maintaining compatibility with the OpenAI-style interface.
Deprecated since version 1.13.0: Use
PerplexityAgentHttpLLMServiceinstead. Perplexity has ended support for Sonar chat completions in favor of its Agent API. Will be removed in 2.0.0.- adapter_class
alias of
PerplexityLLMAdapter
- supports_developer_role: bool = False
Whether this service’s API supports the “developer” message role.
OpenAI’s native API supports it, but some OpenAI-compatible services (e.g. Cerebras) do not. Subclasses that don’t support it should set this to
False, which causes the adapter to convert “developer” messages to “user” messages before sending them to the API.
- Settings
alias of
PerplexityLLMSettings
- __init__(*, api_key: str, base_url: str = 'https://api.perplexity.ai', model: str | None = None, settings: PerplexityLLMSettings | None = None, **kwargs)[source]
Initialize the Perplexity LLM service.
- Parameters:
api_key – The API key for accessing Perplexity’s API.
base_url – The base URL for Perplexity’s API. Defaults to “https://api.perplexity.ai”.
model –
The model identifier to use. Defaults to “sonar”.
Deprecated since version 0.0.105: Use
settings=PerplexityLLMService.Settings(model=...)instead. Will be removed in 2.0.0.settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.**kwargs – Additional keyword arguments passed to OpenAILLMService.
- build_chat_completion_params(params_from_context: OpenAILLMInvocationParams) dict[source]
Build parameters for Perplexity chat completion request.
Perplexity uses a subset of OpenAI parameters and doesn’t support tools.
- Parameters:
params_from_context – Parameters, derived from the LLM context, to use for the chat completion. Contains messages, tools, and tool choice.
- Returns:
Dictionary of parameters for the chat completion request.