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 🙏

© 2025 – Pkg Stats / Ryan Hefner

stasis-proxy

v0.1.0

Published

A high-performance local proxy server for AI Engineers that caches LLM responses, dramatically speeding up development and reducing costs.

Readme

stasis-proxy

The Zero-Config Local Cache for AI Engineers.
Stop burning your budget on repeated test runs.

TypeScript Node.js License


🎯 The Problem

Building AI apps involves running the same prompts hundreds of times:

  1. Expenses Pile Up: Every npm test run costs real money.
  2. Speed Kills Flow: Waiting 5s for GPT-4 breaks your thought process.
  3. Flaky Tests: Non-deterministic LLMs make unit tests unreliable.

You could use a heavyweight Enterprise Gateway (Helicone, Portkey) or install Python tools (LiteLLM), but why add friction to your Node.js workflow?

💡 The Solution

stasis-proxy is the missing json-server for AI.
It is a local-first, zero-config HTTP proxy that caches LLM responses in a local SQLite file.

🆚 Positioning

| Feature | AWS Bedrock Caching | Enterprise Gateways (Helicone) | stasis-proxy | | :--- | :--- | :--- | :--- | | Goal | Lower latency for huge contexts | Production observability | Free & instant local development | | Cost | You still pay (discounted) | You pay for their service | $0.00 | | Setup | Complex CloudFormation | API Keys, Cloud Accounts | npx stasis start | | Data | Ephemeral (5 min TTL) | Sent to 3rd party cloud | 100% Local (SQLite) |



🚀 Quick Start

Installation

# Clone and install
git clone <repo-url> stasis-proxy
cd stasis-proxy
npm install
npm run build

Usage

# Start the proxy (development)
npm run dev -- start --port 4000 --upstream https://api.openai.com

# Start the proxy (production)
npm start -- start --port 4000 --upstream https://api.openai.com

# Or use npx after global install
npx stasis start --port 4000 --upstream https://api.openai.com

Configure Your Application

Point your OpenAI/Anthropic client to the proxy:

// OpenAI
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: 'http://localhost:4000/v1', // Point to stasis-proxy
  apiKey: process.env.OPENAI_API_KEY,
});

// Anthropic (using OpenAI-compatible endpoint)
const anthropic = new OpenAI({
  baseURL: 'http://localhost:4000/v1',
  apiKey: process.env.ANTHROPIC_API_KEY,
});

Or set environment variables:

export OPENAI_API_BASE=http://localhost:4000/v1

AWS Bedrock Support

To use with AWS Bedrock, you need to route requests through the proxy. Since the proxy handles AWS Signature V4 verification (by using the original signature from your client for the upstream request, but a normalized "smart key" for caching), you just need to point your Bedrock client to the proxy.

However, the AWS SDK does not support a simple baseURL override for the entire service URL easily in all versions. The most reliable way is to use a custom request handler or middleware in your application code.

Example: Using a custom Request Handler (Node.js SDK v3)

import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime";
import { NodeHttpHandler } from "@smithy/node-http-handler";

const proxyClient = new BedrockRuntimeClient({
  region: "us-east-1",
  requestHandler: new NodeHttpHandler({
    // Point the underlying HTTP handler to the proxy
    // Note: This requires the proxy to be running on localhost:4000
    httpAgent: new http.Agent({
      host: 'localhost',
      port: 4000,
      protocol: 'http:',
    }),
    httpsAgent: new https.Agent({
      host: 'localhost',
      port: 4000,
      protocol: 'http:',
    })
  }),
  // IMPORTANT: You might need to disable SSL verification if using a local proxy without valid certs for 'bedrock.us-east-1.amazonaws.com'
  // Or simply rely on the proxy to handle the upstream connection.
});

// Stasis Proxy specific: The proxy listens on /model/<model-id>/invoke

Alternatively, if you are using a library like LangChain, you can often set the endpoint_url.

const model = new Bedrock({
  model: "anthropic.claude-v2",
  region: "us-east-1",
  endpointUrl: "http://localhost:4000/model/anthropic.claude-v2/invoke", // Full path to proxy
});

For stasis-proxy, ensuring your client sends standard AWS headers (Authorization: AWS4-HMAC-SHA256...) is crucial for the "Smart Auth" caching to work.


📚 Examples

See the examples/ directory for complete, runnable examples:

  • OpenAI Integration — Full setup with unit tests demonstrating cached testing
  • Development Workflow — Prompt engineering iteration with instant feedback
  • AI Service Pattern — Realistic content analyzer service with sentiment analysis, NER, and categorization
cd examples
npm install
npm run test:with-proxy  # See the caching magic!

Key Results: | Run | Time | Cost | |-----|------|------| | First run | ~175s | ~$0.02 | | Cached run | ~5s | $0.00 |


🧠 LLM-Aware Caching

Unlike a dumb HTTP cache, stasis-proxy understands LLM semantics.

Intelligent Key Generation

The cache key is generated from:

  1. Normalized JSON body — Keys are deeply sorted, so {"a":1,"b":2} and {"b":2,"a":1} produce identical cache keys
  2. Authorization header — Prevents data leakage between API keys

Variance Strategies

Control caching behavior with the X-Stasis-Mode header:

| Mode | Behavior | |------|----------| | cache (default) | Return cached response if available, otherwise fetch and cache | | fresh | Force a new fetch, update the cache, ignore existing cache | | bypass | Proxy directly without touching the cache at all |

Temperature-Aware Behavior

  • temperature: 0 — Responses are cached indefinitely (deterministic)
  • temperature > 0 — Caching still works, use fresh mode when you need new creative outputs

Streaming (MVP Limitation)

For this MVP, requests with "stream": true automatically bypass the cache. Full streaming support is planned for v0.2.


📡 Response Headers

Every response includes the X-Stasis-Status header:

| Status | Meaning | |--------|---------| | HIT | Response served from cache | | MISS | Response fetched from upstream and cached | | BYPASS | Response proxied without cache interaction (streaming, bypass mode) |


🛠️ CLI Reference

stasis start [options]

Options:
  -p, --port <port>       Port to listen on (default: 4000)
  -u, --upstream <url>    Upstream API URL (required)
  -d, --db <path>         SQLite database path (default: ./stasis-cache.db)
  -l, --log-level <level> Log level: fatal|error|warn|info|debug|trace (default: info)
  -h, --help              Show help
  -v, --version           Show version

Examples

# OpenAI
stasis start -p 4000 -u https://api.openai.com

# Anthropic
stasis start -p 4000 -u https://api.anthropic.com

# With custom database location
stasis start -p 4000 -u https://api.openai.com -d ~/.stasis/cache.db

# Verbose logging
stasis start -p 4000 -u https://api.openai.com -l debug

📊 Monitoring

Health Check

curl http://localhost:4000/health
{
  "status": "healthy",
  "cache": {
    "entries": 42,
    "tokensSaved": 128500,
    "dbSizeBytes": 1048576
  }
}

Statistics

curl http://localhost:4000/stats
{
  "totalEntries": 42,
  "totalTokensSaved": 128500,
  "dbSizeBytes": 1048576,
  "oldestEntry": "2024-01-15T10:30:00.000Z",
  "newestEntry": "2024-01-15T14:45:00.000Z"
}

🏗️ Architecture

┌──────────────────┐     ┌──────────────────┐     ┌──────────────────┐
│   Your App       │────▶│   stasis-proxy   │────▶│   OpenAI/etc     │
│                  │◀────│                  │◀────│                  │
└──────────────────┘     └──────────────────┘     └──────────────────┘
                                  │
                                  ▼
                         ┌──────────────────┐
                         │   SQLite Cache   │
                         │ (stasis-cache.db)│
                         └──────────────────┘

Technology Stack

  • Runtime: Node.js 20+
  • Framework: Fastify (low overhead, plugin architecture)
  • Database: better-sqlite3 (single-file, zero-dependency)
  • Validation: Zod (runtime type checking)
  • Logging: Pino (high-performance, pretty-printed)
  • CLI: cac (lightweight CLI framework)

📁 Project Structure

stasis-proxy/
├── src/
│   ├── cli.ts           # CLI entry point
│   ├── index.ts         # Library exports
│   ├── types.ts         # Shared types and schemas
│   ├── core/
│   │   ├── server.ts    # Fastify server setup
│   │   ├── hasher.ts    # JSON normalization & hashing
│   │   └── interceptor.ts # Request interception & caching logic
│   └── store/
│       └── sqlite.ts    # SQLite database wrapper
├── examples/            # Integration examples and tests
│   ├── src/
│   │   ├── services/    # Realistic AI service patterns
│   │   ├── __tests__/   # Unit tests demonstrating caching
│   │   └── dev/         # Development workflow utilities
│   └── README.md        # Examples documentation
├── package.json
├── tsconfig.json
└── README.md

🧪 Testing

# Run tests
npm test

# Watch mode
npm run test:watch

🗺️ Roadmap

  • [ ] v0.2: Streaming response caching
  • [ ] v0.3: Cache TTL and expiration policies
  • [ ] v0.4: Web UI for cache inspection
  • [ ] v0.5: Anthropic-native format support

📄 License

MIT © 2025 Greg King