Official SDKs for Compresr — query-aware LLM context compression. Reduce API costs by 30-70%.
| Language | Package | Documentation |
|---|---|---|
| Python | python/README.md | |
| TypeScript | typescript/README.md | |
| curl / REST | — | curl/README.md |
pip install compresrfrom 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)npm install @compresr/sdkimport { 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 -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
}'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.
- Create an account at compresr.ai.
- Navigate to Dashboard → API Keys.
- Click "Create New Key" and copy it (shown only once).
- 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.
Test all workflows locally before pushing:
./test_ci_local.sh # auto-installs `act` on first runFor tests requiring an API key, create .secrets:
echo "COMPRESR_API_KEY=your_key" > .secretsRequires GitHub CLI and act.
See CONTRIBUTING.md.
Apache 2.0 — see LICENSE.