npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@loop-engine/adapter-perplexity

v1.0.0-rc.0

Published

Perplexity Sonar API adapter for Loop Engine multi-LLM steps (grounded search + reasoning).

Readme

@loop-engine/adapter-perplexity

npm

Overview

@loop-engine/adapter-perplexity wraps the Perplexity Sonar API (OpenAI-compatible chat completions) so Loop Engine state-machine steps can perform grounded web retrieval with citations and Sonar Reasoning models for multi-step analysis. It implements ToolAdapter from @loop-engine/core and returns structured Citation records for audit trails.

Installation

pnpm add @loop-engine/adapter-perplexity @loop-engine/core
# or
npm install @loop-engine/adapter-perplexity @loop-engine/core

Configuration

| Variable | Required | Description | |----------|----------|-------------| | PERPLEXITY_API_KEY | Yes | API key (pplx-...). Never commit or log. | | PERPLEXITY_BASE_URL | No | Default https://api.perplexity.ai. | | PERPLEXITY_DEFAULT_MODEL | No | Overrides default model (e.g. sonar-pro). |

In code, optional PerplexityConfig can set apiKey, baseUrl, defaultModel, defaultSearchRecency (month | week | day | hour), timeout (ms, default 30_000), and retries (default 3 for 429 / 5xx / timeout).

Vercel / serverless: add PERPLEXITY_API_KEY, and optionally PERPLEXITY_BASE_URL and PERPLEXITY_DEFAULT_MODEL, to your project environment variable audit checklist for any app that instantiates this adapter.

Usage

Basic Sonar search

import { createPerplexityAdapter } from "@loop-engine/adapter-perplexity";

process.env.PERPLEXITY_API_KEY = "pplx-..."; // or pass { apiKey } in config in trusted environments only

const adapter = createPerplexityAdapter();

const result = await adapter.invoke({
  prompt: "Latest FDA guidance on cold chain for vaccines?"
});

console.log(result.text);
console.log(result.citations); // { url, title, snippet }[]

Domain filter and recency

const adapter = createPerplexityAdapter({ defaultSearchRecency: "week" });

const result = await adapter.invoke({
  prompt: "Supplier recall news",
  model: "sonar-pro",
  maxTokens: 2048,
  temperature: 0.2,
  metadata: {
    searchDomainFilter: ["fda.gov", "nih.gov"],
    searchRecencyFilter: "day",
    returnCitations: true,
    returnImages: false
  }
});

Citation handling

Sonar returns citations and search_results; the adapter merges them into result.citations. Do not discard them: attach them to the Loop step evidence (or equivalent) for audit compliance. Before persisting or logging, call adapter.guardEvidence(payload) so PII-bearing URLs or text are redacted consistently with other adapters. The full provider payload is available as result.raw for debugging only — never log raw in production.

Supported models

| Model | Role | |-------|------| | sonar | Grounded search | | sonar-pro | Grounded search (default) | | sonar-reasoning | Reasoning-oriented | | sonar-reasoning-pro | Reasoning-oriented |

Perplexity renames models over time; this package pins supported IDs as the PerplexityModel union. If a model is sunset, upgrade this package or pass a supported input.model.

Error handling

Failures surface as PerplexityAdapterError (statusCode, retryable). Repeated rate limits may throw RateLimitError (429, retryable). 400 and 401 are not retried. 429, 500, 503, and timeouts retry with exponential backoff and jitter (up to retries). Integrations should map failures to the Loop step failed state and set loopState.error to the error message.

Perplexity Computer and skills

Perplexity Computer provides hosted skills and agent-style orchestration. This package does not call the Computer Agent API — it is Sonar-only. Use a separate gateway integration (e.g. gateway--perplexity-computer) for Computer orchestration; use @loop-engine/adapter-perplexity when you need cited Sonar completions inside Loop Engine’s ToolAdapter contract.

License

Apache-2.0. See LICENSE.