Skip to main content

compress

Convert arbitrary JSON to a compact KTOF string and return size statistics.

Parameters

NameTypeRequiredDescription
dataAnyJSON-serializable payload (prompts, tool data, structured metadata).
options.delimiterstrSingle-character separator used inside the encoded string.
options.indentintPretty-print indentation applied during decode for readability.
options.length_markerbool | strInclude payload length metadata; set to a custom marker string if needed.
Pass the structure either as a plain dict or via EncodeRequest.

Code example

from kaizen_client import KaizenClient

payload = {
    "data": {
        "messages": [
            {"role": "system", "content": "You are concise."},
            {"role": "user", "content": "Summarize quarterly metrics."}
        ],
        "metadata": {"source": "docs-demo"}
    },
    "options": {"indent": 2}
}

async with KaizenClient.from_env() as client:
    compressed = await client.compress(payload)
    print(compressed["result"][:80], "...")
    print(compressed["stats"])

Response example

{
  "operation": "compress",
  "status": "ok",
  "result": "KTOF:AAA...",
  "stats": {
    "original_bytes": 2048,
    "compressed_bytes": 612,
    "reduction_ratio": 0.299
  },
  "metadata": {"source": "docs-demo"}
}

Errors

  • 400 → Invalid payload (e.g., data missing or not JSON-serializable).
  • 401 → Missing/invalid API key.
  • 413 → Payload too large for the current plan.
All non-2xx statuses raise KaizenAPIError.

Notes

  • Use compress for raw JSON blobs; prefer prompts_encode when your payload follows the chat/messages format.
  • Include metadata to correlate stats with downstream requests—Kaizen echoes it back unchanged.