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

@polyswitch/sdk

v0.1.0

Published

Enterprise Drop-in SDK for Polyswitch AI Gateway & Agent OS — 1-line migration from OpenAI

Readme

@polyswitch/sdk

1-line drop-in replacement for the OpenAI SDK — route all your AI traffic through Polyswitch Enterprise AI Gateway with zero code changes.

npm version License: MIT


Installation

npm install @polyswitch/sdk
# or
pnpm add @polyswitch/sdk
# or
yarn add @polyswitch/sdk

Quick Start

Replace your existing openai import with @polyswitch/sdk — everything else stays exactly the same:

// Before
import OpenAI from 'openai';
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

// After — 1-line change
import Polyswitch from '@polyswitch/sdk';
const client = new Polyswitch({ polyswitchKey: process.env.POLYSWITCH_API_KEY });

Or use the aliased import for a truly zero-change migration:

import { OpenAI } from '@polyswitch/sdk';
const client = new OpenAI(); // reads POLYSWITCH_API_KEY from env automatically

Environment Variables

| Variable | Description | Default | | ------------------------ | ------------------------ | ------------------------------ | | POLYSWITCH_API_KEY | Your Polyswitch API key | pr_guest (demo mode) | | POLYSWITCH_GATEWAY_URL | Gateway endpoint | http://localhost:3000/api/v1 | | OPENAI_API_KEY | Fallback — also accepted | — | | OPENAI_BASE_URL | Fallback — also accepted | — |


Routing Strategies

Control how Polyswitch routes your requests across AI providers:

import Polyswitch, { Strategies } from '@polyswitch/sdk';

const client = new Polyswitch({
  strategy: Strategies.autoSmart() // Auto-pick best model (default)
  // strategy: Strategies.costOptimized(1.0), // Stay under $1/M tokens
  // strategy: Strategies.hedgedLatency({ thresholdMs: 500, fallbackModel: 'gpt-4o-mini' }),
  // strategy: Strategies.kvAffinity('user-session-123'), // Sticky routing for KV cache
});

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Hello!' }]
});

PII Redaction

Automatically strip PII from all requests before they leave your network:

const client = new Polyswitch({
  piiRedact: true
});

Compression

Token compression is enabled by default. Disable explicitly if needed:

const client = new Polyswitch({
  compression: false
});

Extra APIs

The SDK exposes additional Polyswitch-native APIs beyond standard OpenAI:

Agents

const result = await client.agents.run({
  persona: { name: 'Aria', role: 'analyst', systemPrompt: 'You are a data analyst.' },
  taskGoal: 'Summarize Q4 revenue trends',
  tools: [{ name: 'fetch_data', description: 'Fetch financial data' }],
  limits: { maxToolCalls: 5, maxBudgetUsd: 0.1 }
});

OCR

const result = await client.ocr.extract({
  file: fileBlob,
  model: 'mistral/mistral-ocr'
});

Rerank

const result = await client.rerank.create({
  query: 'What is the capital of France?',
  documents: ['Paris is in France.', 'London is in England.'],
  topN: 1
});

Search

const result = await client.search.query({
  query: 'latest AI research papers',
  maxResults: 5
});

Quota

const quota = await client.quota.get();

Telemetry Hooks

React to token savings and fallback events:

const client = new Polyswitch({
  telemetry: {
    onTokensSaved: ({ savedTokens, ratio }) => {
      console.log(`Saved ${savedTokens} tokens (${(ratio * 100).toFixed(1)}% reduction)`);
    },
    onFallbackTriggered: ({ primaryModel, fallbackModel, latencyMs }) => {
      console.log(`Fell back from ${primaryModel} → ${fallbackModel} after ${latencyMs}ms`);
    }
  }
});

TypeScript

Full type support included. The SDK ships .d.ts declarations and works with both CommonJS and ESM:

// ESM
import Polyswitch, { Strategies, PolyswitchOptions } from '@polyswitch/sdk';

// CommonJS
const { Polyswitch } = require('@polyswitch/sdk');

License

MIT © Polyswitch