Perplexity Provider

Perplexity is supported via OpenAI API compatibility - the OpenAI provider is used in the examples below.

The Perplexity provider contains language model support for the Perplexity API. It creates language model objects that can be used with the generateText and streamText.


The Perplexity provider is available via the @ai-sdk/openai module as it is compatible with the OpenAI API. You can install it with

pnpm install @ai-sdk/openai

Provider Instance

To use Perplexity, you can create a custom provider instance with the createOpenAI function from @ai-sdk/openai:

import { createOpenAI } from '@ai-sdk/openai';
const perplexity = createOpenAI({
apiKey: process.env.PERPLEXITY_API_KEY ?? '',
baseURL: '',


You can create Perplexity models using a provider instance. The first argument is the model id, e.g. llama-3-sonar-large-32k-online.

const model = perplexity('llama-3-sonar-large-32k-online');