Vercel Perplexity IntegrationMarketplace
Learn how to integrate Perplexity with Vercel.Perplexity API specializes in deep language understanding and generation models. Integrating Perplexity with Vercel allows your applications to use advanced text interpretation, sentiment analysis, and language modeling capabilities.
You can use the Vercel and Perplexity integration to power a variety of AI applications, including:
- Advanced text generation: Use Perplexity for creating sophisticated text generation tools for content creation and communication
- Semantic text analysis: Use Perplexity for applications requiring deep semantic analysis of text, such as sentiment analysis or topic detection
- Language understanding applications: Use Perplexity in tools for language understanding and translation, enhancing communication across languages
Perplexity provides models focused on deep language understanding and generation. They excel in tasks such as contextual text interpretation, predictive typing, and nuanced sentiment analysis.
llama-3.1-sonar-huge-128k-online
Type: Chat
Perplexity's 405B parameter chat model based on Llama 3 architecture
llama-3.1-sonar-large-128k-online
Type: Chat
Perplexity's latest 70B parameter chat model based on Llama 3.1 architecture
llama-3.1-sonar-small-128k-online
Type: Chat
Perplexity's 8B parameter chat model based on Llama 3.1 architecture
The Vercel Perplexity API integration can be accessed through the AI tab on your Vercel dashboard.
To follow this guide, you'll need the following:
- An existing Vercel project
- The latest version of Vercel CLI
pnpm i -g vercel@latest
- Navigate to the AI tab in your Vercel dashboard
- Select Perplexity API from the list of providers, and press Add
- Review the provider information, and press Add Provider
- You can now select which projects the provider will have access to. You can choose from All Projects or Specific Projects
- If you select Specific Projects, you'll be prompted to select the projects you want to connect to the provider. The list will display projects associated with your scoped team
- Multiple projects can be selected during this step
- Select the Connect to Project button
- You'll be redirected to the provider's website to complete the connection process
- Once the connection is complete, you'll be redirected back to the Vercel dashboard, and the provider integration dashboard page. From here you can manage your provider settings, view usage, and more
- Pull the environment variables into your project using Vercel CLI
terminal
vercel env pull .env.development.local
- Install the providers package
pnpm i openai ai
- Connect your project using the code below:
app/api/chat/route.ts// app/api/chat/route.tsimport { createOpenAI } from '@ai-sdk/openai';import { streamText } from 'ai';// Allow streaming responses up to 30 secondsexport const maxDuration = 30;const perplexity = createOpenAI({name: 'perplexity',apiKey: process.env.PERPLEXITY_API_KEY ?? '',baseURL: 'https://api.perplexity.ai/',});export async function POST(req: Request) {// Extract the `messages` from the body of the requestconst { messages } = await req.json();// Call the language modelconst result = streamText({model: perplexity('llama-3.1-sonar-large-32k-online'),messages,});// Respond with the streamreturn result.toDataStreamResponse();}
- Add the provider to your page using the code below:
app/chat/page.tsx// app/chat/page.tsx'use client';import { useChat } from 'ai/react';export default function Chat() {const { messages, input, handleInputChange, handleSubmit } = useChat();return (<div>{messages.map((m) => (<div key={m.id}>{m.role === 'user' ? 'User: ' : 'AI: '}{m.content}</div>))}<form onSubmit={handleSubmit}><inputvalue={input}placeholder="Say something..."onChange={handleInputChange}/></form></div>);}
Was this helpful?