Documentation Index
Fetch the complete documentation index at: https://docs.perplexity.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Vercel AI SDK is a TypeScript-first toolkit for building AI-powered apps with a unified provider interface, streaming primitives, and React hooks. The official@ai-sdk/perplexity provider gives you full access to Perplexity’s Sonar models — including streaming, citations, image results, and PDF inputs — with a one-line model identifier.
Vercel AI SDK powers
generateText, streamText, generateObject, and React hooks like useChat and useCompletion. Learn more at ai-sdk.dev.Installation
- pnpm
- npm
- yarn
- bun
API Key Setup
Set your Perplexity API key:Get API Key
Generate your Perplexity API key from the API portal.
Quick Start
Import the default provider instance and callgenerateText:
Accessing Citations
Every response includes asources array of the URLs Perplexity consulted:
Provider Options
Pass Perplexity-specific parameters throughproviderOptions.perplexity:
| Option | Type | Description |
|---|---|---|
return_images | boolean | Include images in the response (Tier-2+ accounts). |
search_recency_filter | string | One of 'hour', 'day', 'week', 'month'. |
Custom Provider Configuration
UsecreatePerplexity when you need a custom base URL, headers, or a custom fetch implementation:
PDF Inputs
Sonar models can read PDF files passed asfile message parts:
Supported Models
| Model | Image Input | Object Generation |
|---|---|---|
sonar | Yes | Yes |
sonar-pro | Yes | Yes |
sonar-reasoning | Yes | Yes |
sonar-reasoning-pro | Yes | Yes |
sonar-deep-research | No | Yes |
Streaming and React Hooks
The provider works seamlessly withstreamText, useChat, and useCompletion from ai/react. Drop perplexity("sonar-pro") into any AI SDK helper that takes a model:
Links & Resources
Vercel AI SDK Provider
Official
@ai-sdk/perplexity provider docs.Vercel AI SDK Docs
Full Vercel AI SDK documentation.
Perplexity API Reference
Full Perplexity API parameter reference.
Perplexity Models
Available Sonar models and capabilities.
Support
Need help with the integration?- Browse the Vercel AI SDK documentation
- Review our FAQ