Skip to main content
POST
curl
Keep the last N messages and/or fit a heuristic token budget, optionally dropping tool parts from what is kept (tool parts are stripped before the budget is applied). Returns the trimmed messages plus before/after stats. With no constraints set, the messages are returned unchanged and only the stats are computed - a deliberate, cheap “how big is my context?” probe (no LLM call, no mutation). Required ACL: search

Authorizations

x-algolia-application-id
string
header
required

Your Algolia application ID.

x-algolia-api-key
string
header
required

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

application/json

Deterministic trim request (no LLM calls).

messages
required
dropToolParts
boolean
default:false

Strip tool-invocation/result parts from the messages that are kept. Applied before the token budget, so the budget counts only surviving content.

keepLastMessages
integer

Keep only the last N messages, dropping older ones. Applied before the token budget.

Required range: x >= 0
maxTokensEstimate
integer

Drop oldest messages until the estimated token total fits this budget (heuristic).

Required range: x >= 0

Response

Successful Response.

Result of a context operation, ready to feed to /completions.

messages
required
stats
contextStats · object
required

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
compactionStats · object | null

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.

Last modified on October 12, 2026