Prompt token optimizer
The token optimizer is a payload-size pass on the user-side messages and the system prompt before the request reaches the upstream provider. Only system and user text is shortened; tool calls, tool results and the model's earlier replies pass through as they are, so the saving on a request depends on how much of its input is system and user text. The optimizer is a FinOps lever, not a quality lever; it does not rewrite prompts to be "better."
If anything goes wrong while optimizing, IQ sends your original prompt unchanged. The optimizer runs before the call, so it can add a small delay.
Three modes
Aggressive is not available yet. Off and Safe are available.
| Mode | What it does | Latency budget | When to use |
|---|---|---|---|
| off | Pass-through. No compression. | 0 ms | Default. Use when payload size is not a cost driver. |
| safe | Deterministic cleanup of redundant formatting in conversational text. It can also drop a repeated header and trim "please" or "thank you" at the start or end of a message. | Small, with no model call. | Default-on recommendation. Observable token reduction on chat-heavy prompts. |
| aggressive (not available yet) | Aggressive mode removes more low-value text from the prompt for a larger token reduction, with a small risk to answer quality. | 250 ms hard cap; fails open above. | Cost-driven workloads. Gated by an explicit opt-in so the trade-off is a conscious choice, not a default. |
What the optimizer never touches
- Tool-call payloads. Function arguments and structured outputs pass through unchanged. The compression scope is conversational text, not machine-readable JSON.
- Assistant messages. The optimizer compresses what you send; what the model said back stays as-is for the conversation history.
- Code fences. Triple-backtick blocks pass through whitespace-
preserving even in
safemode. Code semantics depend on indentation.
Picking a mode
Settings → Token optimizer → mode picker. Aggressive is not available yet. Off and Safe are available. The aggressive option is a deliberate control: an explicit opt-in checkbox turns it on at the org's threshold, so choosing more compression for cost-driven workloads is a conscious choice rather than a default.
One composition to know about: an org whose routing focus mode is set to
quality runs safe even when the optimizer dial says aggressive. An
operator who asked for quality on the routing side does not silently get
lossy compression on the prompt side.
The dashboard surface lives at /settings#token-optimizer.
The pane also exposes:
- Threshold (aggressive only). The retain-or-drop threshold the aggressive pass uses. A lower threshold means more aggressive compression and a higher quality risk.
- Compression stats. A 30-day rollup of tokens saved, cost saved, average compression ratio, and the number of requests the optimizer ran on. Tokens saved is the number the ROI case rests on.
Safe mode
Safe mode is a deterministic cleanup of redundant formatting in conversational text. It tidies the kind of structure that costs tokens without carrying meaning for the model: extra blank space, mixed bullet markers, a repeated header with nearly the same text under it, and "please" or "thank you" at the very start or end of a user message. Code fences and inline code keep their whitespace. The result is a smaller payload with the same substance.
Aggressive mode
Aggressive is not available yet. Off and Safe are available. Aggressive mode removes more low-value text from the prompt for a larger token reduction, with a small risk to answer quality. If it can't finish quickly or isn't available, IQ sends the prompt without compression. The standalone bundle supports safe mode only.
How much a prompt can shrink
Each mode limits how much it will shrink a prompt. If a result would go past that limit, IQ sends your original prompt and records a compression_threshold_breached event, which you can subscribe to with webhooks. Aggressive mode allows more reduction than safe mode.
Rollback
Rollback is a mode change, not a deploy. If safe mode misbehaves on your
traffic, set the workspace's optimizer mode to off in the dashboard, and
the pass-through path restores the prior behaviour within about a minute. If
aggressive mode misbehaves, drop the workspace back to safe from the same
picker; the aggressive pass stops within about a minute, and nothing else
about the request path changes.
Bundling for offline use (Enterprise)
The standalone gateway bundle is the Enterprise on-prem option, arranged with us rather than downloaded; there is no self-hosted distribution on the self-serve plans.
The bundle does not ship the aggressive-mode weights and does not load
them at runtime, on any host, regardless of network access. A workspace
running the bundle that is set to aggressive sends prompts without
compression, the same fallback described in Aggressive mode, above.
safe mode is unaffected: it has no model to load, so it runs the same way
in the bundle and on the hosted gateway.
See also
- /docs/billing -- token classes and the four-way cost split the optimizer's savings show up against.
- /docs/caching -- the optimizer runs before cache lookup, so a compressed prompt has its own cache key, and a gateway cache hit is billed at zero whether or not the optimizer ran.
- /docs/webhooks -- subscribe to
compression_threshold_breachedto get notified the moment a floor breach ships an uncompressed prompt, instead of finding out from the 30-day compression-stats rollup. - /docs/quickstart -- the SDK setup does not need to change for the optimizer to apply.