Skip to main content

Perplexity AI

Perplexity AI provides search-augmented LLMs with an OpenAI-compatible API.

Install

pip install synapsekit[openai]

Perplexity AI uses the OpenAI-compatible API, so it requires the openai package.

Usage

from synapsekit import LLMConfig
from synapsekit.llm.perplexity import PerplexityLLM

llm = PerplexityLLM(LLMConfig(
model="sonar-pro",
api_key="pplx-...",
))

async for token in llm.stream("What is RAG?"):
print(token, end="", flush=True)

Available models

ModelID
Sonarsonar
Sonar Prosonar-pro
Sonar Reasoningsonar-reasoning
Sonar Reasoning Prosonar-reasoning-pro

See the full list at docs.perplexity.ai.

Function calling

result = await llm.call_with_tools(messages, tools)

Custom base URL

llm = PerplexityLLM(config, base_url="http://localhost:8000/v1")

Parameters

ParameterDescription
modelPerplexity model ID
api_keyYour Perplexity API key
base_urlCustom API base URL (default: https://api.perplexity.ai)