packages
Loading
Loading
packages
@loop-engine/adapter-perplexity wraps the Perplexity Sonar chat API as a Loop Engine LLMAdapter. Sonar adds grounded web retrieval with cited sources. You use it for Loop steps that need real-time, verifiable information — regulatory lookups, compliance research, supplier or market news. It is not a general-purpose generation adapter; for broad LLM actor flows, use Anthropic or OpenAI actor adapters.
1npm install @loop-engine/adapter-perplexity1import { PerplexityAdapter } from "@loop-engine/adapter-perplexity";2 3const adapter = new PerplexityAdapter({4 apiKey: process.env.PERPLEXITY_API_KEY,5 defaultModel: "sonar-pro", "cmt">// sonar | sonar-pro | sonar-reasoning | sonar-reasoning-pro6 defaultSearchRecency: "month", "cmt">// day | week | month7 timeout: 30_000,8 retries: 3,9});1import { PerplexityAdapter } from "@loop-engine/adapter-perplexity";2import type { AdapterInput } from "@loop-engine/core";3 4const adapter = new PerplexityAdapter({ apiKey: process.env.PERPLEXITY_API_KEY! });5 6const input: AdapterInput = {7 prompt:8 "What are the HIPAA breach notification requirements for PHI accessed outside approved hours?",9 model: "sonar-pro",10 metadata: {11 returnCitations: true,12 searchDomainFilter: ["hhs.gov", "nist.gov"],13 searchRecencyFilter: "month",14 },15};16 17const result = await adapter.invoke(input);18 19console.log(result.text); "cmt">// Sonar answer text20console.log(result.citations); "cmt">// { url, title, snippet }[]Citations are a first-class output on SonarResult. Each entry includes url, title, and snippet (for example derived from search metadata).
1const result = await adapter.invoke({2 prompt: "Summarize recent FDA guidance on AI/ML SaMD change control.",3 metadata: { returnCitations: true, searchRecencyFilter: "month" },4});5 6for (const citation of result.citations) {7 console.log(citation.url);8 console.log(citation.title);9}| Model | Use case | Speed |
| --- | --- | --- |
| sonar | Fast retrieval, change detection | Fastest |
| sonar-pro | Research, regulatory lookup | Fast |
| sonar-reasoning | Multi-step analysis | Medium |
| sonar-reasoning-pro | Policy classification, complex inference | Slower |
PerplexityAdapter implements guardEvidence from @loop-engine/core, masking pplx-* API keys (and common secret field names) in payloads you log or export. You do not configure this — call adapter.guardEvidence(payload) before persisting raw request/response objects.
| Error | Retryable | Description |
| --- | --- | --- |
| PerplexityAdapterError (400) | No | Bad prompt or parameter |
| PerplexityAdapterError (401) | No | Invalid or missing API key |
| RateLimitError (429) | Yes | Exponential backoff, up to retries (default 3) |
| PerplexityAdapterError (500, 503) | Yes | Upstream or service errors — same backoff |
| Timeout / network | Yes | Treated like a retryable failure when attempts remain |
1PERPLEXITY_API_KEY=pplx-...2PERPLEXITY_BASE_URL=https:"cmt">//api.perplexity.ai # optional3PERPLEXITY_DEFAULT_MODEL=sonar-pro # optional