Skip to main content

Overview

Mastra is an open-source TypeScript framework for building AI agents and workflows. It ships first-class Perplexity integrations through its model router and tool system, so you can wire Perplexity into a Mastra Agent with a single string identifier or expose the Search API as a Mastra-compatible tool.
Mastra provides a unified Agent interface, a model router, and a tools/MCP system for orchestrating LLM workflows. Learn more at mastra.ai.
The Mastra ecosystem provides three Perplexity integrations:
  • Perplexity model provider — Use Perplexity’s web-grounded models in a Mastra Agent.
  • Perplexity Agent provider — Use the Agent API (OpenAI-compatible /chat/completions) through Mastra.
  • Perplexity Search tool — Expose the Search API as a Mastra tool for ranked web results.

API Key Setup

All three integrations read your Perplexity API key from the environment:
The Search tool also accepts PPLX_API_KEY as a fallback.

Get API Key

Generate your API key from the Perplexity dashboard.

Perplexity Model Provider

Use Perplexity’s web-grounded models inside a Mastra Agent through the model router.
The agent supports both agent.generate(...) and agent.stream(...). For the full list of Perplexity models available through the router, see the Mastra Perplexity provider docs.

Perplexity Agent Provider

The Agent provider routes through Perplexity’s OpenAI-compatible /chat/completions endpoint, giving you access to third-party models served by the Agent API.
For finer control — for example, custom headers or a pinned base URL — pass an object instead of a string:
See the Mastra Perplexity Agent provider docs for the full list of supported models and configuration options.

Perplexity Search Tool

The @mastra/perplexity package wraps the Search API as a Mastra-compatible tool. Use this when you want raw ranked web results — for chat completions or agentic workflows, prefer the model or Agent provider above.
The tool ID is perplexity-search and supported input parameters include query, maxResults, searchDomainFilter, searchRecencyFilter, searchAfterDateFilter, and searchBeforeDateFilter. Each result includes title, url, snippet, and an optional date. To register multiple Perplexity tools at once, use createPerplexityTools(config?). See the Mastra Perplexity tool reference for the full schema.

Perplexity Model Provider

Use Perplexity models in a Mastra Agent.

Perplexity Agent Provider

Use the Perplexity Agent API through Mastra.

Perplexity Search Tool

Wrap the Perplexity Search API as a Mastra tool.

Mastra Docs

Learn more about agents, tools, and workflows in Mastra.

Support

Need help with the integration?