
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@mastra/perplexity
Advanced tools
Affected versions:
Web search tool for Mastra agents, backed by the Perplexity Search API.
npm install @mastra/perplexity zod
import { Agent } from '@mastra/core/agent';
import { createPerplexitySearchTool } from '@mastra/perplexity';
const agent = new Agent({
id: 'research-agent',
name: 'Research Agent',
model: 'anthropic/claude-sonnet-4-6',
instructions:
'You are a research assistant. Use the perplexity-search tool to find up-to-date information from the web before answering.',
tools: {
search: createPerplexitySearchTool(),
},
});
The tool reads PERPLEXITY_API_KEY (or PPLX_API_KEY as a fallback) from the environment. Pass { apiKey } explicitly to override.
The Search API supports filtering by domain and date. All filters are optional.
const tool = createPerplexitySearchTool();
await tool.execute!({
query: 'recent papers on agent evaluation',
maxResults: 10,
searchRecencyFilter: 'month',
searchDomainFilter: ['arxiv.org', 'openreview.net'],
}, {} as any);
To exclude domains, prefix them with -. Don't mix allow- and deny-list entries in the same call.
searchDomainFilter: ['-pinterest.com', '-quora.com'];
Perplexity is also a first-class model provider in Mastra's model router. To chat with Perplexity models (separate from this search tool), set PERPLEXITY_API_KEY and reference the model directly:
import { Agent } from '@mastra/core/agent';
const agent = new Agent({
id: 'agent-api',
name: 'Perplexity Agent',
model: 'perplexity-agent/openai/gpt-5',
instructions: 'You are a research assistant powered by the Perplexity Agent API.',
});
See the Perplexity provider docs and Perplexity Agent provider docs.
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | PERPLEXITY_API_KEY → PPLX_API_KEY | Perplexity API key. |
baseUrl | string | https://api.perplexity.ai | Override the API base URL (useful for proxies and tests). |
fetch | typeof fetch | global fetch | Inject a custom fetch implementation. |
Apache-2.0
FAQs
Perplexity Search tool for Mastra agents
The npm package @mastra/perplexity receives a total of 1,547 weekly downloads. As such, @mastra/perplexity popularity was classified as popular.
We found that @mastra/perplexity demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.