PatternsSDK API

Sources & Citations

Loading pattern preview

Loading preview…

Problems solved

Technical challenges this implementation handles out of the box.
  • Answer questions with citation-backed Perplexity Sonar responses
  • Stream clickable source links for fact-checking
  • Smooth word-chunked token streaming for readable answers

Use cases

Products and workflows this pattern is designed to support.
  • Research assistants with citations
  • Fact-checking chat experiences
  • News and information verification tools
  • Educational tutors that show sources

Setup

Requirements, wiring steps, and what this pattern adds to your project.

Getting started

Pick how you want to pull this pattern in — then wire env vars and routes the same way.

  1. 1

    Install from the preview toolbar

    Shadcn Icon

    Copy the install command above and run it in your project — Pro patterns include a short-lived token.

  2. 2

    Add environment variables to .env.local

    PERPLEXITY_API_KEY

  3. 3

    Point client fetches at your API routes

    Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.

  4. 4

    Customize the agent and tool files

    Adapt prompts, tools, and stop conditions for your product — Copy for AI in the toolbar helps seed that work.

  5. 5

    Run your dev server and open the pattern route

    Install dependencies if needed, then start the app and verify responses.

Environment variables

Capabilities

AI SDK APIs

streamTextconvertToModelMessages

Providers

Perplexity

Files added

6 files
  • app/page.tsx
  • app/layout.tsx
  • lib/request-utils.ts
  • components/sources-chat-form.tsx
  • app/api/chat/route.ts
  • README.md

Dependencies

7 total

npm packages

4
AISDKlucide-reactNext.jsReact

Shadcn IconRegistry components

3
emptyscroll-areatooltip

Critical files

  • chat/route.ts

    API route demonstrating perplexity/sonar integration with sendSources: true for citation-backed responses. Uses smoothStream with word chunking.

Requirements

Complexity
Beginner
Setup time
~15 minutes
Node
24+
Memory
512MB
Upstash Redis