Perplexity with Haystack
Overview
Section titled “Overview”The perplexity-haystack package provides Haystack components for Perplexity's Agent API, Embeddings API, and grounded Search API, so you can build retrieval-augmented and agentic pipelines that combine chat, embeddings, and live web search.
The integration includes:
- PerplexityChatGenerator — Chat generation through the Agent API.
- PerplexityTextEmbedder and PerplexityDocumentEmbedder — Embeddings through the Embeddings API.
- PerplexityWebSearch — Ranked, grounded web results through the Search API.
Installation
Section titled “Installation”pip install perplexity-haystackuv add perplexity-haystackAPI Key Setup
Section titled “API Key Setup”Set your Perplexity API key as an environment variable:
import os
os.environ["PERPLEXITY_API_KEY"] = "your_api_key_here"Get API Key
Generate your API key from the Perplexity dashboard.
Quick Start: Chat (Agent API)
Section titled “Quick Start: Chat (Agent API)”PerplexityChatGenerator is powered by the Perplexity Agent API. Set the model explicitly so your integration does not depend on the package default.
import os
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.generators.perplexity import PerplexityChatGenerator
os.environ["PERPLEXITY_API_KEY"] = "your_api_key_here"
client = PerplexityChatGenerator(model="openai/gpt-5.6-terra")
response = client.run(
messages=[ChatMessage.from_user("What are Agentic Pipelines? Be brief.")]
)
print(response["replies"])Selecting a Model
Section titled “Selecting a Model”You can pick any of the supported Agent API models via the model parameter:
client = PerplexityChatGenerator(model="anthropic/claude-sonnet-4-6")Supported models include openai/gpt-5.6-terra, openai/gpt-5.5, anthropic/claude-sonnet-4-6, xai/grok-4.5, and google/gemini-3-flash-preview. See the Agent API models page for the full list.
Quick Start: Embeddings
Section titled “Quick Start: Embeddings”Embed a single query with PerplexityTextEmbedder:
import os
from haystack_integrations.components.embedders.perplexity import PerplexityTextEmbedder
os.environ["PERPLEXITY_API_KEY"] = "your_api_key_here"
embedder = PerplexityTextEmbedder()
response = embedder.run(text="What is Haystack by deepset?")
print(response["embedding"])Embed a list of documents with PerplexityDocumentEmbedder:
from haystack import Document
from haystack_integrations.components.embedders.perplexity import PerplexityDocumentEmbedder
docs = [Document(content="What is Haystack by deepset?")]
result = PerplexityDocumentEmbedder().run(documents=docs)
print(result["documents"][0].embedding)Both embedders default to pplx-embed-v1-0.6b. The larger pplx-embed-v1-4b model is also available — set it via the model parameter.
Quick Start: Web Search (Search API)
Section titled “Quick Start: Web Search (Search API)”Use PerplexityWebSearch to get ranked, grounded web results inside a Haystack pipeline:
import os
from haystack.utils import Secret
from haystack_integrations.components.websearch.perplexity import PerplexityWebSearch
os.environ["PERPLEXITY_API_KEY"] = "your_api_key_here"
websearch = PerplexityWebSearch(
api_key=Secret.from_env_var("PERPLEXITY_API_KEY"),
top_k=5,
)
result = websearch.run(query="What is Haystack by deepset?")
documents = result["documents"]
links = result["links"]
print(documents)
print(links)Links & Resources
Section titled “Links & Resources”Haystack Integrations
Catalog entry on haystack.deepset.ai
Source Code
perplexity-haystack on GitHub
PyPI Package
View on PyPI
Haystack Docs
Full Haystack documentation
Support
Section titled “Support”Need help with the integration?
- Check the Haystack documentation
- Open an issue at haystack-core-integrations
- Review our FAQ