https://api.getnadir.com/v1/optimizeCompact a message list and report the tokens removed. Returns the same message schema you sent, so the output drops straight into your provider call. No LLM call.
Authentication
Required. Send your key as X-API-Key.
Request body
messagesobject[]requiredMessages to compact. At least 1.
modestringsafe, aggressive, kompress, or select. Defaults to safe. See below.
max_turnsintegerMaximum conversation turns kept when trimming. Between 1 and 500, defaults to 40.
modelstringTarget model id, used for accurate token counting.
tierstringThe routed tier this request is headed for, for example from /v1/bucket. Read by select mode only. Every other mode ignores it.
Modes
safe
Deterministic, no model calls. Dedups repeated system prompts and tool schemas, minifies JSON, and normalizes plain prose while preserving code, string spacing and Markdown line breaks. Not lossless: JSON formatting can change and long histories may be trimmed. Use off for exact-copy tasks.
aggressive
Adds semantic deduplication of repeated content.
kompress
Compresses eligible tool results only after an explicit protected-prefix boundary. Without that boundary it preserves input; it does not fall back to aggressive mode or trim history.
select
Adds query-conditioned removal of whole retrieved passages. Nothing is rewritten: a passage survives verbatim or is dropped.
Example
curl https://api.getnadir.com/v1/optimize \
-H "Content-Type: application/json" \
-H "X-API-Key: $NADIR_API_KEY" \
-d '{
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "..."}
],
"mode": "safe",
"model": "claude-sonnet-4-6"
}'Response
messagesobject[]requiredCompacted messages, same schema as the input.
original_tokensintegerrequiredToken count before optimization.
optimized_tokensintegerrequiredToken count after optimization.
tokens_savedintegerrequiredoriginal_tokens minus optimized_tokens.
savings_pctnumberrequiredtokens_saved / original_tokens * 100.
modestringrequiredMode actually applied, which can differ from the mode requested when a mode degrades.
optimizations_appliedstring[]requiredNamed transforms that fired on this message list.
latency_msintegerrequiredOptimization latency in milliseconds.
Info
api.getnadir.com/openapi.json. The values in the example response are illustrative, not a recorded call.Warning
safe and aggressive modes the output is prefix-stable: re-optimizing a conversation that has grown by a turn returns the previously optimized messages byte for byte, so provider prompt caches keyed on that prefix keep hitting. The exception is history trimming, which moves the prefix. When it fires, optimizations_applied includes chat_history_trim. Check for it before assuming a cache hit.