API Reference
Compact API
Compress chat history and code context at 33,000 tok/s with byte-identical output
POST
Compact context
Overview
Compact compresses chat history and code context at 33,000 tok/s by removing irrelevant lines. Every surviving line is byte-for-byte identical to the original input. 100K tokens compresses in under 2 seconds. Passquery to tell the model what matters for the next LLM call. Without it, the model auto-detects from the last user message.
Usage Examples
keepContext Tags
Wrap sections you never want compressed in<keepContext> / </keepContext> tags. Tagged content survives compression verbatim regardless of the compression ratio.
kept_line_ranges showing which lines were force-preserved.
Compatible Endpoints
Compact also works through OpenAI-compatible endpoints withmodel: "morph-compactor":
See the full Compact documentation for SDK reference, best practices, and advanced usage.
Authorizations
Morph API key, passed as Authorization: Bearer sk-.... Create keys at https://www.morphllm.com/dashboard/api-keys.
Body
application/json
Compact request with text or messages to compress
Text or conversation to compress, plus the knobs controlling how aggressively lines are pruned.
Response
Compact response with compressed output and metadata
Compacted output, per-message line ranges, and usage statistics.