Everything you need to use SuperCompress programmatically — Python library, HTTP API, response types, and client configuration.
The supercompress package provides the core compression functions. Local and hosted paths share one CompressResult type.
compress_for_turn(context, user_query, context_blocks=None, budget_ratio=0.35, mode="compiler")Query-aware local compression. Returns a CompressResult.
from supercompress import compress_for_turn
result = compress_for_turn(
context="",
user_query=user_message,
context_blocks=[system_prompt, tool_output, chat_history],
budget_ratio=0.35,
)
# Send result.compressed_text to your LLM
print(result.tokens_saved_pct)
compress_context(text, query, budget_ratio=0.35)Alias for compress_for_turn with a single context string. Returns a CompressResult.
from supercompress import compress_context
result = compress_context(
text="Your long context…",
query="What does fetch return?",
)
print(result.compressed_text)
print(f"Saved {result.tokens_saved_pct:.1f}% tokens")
SuperCompress.compress(...)Same CompressResult type as the local engine.
from supercompress.client import SuperCompress
sc = SuperCompress(api_key="sc_live_…")
result = sc.compress(context, query, mode="precision")
| Field | Type | Description |
|---|---|---|
compressed_text | str | Compressed context for your LLM |
original_tokens | int | Tokens before compression |
kept_tokens | int | Tokens after compression |
tokens_saved_pct | float | Percent of prompt tokens removed: (1 − kept/original) × 100. |
tokens_saved | int | original − kept |
policy_name | str | e.g. local-query-aware, SuperCompress-compiler |
mode | str | compiler or precision |
keep_ratio | float | Retention budget used |
kept_line_ratio | float | Fraction of original lines kept (hosted API) |
The hosted API uses compiler mode by default — no budget needed. Compiler mode maximizes token removal while preserving answer-critical evidence.
curl -d "context=Your long text&query=What matters?" https://supercompress.dev/compress \
-H "X-API-Key: sc_live_YOUR_KEY"
Send as JSON (standard) or form-encoded (simpler for curl). All three work:
# Option 1: JSON (standard)
POST https://supercompress.dev/api/v1/compress
Content-Type: application/json
X-API-Key: sc_live_YOUR_KEY
{
"context": "Your long context…",
"query": "What matters?"
}
# Option 2: Form-encoded (quick curl)
curl -d "context=...&query=..." https://supercompress.dev/compress \
-H "X-API-Key: sc_live_YOUR_KEY"
# Option 3: GET with query params (small contexts)
curl "https://supercompress.dev/compress?context=...&query=...&api_key=sc_live_YOUR_KEY"
All three hit the same endpoint and return the identical response. Use whatever fits your workflow.
| Parameter | Type | Required | Description |
|---|---|---|---|
context | string | yes | The full context to compress. Supports Unicode, code, markup, logs. |
query | string | yes | The user question that defines retention relevance. |
budget_ratio | number | no | Pass only for legacy fixed-ratio mode (0.1–1.0). Omit for default compiler mode. |
{
"compressed_text": "…",
"original_tokens": 1248,
"kept_tokens": 436,
"tokens_saved": 812,
"tokens_saved_pct": 65.06,
"important_kept_pct": 0.98,
"compression_risk": "low",
"kept_blocks": [
{"heading": "User account", "reason": "matches query topic"},
{"heading": "Billing history", "reason": "contains answer evidence"}
],
"dropped_blocks": [
{"heading": "Feature requests", "reason": "irrelevant to billing question"}
],
"policy_name": "SuperCompress-compiler"
}
| Field | Type | Description |
|---|---|---|
compressed_text | string | The compressed context. Send this to your LLM. |
original_tokens | int | Input token count (rough estimate). |
kept_tokens | int | Tokens after compression. |
tokens_saved | int | original − kept. |
tokens_saved_pct | float | Percent of prompt tokens removed. |
important_kept_pct | float | Estimated fraction of important context preserved. 0.0–1.0. |
compression_risk | string | "low", "medium", or "high" — verifier confidence. |
kept_blocks | array | Evidence blocks kept, with reasons. |
dropped_blocks | array | Largest removed blocks, with reasons. |
policy_name | string | "SuperCompress-compiler" or "SuperCompress-fixed". |
Include your API key in either the X-API-Key header or the Authorization: Bearer sc_live_… header. Get a key from the dashboard.
Compiler mode is the production path. Users do not choose a budget or ratio. The engine:
Compiler mode is the default on the hosted API. The local Python library uses fixed-ratio mode by default for backward compatibility, but you can enable compiler-style behavior by omitting budget_ratio.
| Situation | Use |
|---|---|
| Production API call — maximize savings safely | Compiler mode (omit budget) |
| Research / fixed retention budget | Fixed-ratio mode (pass budget_ratio) |
| Local offline / no API key | compress_for_turn() / compress_context() |
| Hosted with quality gate | SuperCompress(...).compress(..., mode="precision") |
The sustainability_from_tokens_saved helper converts token savings into estimated GPU-seconds, kWh, and CO₂ avoided.
from supercompress.benchmarks.metrics import sustainability_from_tokens_saved
saved = result.original_tokens - result.kept_tokens
impact = sustainability_from_tokens_saved(saved)
print(impact.co2_kg_avoided)
print(impact.watt_hours_saved)
print(impact.assumptions.to_dict())
Default assumptions: 2,500 tokens/GPU-sec, 150W GPU, 0.417 kg CO₂/kWh (US grid), and context_share_of_prefill set to 55%. This estimates the prefill work avoided by removing prompt tokens before inference; SuperCompress does not read or write the model’s KV cache. See Environment & CO₂ for the full methodology.
| Error | Cause |
|---|---|
ValueError | budget_ratio outside (0, 1] |
FileNotFoundError | Checkpoint path doesn't exist |
RuntimeError | Model loading failure (corrupt checkpoint) |
| Status | Meaning |
|---|---|
| 200 | Success — compressed text in response |
| 400 | Missing or invalid context or query |
| 401 | Missing or invalid API key |
| 402 | Payment required — quota exceeded |
| 429 | Rate limit exceeded |
| 500 | Internal server error |