Skip to main content

Overview

The Vercel AI SDK is a TypeScript toolkit for building AI apps — Next.js and React — with streaming primitives and UI hooks like useChat. 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 with createOpenResponses, point it at /v1/responses, and call generateText.

Web-Grounded Answers

Add the web_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.
The answer is grounded server-side, but @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. Set preset on the request body in the same fetch hook — a preset already includes web_search, so you don’t add tools separately.
Presets scale from fast (single-fact lookups) to xhigh (open-ended, agentic work with code execution in a sandbox). See the presets guide to pick the right one.

Streaming

Use streamText 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.

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?