| name | perplexity-hello-world |
| description | Create a minimal working Perplexity Sonar search example with citations.
Use when starting a new Perplexity integration, testing your setup,
or learning basic search-with-citations patterns.
Trigger with phrases like "perplexity hello world", "perplexity example",
"perplexity quick start", "simple perplexity search".
|
| allowed-tools | Read, Write, Edit |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","perplexity","api","testing"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Perplexity Hello World
Overview
Minimal working example demonstrating Perplexity's core value: web-grounded answers with citations. Unlike standard LLMs, Perplexity searches the web for every query and returns cited sources.
Prerequisites
- Completed
perplexity-install-auth setup
openai package installed
PERPLEXITY_API_KEY environment variable set
Instructions
Step 1: Basic Search with Citations (TypeScript)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.PERPLEXITY_API_KEY,
baseURL: "https://api.perplexity.ai",
});
async function main() {
const response = await client.chat.completions.create({
model: "sonar",
messages: [
{
role: "system",
content: "Be precise and cite your sources.",
},
{
role: "user",
content: "What are the latest features in Node.js 22?",
},
],
});
const answer = response.choices[0].message.content;
console.log("Answer:", answer);
citations = (response ). || [];
.();
citations.( {
.();
});
.(, {
: response.?.,
: response.?.,
: response.?.,
});
}
().(.);