Compact Context
Summarize the older part of a conversation into a single user message via the caller’s LLM.
keepLastMessages messages is summarized; the summary is
returned as a user-role message followed by the kept tail verbatim. Your provider runs the
summary, so the provider adds the cost to your account.
A conversation too large for the summarizer’s context window is split into chunks that each fit,
summarized concurrently, then merged in a reduce pass - so payload size alone does not fail the
request. When the conversation still cannot be summarized (it needs more chunks than the server
allows, or the chunk summaries will not converge), the response is a 400, not a 500.
Two optional controls shape the output. instructions adds caller guidance inside the
server-owned prompt frame, so it steers the summary without the model echoing the wording back.
targetTokensEstimate sets a desired summary size, translated into word-count guidance.
The compaction block reports what happened: compacted is false when the payload passed
through untouched (nothing older than the kept tail), alongside chunk/pass counts and the
summarizer’s own token usage.
Required ACL: searchAuthorizations
Your Algolia application ID.
Your Algolia API key with the necessary permissions to make the request. Permissions are controlled through access control lists (ACL) and access restrictions. The required ACL to make a request is listed in each endpoint's reference.
Body
LLM-summarization request.
Your provider runs the summary, so the provider adds the cost to your account.
- userMessageV4
- assistantMessageV4
Model name (e.g., gpt-4o-mini).
Provider UUID for LLM credentials.
Extra guidance for the summarizer (e.g. 'keep every product reference'). Appended inside the server-owned prompt frame, so it steers the summary without the model echoing your wording back into it.
2000Number of trailing messages kept verbatim; everything older is summarized.
x >= 0Desired size of the final summary, in tokens. Translated into word-count guidance for the summarizer (best-effort, not a hard cap). Omit to let the summarizer default to a concise summary.
x >= 64Response
Successful Response.
Result of a context operation, ready to feed to /completions.
- userMessageV4
- assistantMessageV4
Before/after accounting for a context operation.
tokens*Estimate fields are heuristic, not an authoritative provider count.
messages_dropped is the net reduction in message count (messages_before - messages_after); for compaction the summarized tail is replaced by a single summary
message, so this reflects the net change rather than a raw delete count.
Compaction-specific telemetry, returned only by /context/compact.
compacted makes the short-conversation passthrough detectable: without it a caller
cannot tell a no-op from a summary that happened to be short.