Overview
The Vercel AI SDK is a TypeScript toolkit for building AI apps — Next.js and React — with streaming primitives and UI hooks likeuseChat.
Reach the Agent API through the @ai-sdk/open-responses provider, pointed at Perplexity’s /v1/responses endpoint, to get a native AI SDK model you can pass to generateText, streamText, and useChat.
Create the provider on the server — a Next.js Route Handler, Server Action, or API route — so
PERPLEXITY_API_KEY never reaches the browser.Installation
API Key Setup
Get API Key
Generate your Perplexity API key from the API portal.
Quickstart
Create the provider withcreateOpenResponses, point it at /v1/responses, and call generateText.
Web-Grounded Answers
Add theweb_search tool to ground answers in real-time results from Perplexity’s web search — the same search that powers Perplexity’s own answer engine.
The 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.
@ai-sdk/open-responses does not surface the sources on the result — result.sources is empty.
That’s why the fetch hook reads them from the raw search_results item in the response output array.
See Reading Sources from the Response for the full response shape.
Presets
Presets bundle a model, tools, and a tuned system prompt for a use case, so you don’t wire them up yourself. Setpreset on the request body in the same fetch hook — a preset already includes web_search, so you don’t add tools separately.
Streaming
UsestreamText for token-by-token output.
In a Next.js Route Handler, return result.toUIMessageStreamResponse() and render it on the client with useChat.
Supported Models
Pass any Agent API model to the provider — OpenAI, Anthropic, Google, xAI, and more — all routed through your single Perplexity key.Agent API Models
Browse every available model and its pricing.
Links & Resources
Open Responses Provider
Configure the AI SDK provider used on this page.
Agent API Quickstart
Build with Agent API models, tools, and presets.
Web Search Tool
Ground answers in Perplexity’s real-time web search.
Vercel AI SDK Docs
Core generation APIs and UI hooks.
Support
Need help with the integration?- Browse the Vercel AI SDK documentation
- Review our FAQ