TypeScript integration guide

TypeScript prompt compression guide

TypeScript and Node.js power most modern AI applications. SuperCompress provides a REST API that any Node.js app can call to compress prompts before sending them to an LLM.

By Arjun Shah - Creator of SuperCompress - Updated 2026-07-03

API-based integration

// compress.ts
const SUPERCOMPRESS_API_KEY = process.env.SUPERCOMPRESS_API_KEY;

export async function compress(context: string, query: string) {
  const res = await fetch("https://supercompress.dev/api/v1/compress", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": SUPERCOMPRESS_API_KEY,
    },
    body: JSON.stringify({ context, query }),
  });
  const data = await res.json();
  return data.compressed_text;
}

Vercel AI SDK integration

import { StreamingTextResponse } from "ai";
import { openai } from "@ai-sdk/openai";
import { compress } from "./compress";

export async function POST(req: Request) {
  const { messages } = await req.json();
  const latestQuery = messages[messages.length - 1].content;
  const history = messages.slice(0, -1)
    .map((m: any) => `${m.role}: ${m.content}`).join("\n");

  const compressed = await compress(history, latestQuery);

  const response = await openai.chat.completions.create({
    model: "gpt-4o",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: compressed + "\n\n" + latestQuery },
    ],
    stream: true,
  });

  return new StreamingTextResponse(response);
}

Frequently asked questions

Is there a native npm package?

Not yet. Use the REST API for now. A native npm wrapper is on the roadmap.

Does the API support streaming?

Compression returns the compressed text synchronously. Use it before your streaming LLM call.

Try it yourself

Paste your long prompt into the playground, ask a question, and see what SuperCompress keeps and removes. Free, no signup needed.

Open the Playground Embed the badge