| name | perplexity-local-dev-loop |
| description | Configure Perplexity local development with mocking, testing, and hot reload.
Use when setting up a development environment, configuring test workflows,
or establishing a fast iteration cycle with Perplexity Sonar API.
Trigger with phrases like "perplexity dev setup", "perplexity local development",
"perplexity dev environment", "develop with perplexity", "mock perplexity".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Bash(pnpm:*), Grep |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","perplexity","testing","workflow"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Perplexity Local Dev Loop
Overview
Set up a fast, cost-effective local development workflow for Perplexity Sonar API. Key challenge: every real API call performs a web search and costs money, so mocking and caching are essential for development.
Prerequisites
- Completed
perplexity-install-auth setup
- Node.js 18+ with npm/pnpm
vitest for testing
Instructions
Step 1: Project Structure
my-perplexity-project/
├── src/
│ ├── perplexity/
│ │ ├── client.ts # OpenAI client wrapper for Perplexity
│ │ ├── search.ts # Search functions with citation handling
│ │ └── types.ts # Response type extensions
│ └── index.ts
├── tests/
│ ├── fixtures/ # Saved API responses for mocking
│ │ └── sonar-response.json
│ ├── perplexity.test.ts
│ └── setup.ts
├── .env.local # API key (git-ignored)
├── .env.example # Template
└── package.json
Step 2: Type-Safe Client Wrapper
import OpenAI from "openai";
export interface PerplexityResponse extends OpenAI.ChatCompletion {
citations?: string[];
search_results?: Array<{
title: string;
url: string;
snippet: string;
}>;
related_questions?: string[];
}
export type PerplexityModel = "sonar" | "sonar-pro" | "sonar-reasoning-pro" | "sonar-deep-research";
export (): {
({
: apiKey || process..,
: ,
});
}
(): <> {
response = client...({
: opts. || ,
: [
...(opts.
? [{ : , : opts. }]
: []),
{ : , : query },
],
: opts.,
...(opts. && { : opts. }),
...(opts. && { : opts. }),
} );
response ;
}