Skip to main content

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

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 call generateText:

Accessing Citations

Every response includes a sources array of the URLs Perplexity consulted:

Provider Options

Pass Perplexity-specific parameters through providerOptions.perplexity:
Any other Perplexity API parameter can be passed the same way.

Custom Provider Configuration

Use createPerplexity when you need a custom base URL, headers, or a custom fetch implementation:

PDF Inputs

Sonar models can read PDF files passed as file message parts:
You can also pass a PDF URL:

Supported Models

See all available models for full capability details.

Streaming and React Hooks

The provider works with streamText, useChat, and useCompletion from ai/react. Drop perplexity("sonar-pro") into any AI SDK helper that takes a model:

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?