Learning resourcesReviewed · Perplexity

Perplexity with Mastra

Perplexity with Mastra is a guide for TypeScript developers adding Perplexity to Mastra agents, although web-grounded answers through the Agent API, and reading their sources, require a custom fetch hook. It demonstrates an Agent API connection through @ai-sdk/open-responses and a separate @mastra/perplexity tool for retrieving ranked web results.

Researched 14 Nov 2026

In short.

Perplexity with Mastra is a guide for TypeScript developers connecting Mastra agents to Perplexity, with a custom request hook needed for its web-grounded answer example. It shows two routes: use @ai-sdk/open-responses to generate answers through the Agent API, or use @mastra/perplexity to retrieve ranked search results. The guide explains that result.sources remains empty on the generation route, so its example extracts sources from the raw response. Streaming source extraction, package compatibility, prices and licensing are not established, and none of the examples were executed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the entire selected page at [https://docs.perplexity.ai/docs/getting-started/integrations/mastra.md], including its API-key instructions, legacy-provider warning, generation and search examples, source-extraction caveats and resource links. The original capture is selected-page.txt, acquired at 2026-11-14T20:19:26.597Z with source SHA-256 ad874da7e29ef8b98b96276d6f95f7767e2f891553ee3c4869bbe4d04b2aa7f2. Linked documentation, the documentation index, package contents, pricing and licence pages are excluded. Nothing was executed; runtime behaviour, compatibility, performance and answer quality were not assessed.

The overview

Identity

Perplexity with Mastra is a documentation tutorial published at [https://docs.perplexity.ai/docs/getting-started/integrations/mastra.md]. It explains how to connect Perplexity services to Mastra, which the page describes as an open-source TypeScript framework for AI agents and workflows.

The resource covers two integrations: Agent API access through the Open Responses provider and Search API access through a Mastra-compatible tool.

Assessment

The guide provides a concrete starting point for developers who already use Mastra. Its most useful detail is the explanation of provider limitations: enabling Perplexity's built-in web search requires modifying the outgoing request, and retrieving sources requires reading the raw response.

The examples demonstrate integration structure, but they do not establish production reliability, answer accuracy or compatibility with a particular dependency version. Those properties were not assessed.

Users

The primary audience is TypeScript developers building Mastra research agents or workflows that need web information. Developers can choose generated answers through the Agent API or ranked search results (title, URL, snippet and optional date) that their own agent processes.

Beginners will need familiarity with npm packages, API keys, environment variables and asynchronous JavaScript. The page supplies examples but does not teach those prerequisites or show a complete application.

Capabilities

The Agent API route supports agent.generate and agent.stream according to the guide. Its extended example enables the web_search tool and extracts search results for use as supporting sources.

The Search tool returns ranked results containing a title, URL, snippet and optional date. Documented inputs include query, maxResults, searchDomainFilter, searchRecencyFilter, searchAfterDateFilter and searchBeforeDateFilter. The page also names createPerplexityTools(config?) for creating multiple Perplexity tools, without documenting its full schema.

Using it

Requirements

Both routes require a Perplexity API key. The examples use PERPLEXITY_API_KEY, and the Search tool additionally accepts PPLX_API_KEY as a fallback. The generation example installs @mastra/core and @ai-sdk/open-responses; the search example installs @mastra/perplexity and zod.

The code uses TypeScript, environment-variable access and network requests to Perplexity. Required runtime versions, supported package-version combinations, account billing prerequisites and rate limits are not specified.

Mechanism

For generation, createOpenResponses points a provider at [https://api.perplexity.ai/v1/responses]. A model returned by that provider is passed into a Mastra Agent. The page warns that Mastra's built-in perplexity and perplexity-agent router providers target the legacy Chat Completions endpoint and directs Agent API users to this Open Responses connection.

For web search, a custom fetch hook sets the request body's tools array to a single web_search entry, replacing any tools already declared. On non-streaming responses, it clones the response and extracts search_results items from the output array because the provider does not expose them through result.sources.

The separate createPerplexitySearchTool wrapper exposes search as the tool perplexity-search. Its demonstrated execute call returns retrieved results directly rather than generating an answer.

Setup

For the generation route, the documented installation command is npm install @mastra/core @ai-sdk/open-responses. Set PERPLEXITY_API_KEY, configure createOpenResponses with the Perplexity endpoint and key, and pass the selected model into a Mastra Agent.

For the search route, the command is npm install @mastra/perplexity zod. Create the tool with createPerplexitySearchTool and call execute with a context containing the query and optional filters. The page demonstrates direct execution but does not show the full registration of this tool into an agent.

To reproduce the web-grounded generation example, add its custom fetch hook and raw-response source extraction. The basic generation example alone does not enable web_search.

Example

The generation example creates a Research Agent using the documented model ID openai/gpt-5.6-luna and asks for a short explanation of the Agent API. An extended example asks about fusion-energy developments, enables web_search and prints source titles and URLs extracted from the response.

The standalone search example requests nuclear-fusion results with maxResults set to 5 and searchRecencyFilter set to month, then prints each result's title and URL. These are supplied code examples; no actual answers, search results or execution measurements are provided.

Assessment & evidence

Limitations

The provider does not expose the documented sources through result.sources. The workaround only reads sources for non-streaming responses; although agent.stream is supported according to the page, streaming source extraction is not demonstrated.

The hook replaces body.tools with a web_search entry, so combining it with other tool declarations would require adapting the example. It also stores sources in a shared variable, which would need request-specific handling for concurrent use.

The examples do not demonstrate retries, API-error handling or response validation. No code was executed, so runtime compatibility, latency, reliability and citation quality remain unassessed.

Choosing an approach

The generation route fits a workflow that asks a Mastra agent to produce an answer through Perplexity. Adding web_search also requests supporting web information, but displaying sources requires the additional extraction code shown in the guide.

The Search tool fits a workflow that needs ranked search results as inputs to its own processing or answer generation. This distinction follows from the examples: one returns agent-generated text, while the other returns result records. The page provides no evidence that either route is faster, cheaper or more accurate.

Alternatives

The two documented alternatives are Agent API generation through @ai-sdk/open-responses and direct retrieval through @mastra/perplexity. They serve different needs and are not presented with comparative measurements.

The page links to the official Perplexity SDK and further Mastra documentation, but those pages are outside the evidence. Their setup, capabilities and suitability cannot be compared here.

Evidence

The evidence is the complete Perplexity documentation page at [https://docs.perplexity.ai/docs/getting-started/integrations/mastra.md]. It includes installation commands, TypeScript examples, a legacy-provider warning, source-handling limitations and links to additional references.

The page supports descriptions of the documented integration patterns. It supplies no execution logs, benchmark results, dependency lockfile or independent confirmation of the examples' behaviour.

Access & freshness

Costs

The page provides no prices for generation, web search or standalone Search API requests. Free allowances, billing requirements and spending controls are also unknown from this evidence.

An API-key setup example does not establish free access. No supported estimate of cost per answer, search or workflow can be made from this page.

Rights

The page describes Mastra as open source but does not identify a licence or supply licence terms for Mastra, the integration packages, documentation or examples. Specific reuse and redistribution permissions are therefore unknown.

Rights and obligations for generated answers, retrieved snippets and linked web content are not explained. The evidence does not establish permission to redistribute the captured documentation.

Freshness

The supplied page was captured on 14 November 2026. It contains no explicit publication or last-updated date, so the capture date does not establish when its instructions changed.

The installation commands do not pin package versions. Present model availability, dependency compatibility and whether the documented provider limitations have changed are unknown beyond this captured page.

Next steps

Choose whether the application needs generated answers or raw search results, then follow the corresponding package and API-key setup. Verify current package compatibility, model availability, pricing and licence terms before committing to the integration.

If users need visible sources, implement source extraction with per-request storage and define how streaming responses will expose citations. Adapt the sample's tool-array replacement if the application needs additional tools, and assess error handling and behaviour in the intended runtime.

Evidence for this report

selected-page.txtselected · checked 2026-11-14