2# Vercel AI SDK, Next.js, and Perplexity.ai Chat Example
This example shows how to use the Vercel AI SDK with Next.js and Perplexity.ai to create a ChatGPT-like AI-powered streaming chat bot. Perplexity's APIs are compatible with OpenAI's so we use the OpenAI JS SDK but change its base URL to point to Perplexity's API with an environment variable.
Deploy the example using Vercel:
Execute create-next-app
with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example https://github.com/vercel/ai/tree/main/examples/next-perplexity next-perplexity-app
yarn create next-app --example https://github.com/vercel/ai/tree/main/examples/next-perplexity next-perplexity-app
pnpm create next-app --example https://github.com/vercel/ai/tree/main/examples/next-perplexity next-perplexity-app
To run the example locally you need to:
- Sign up at Perplexity.ai's Developer Platform.
- Go to Perplexity.ai's dashboard and create an API KEY.
- Set the required environment variables as shown the example env file but in a new file called
.env.local
pnpm install
to install the required dependencies.pnpm dev
to launch the development server.
To learn more about OpenAI, Next.js, and the Vercel AI SDK take a look at the following resources:
- Vercel AI SDK docs
- Vercel AI Playground
- Perplexity.ai Documentation - learn about Perplexity AI features and API.
- Next.js Documentation - learn about Next.js features and API.