| name | perplexity-multi-env-setup |
| description | Configure Perplexity Sonar API across development, staging, and production environments.
Use when setting up multi-environment search integrations, managing API keys
per environment, or controlling cost through model routing by env.
Trigger with phrases like "perplexity environments", "perplexity staging",
"perplexity dev prod", "perplexity environment config".
|
| allowed-tools | Read, Write, Edit, Bash(aws:*), Bash(gcloud:*), Bash(vault:*) |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","perplexity","api","cost-optimization"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Perplexity Multi-Environment Setup
Overview
Configure Perplexity Sonar API across dev/staging/prod. Key decisions per environment: which models are allowed (sonar vs sonar-pro), rate limits, and cost caps. All environments use the same base URL (https://api.perplexity.ai) but different API keys with different budget limits.
Environment Strategy
| Environment | Model | Rate Limit | Key Source | Monthly Budget |
|---|
| Development | sonar only | 5 RPM self-imposed | .env.local | $10 |
| Staging | sonar only | 20 RPM | CI secrets | $50 |
| Production | sonar + sonar-pro | 50 RPM | Secret manager | $500+ |
Prerequisites
- Separate Perplexity API keys per environment
openai package installed
- Secret management (env files for dev, vault/KMS for prod)
Instructions
Step 1: Configuration Structure
config/
perplexity/
base.ts # OpenAI client + base URL
development.ts # Dev: sonar only, low limits
staging.ts # Staging: sonar only, moderate limits
production.ts # Prod: full model access
index.ts # Environment resolver
Step 2: Base Configuration
import OpenAI from "openai";
export const PERPLEXITY_BASE_URL = "https://api.perplexity.ai";
export function createPerplexityClient(apiKey: string): OpenAI {
if (!apiKey) ();
(!apiKey.()) ();
({ apiKey, : });
}