Skip to content

Compresr SDK

PyPI npm Python TypeScript License

Official SDKs for Compresr — query-aware LLM context compression. Reduce API costs by 30-70%.

SDKs

Language Package Documentation
Python PyPI python/README.md
TypeScript npm typescript/README.md
curl / REST curl/README.md

Quick Start

Python

pip install compresr
from compresr import CompressionClient

client = CompressionClient(api_key="cmp_your_api_key")

result = client.compress(
    context="Long passage to compress...",
    query="What is the main conclusion?",
    target_compression_ratio=0.5,
)

print(f"Saved {result.data.tokens_saved} tokens")
print(result.data.compressed_context)

TypeScript

npm install @compresr/sdk
import { CompressionClient } from '@compresr/sdk';

const client = new CompressionClient({ apiKey: 'cmp_your_api_key' });

const result = await client.compress({
  context: 'Long passage to compress...',
  query: 'What is the main conclusion?',
  targetCompressionRatio: 0.5,
});

console.log(`Saved ${result.data?.tokens_saved} tokens`);

curl

curl -X POST https://api.compresr.ai/api/compress/question-specific/ \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $COMPRESR_API_KEY" \
  -d '{
    "context": "Long passage to compress...",
    "query": "What is the main conclusion?",
    "compression_model_name": "latte_v2",
    "target_compression_ratio": 0.5
  }'

Framework integrations

Both Python and TypeScript ship first-party integrations as optional installs:

Framework Python import TypeScript import
LangChain compresr.integrations.langchain @compresr/sdk/integrations/langchain
LangGraph compresr.integrations.langgraph @compresr/sdk/integrations/langgraph
LlamaIndex compresr.integrations.llamaindex @compresr/sdk/integrations/llamaindex

Each integration exposes the same set of helpers: agent middleware, tool wrappers, retriever/postprocessor adapters, and graph nodes. See the language-specific READMEs for code snippets and the tutorial/ directories for runnable end-to-end examples.

Getting an API key

  1. Create an account at compresr.ai.
  2. Navigate to Dashboard → API Keys.
  3. Click "Create New Key" and copy it (shown only once).

Features

  • Query-aware compression (latte_v2) — keeps tokens relevant to the supplied query, drops the rest.
  • 30-70% token reduction on typical agent / RAG workloads.
  • Permissive model surface — new compression models work without an SDK update; the backend is the authority.
  • Batch endpoint — compress up to 100 contexts in one call.
  • Streaming + async — full async/await + streaming for high-throughput pipelines.
  • First-party integrations — LangChain, LangGraph, LlamaIndex (both Python and TypeScript).
  • Fail-open by default — integrations log + passthrough on compression errors, opt-in to raise.

Documentation

Run CI Locally

Test all workflows locally before pushing:

./test_ci_local.sh    # auto-installs `act` on first run

For tests requiring an API key, create .secrets:

echo "COMPRESR_API_KEY=your_key" > .secrets

Requires GitHub CLI and act.

Support

Contributing

See CONTRIBUTING.md.

License

Apache 2.0 — see LICENSE.

About

SDK for seamless integration with the Compresr context compression service.

Resources

Code of conduct

Contributing

Security policy

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages