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

the-token-company

v0.4.0

Published

Node.js SDK for The Token Company — compress LLM prompts to reduce costs and latency

Readme

The Token Company Node.js SDK

Compress LLM prompts to reduce costs and latency. 100K tokens compressed in ~85ms.

CI npm version License: MIT

Docs · Website · Dashboard · Python SDK

Install

npm install the-token-company

Quick start

import { TheTokenCompany } from "the-token-company";

const client = new TheTokenCompany({ apiKey: "ttc-..." });
const result = await client.compress("Your long prompt text here...", { model: "bear-2" });

console.log(result.output);          // compressed text
console.log(result.tokensSaved);     // tokens removed
console.log(result.compressionRatio); // e.g. 1.8

SDK wrappers

Drop-in wrappers that auto-compress all non-assistant messages before sending to your LLM. Assistant messages pass through unchanged so the provider's KV cache stays warm.

OpenAI / OpenRouter

import OpenAI from "openai";
import { withCompression } from "the-token-company/openai";

const client = withCompression(new OpenAI(), { compressionApiKey: "ttc-..." });

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful assistant..." },
    { role: "user", content: "Summarize these results..." },
  ],
});

For OpenRouter, just set the base URL:

const client = withCompression(
  new OpenAI({ baseURL: "https://openrouter.ai/api/v1", apiKey: "or-..." }),
  { compressionApiKey: "ttc-..." }
);

Anthropic

import Anthropic from "@anthropic-ai/sdk";
import { withCompression } from "the-token-company/anthropic";

const client = withCompression(new Anthropic(), { compressionApiKey: "ttc-..." });

const response = await client.messages.create({
  model: "claude-sonnet-4-6",
  max_tokens: 1024,
  system: "You are a helpful assistant...",
  messages: [{ role: "user", content: "Summarize these results..." }],
});

Both messages and the system parameter are compressed.

Vercel AI SDK

withCompression() one-liner — wraps any AI SDK model with automatic compression:

import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
import { withCompression } from "the-token-company/ai-sdk";

const model = withCompression(openai("gpt-4o"), { compressionApiKey: "ttc-..." });

const { text } = await generateText({
  model,
  messages: [{ role: "user", content: "Summarize these results..." }],
});

Works with any provider (@ai-sdk/openai, @ai-sdk/anthropic, @ai-sdk/google, etc.).

compressionMiddleware() for composition — use when combining with other middleware:

import { wrapLanguageModel, generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { compressionMiddleware } from "the-token-company/ai-sdk";

const model = wrapLanguageModel({
  model: openai("gpt-4o"),
  middleware: compressionMiddleware({ compressionApiKey: "ttc-..." }),
});

Models

| Model | Description | |------------|------------------------| | bear-2 | Latest, recommended | | bear-1.2 | Previous generation |

Aggressiveness

Control compression intensity — a single number applies to all roles, or pass a per-role object:

// All roles at 0.5
withCompression(client, { compressionApiKey: "ttc-...", aggressiveness: 0.5 });

// Per-role — only listed roles are compressed
withCompression(client, {
  compressionApiKey: "ttc-...",
  aggressiveness: { system: 0.1, user: 0.3, tool: 0.5 },
});

| Role key | OpenAI | Anthropic | AI SDK | |------------|---------------------------------|--------------------------------|---------------------| | user | role: "user" messages | User text content | User messages | | system | role: "system" messages | system parameter | System messages | | tool | tool + function messages | tool_result content blocks | Tool result parts |

App ID

Tag compression requests with an application identifier for usage tracking:

// Set on the client — applies to all requests
const client = new TheTokenCompany({ apiKey: "ttc-...", appId: "my-chatbot" });

// Or per-request (overrides the client-level value)
const result = await client.compress(text, { model: "bear-2", appId: "my-chatbot" });

Also supported in wrappers:

const client = withCompression(new OpenAI(), { compressionApiKey: "ttc-...", appId: "my-chatbot" });

Gzip

Gzip compression of request payloads is on by default. Disable with:

const client = new TheTokenCompany({ apiKey: "ttc-...", gzip: false });

Response

CompressResult fields:

| Field | Type | Description | |--------------------|----------|------------------------------------| | output | string | Compressed text | | outputTokens | number | Token count after compression | | inputTokens | number | Token count before compression | | tokensSaved | number | Tokens removed | | compressionRatio | number | Ratio (e.g. 1.8x) |

License

MIT