How-to

Vercel Perplexity IntegrationMarketplace

Learn how to integrate Perplexity with Vercel.
Table of Contents

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-70b-instruct

Type: Chat

Meta's CodeLlama 70B model hosted by Perplexity.

llama-3.1-8b-instruct

Type: Chat

Meta's Llama 8B model hosted by Perplexity.

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-chat

Type: Chat

Perplexity's 70B parameter chat model based on Llama 3.1 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-chat

Type: Chat

Perplexity's 8B 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:

  1. Navigate to the AI tab in your Vercel dashboard
  2. Select Perplexity API from the list of providers, and press Add
  3. Review the provider information, and press Add Provider
  4. 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
  5. Select the Connect to Project button
  6. You'll be redirected to the provider's website to complete the connection process
  7. 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
  8. Pull the environment variables into your project using Vercel CLI
    terminal
    vercel env pull .env.development.local
  9. Install the providers package
    pnpm
    yarn
    npm
    pnpm i openai ai
  10. Connect your project using the code below:
    Next.js (/app)
    Next.js (/pages)
    SvelteKit
    Other frameworks
    app/api/chat/route.ts
    // app/api/chat/route.ts
    import { OpenAIStream, StreamingTextResponse } from 'ai';
    import OpenAI from 'openai';
    const perplexity = new OpenAI({
    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 request
    const { messages } = await req.json();
    // Request the OpenAI-compatible API for the response based on the prompt
    const response = await perplexity.chat.completions.create({
    model: 'llama-3.1-sonar-small-128k-online',
    stream: true,
    messages: messages,
    });
    // Convert the response into a friendly text-stream
    const stream = OpenAIStream(response);
    // Respond with the stream
    return new StreamingTextResponse(stream);
    }
  1. Add the provider to your page using the code below:
    Next.js (/app)
    Next.js (/pages)
    SvelteKit
    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}>
    <input
    value={input}
    placeholder="Say something..."
    onChange={handleInputChange}
    />
    </form>
    </div>
    );
    }
Last updated on July 31, 2024