Skip to main content

Overview

Mastra is an open-source TypeScript framework for building AI agents and workflows. Wire Perplexity’s Agent API into a Mastra Agent through the Open Responses provider, 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 two Perplexity integrations:
  • Agent API — Run the Agent API inside a Mastra Agent through the Open Responses provider.
  • Perplexity Search tool — Expose the Search API as a Mastra tool for ranked web results.

API Key Setup

Both 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.

Agent API

Mastra’s built-in perplexity and perplexity-agent model-router providers target Sonar Chat Completions, which is now the Agent API — more models, tools, and research-backed presets. Reach it through @ai-sdk/open-responses as shown below, or see the migration guide.
The Agent API speaks the Open Responses standard, so the @ai-sdk/open-responses provider connects to it directly. Point the provider at Perplexity’s /v1/responses endpoint, then pass the model id to your Mastra Agent:
The agent supports both agent.generate(...) and agent.stream(...). See the Agent API quickstart for the full model list, built-in tools, and presets. For web-grounded answers, add the web_search tool (below).

Web-Grounded Answers

Add the web_search tool to ground the agent’s answers in real-time results from Perplexity’s web search. The @ai-sdk/open-responses provider sends a fixed request body and does not expose the Agent API’s built-in tools as first-class options, so enable web_search by adding it to the body in the provider’s fetch hook — every call the agent makes through this provider is then grounded:
The answer is grounded server-side, but @ai-sdk/open-responses does not surface the sources on the result — result.sources is empty — so the fetch hook reads the raw search_results items directly. See Reading Sources from the Response for the full response shape.

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 to feed into an agent.
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.

Agent API Quickstart

Build with Agent API models, tools, and presets.

Perplexity SDK

Install and configure the official Perplexity SDK.

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?