Build
Updated
Context management
Keep a long conversation inside the model's context window by summarizing its older turns and clearing old tool results, see how full a conversation is, and see what left the prompt.
A conversation grows with every turn. Once it outgrows the model’s context
window, a turn is refused under truncation: "disabled", the default, or loses
its oldest turns under truncation: "auto". Context management keeps the
conversation small enough that this usually does not happen:
- Compaction summarizes the older part of the conversation once it reaches a threshold. Later responses read the summary in place of those turns.
- Tool result clearing removes the oldest tool results from the prompt when a response would otherwise overflow, and leaves the model a way to read them again.
Both are off unless you ask for them, and nothing changes or is charged when you do not. Every response on a stored conversation reports how full it is either way, so you can decide when to turn them on.
If you turn on context management, we use the model provider handling your conversation to summarize older parts of it, and store that summary with the conversation. Summaries are deleted along with the content they came from.
The Node and Python examples use a client set up for this API.
See how full a conversation is
Section titled “See how full a conversation is”Every response on a stored conversation carries helpingio:context:
"helpingio:context": { "stored_tokens": 142000, "window_tokens": 200000 }| Field | Meaning |
|---|---|
window_tokens |
The model’s context window |
stored_tokens |
An estimate of what the next turn would load under this response’s own setting: the whole conversation when compaction is off, the summary and what follows it when it is on |
stored_tokens is an estimate, about four characters per token. Compaction
decides by the token count the model provider reports, so it can start just
below a threshold you set, or not start just above it.
Turn on automatic compaction
Section titled “Turn on automatic compaction”Send helpingio:context_management on POST /v1/responses:
curl https://api.helping.io/v1/responses \ -H "Authorization: Bearer $HELPINGIO_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "anthropic/claude-sonnet-5-5", "previous_response_id": "resp_abc", "input": "What did we decide about the schema?", "helpingio:context_management": {"compaction": "auto"}}'const response = await client.responses.create({ model: "anthropic/claude-sonnet-5-5", previous_response_id: "resp_abc", input: "What did we decide about the schema?", "helpingio:context_management": { compaction: "auto" },});response = client.responses.create( model="anthropic/claude-sonnet-5-5", previous_response_id="resp_abc", input="What did we decide about the schema?", extra_body={"helpingio:context_management": {"compaction": "auto"}},)| Field | Default | Meaning |
|---|---|---|
compaction |
Required | auto turns compaction and tool result clearing on for this request. off leaves them off |
compact_threshold |
70 percent of the model’s context window | The input tokens at which a summary is considered. Optional |
model |
The default summarizing model of the conversation’s provider (see Summarizing models) | The model that writes the summary. Optional. It must come from the same provider as the conversation, and from the list under Summarizing models |
The setting applies to one request. Send it on every request you want it for. A request that leaves it out reads the whole conversation, as if no summary existed, and clears nothing.
These are a 400 naming the field, before anything is created or charged: an
object without compaction, such as {}; a key the object does not define; a
compaction value other than auto or off; compact_threshold or model
with compaction: "off"; a compact_threshold below 50,000 tokens, or at or
above the model’s context window; a model from another provider; and a
workflow that cannot compact. A model that may not write summaries is a
400 with the code compaction_model_not_allowed. Context management needs a
stored conversation, so sending it with store: false is a 400 too.
What happens
Section titled “What happens”- A response finishes as usual. If the input of its last model call reached the threshold, a summary is considered after the response is final. Your response is never delayed or changed by it.
- A separate model call summarizes everything older than the last 6 turns, and the previous summary if there is one. It is billed as its own line in your usage.
- The next response that sends
compaction: "auto"reads the summary and then every turn after it, and shows acompactionitem in itsoutput, ahead of its reply. That response’shelpingio:context_omissionssays how many items the summary replaced.
So the summary takes effect one response after the threshold is crossed.
Nothing about the conversation’s stored history changes: every message stays,
the conversation’s item list keeps every item, and the compaction item is
added beside them. A summary is considered only when there is enough older
history to make it worth a call, so a conversation whose last few turns alone
are near the threshold is not summarized on every turn.
When no summary is made
Section titled “When no summary is made”compact_threshold says when a summary is considered, not that one is made.
None is made when your organization cannot pay for the call or a spend
control refuses it, when no model of the conversation’s provider may write
summaries, or when the conversation is too short. The conversation carries on
as it would without context management, and nothing is charged for a summary
that was not made.
A summary is considered after your response is final, so that response cannot
report it. The next response on the conversation reports each attempt that was
declined or failed since the last report, once, in helpingio:warnings:
{ "type": "other", "param": "helpingio:context_management", "reason": "refused_funds", "message": "..."}Switch on reason; the message is for a person and says whether the attempt
was charged. Every response on the conversation reports them, whether or not it
asked for compaction, because the attempt belongs to the conversation.
reason |
What happened | Charged |
|---|---|---|
too_little_to_compact |
Declined: too little is older than the turns kept in full to be worth a call | No |
waiting_for_growth |
Declined: an earlier attempt was charged and stored nothing, so the next waits for the conversation to grow | No |
model_unavailable |
Declined: no summarizing model of the conversation’s provider is available | No |
refused_funds |
Failed: your organization’s credit or a spend control refused the call | No |
start_failed |
Failed: the summarizing call never started | No |
oversized_turn |
Failed: the oldest turn alone is too large to summarize, so nothing was sent | No |
provider_failed |
Failed: the model provider failed and its retries ran out | For the calls that completed |
unusable_summary |
Failed: the summary came back empty, cut off or larger than what it replaces, or outgrew its allowance before the last part | Yes |
source_gone |
Failed: content the summary was written from was deleted while it ran | Yes |
Compact on request
Section titled “Compact on request”POST /v1/responses/compact summarizes a conversation now:
curl https://api.helping.io/v1/responses/compact \ -H "Authorization: Bearer $HELPINGIO_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "anthropic/claude-haiku-5-5", "previous_response_id": "resp_def"}'const compacted = await client.post("/responses/compact", { body: { model: "anthropic/claude-haiku-5-5", previous_response_id: "resp_def", },});compacted = client.post( "/responses/compact", body={ "model": "anthropic/claude-haiku-5-5", "previous_response_id": "resp_def", }, cast_to=object,)model and previous_response_id are required, and previous_response_id
names a response your key created. model writes the summary: it must come
from the provider of the named response, and from the list under
Summarizing models. The answer has
object: "response.compaction", an output holding the compaction item, and
the summary’s own usage, which is also its line in your usage, and what it
cost in helpingio:cost.
The rest of the conversation stays on the server, so your next
POST /v1/responses needs no change. Unlike the Open Responses
specification’s answer, output holds only the compaction item and not the
messages that follow it. The next response reads the summary whether or not it
sends helpingio:context_management, because you asked for it by name.
input is a 400. instructions and prompt_cache_key are accepted and not
applied, and helpingio:warnings says so for instructions.
| Case | Answer |
|---|---|
| A summary was written | 200 |
| Nothing new to summarize, and a summary exists | 200 with the newest compaction item, zero usage and a helpingio:cost of "0", so a retry is safe |
| Nothing to summarize, and no summary | 400 naming previous_response_id |
| The oldest turn alone is too large to summarize | 400 naming previous_response_id, and nothing is charged |
| The named response is still running | 409 resource_conflict |
| Another summary of this conversation is being written, or this one took longer than the request waits | 409 compaction_in_progress. One past the wait keeps running and is charged for its calls: the same request sent again returns its summary at no charge while no turn has been added, and a failure is reported on the conversation’s next response |
| Your organization cannot pay, before anything starts | Refused as a new response is |
| Credit or a spend limit runs out part way | 429 with the code a failed response carries for it, and what was billed in helpingio:usage and helpingio:cost |
| The model provider failed, or the summary could not be used | The provider failure’s 429 or 502, with what was billed in helpingio:usage and helpingio:cost |
| Content it was written from was deleted while it ran | 409 resource_conflict, with what was billed in helpingio:usage and helpingio:cost |
The answer’s id starts cmpres_ and names that answer only. The
compaction item’s id starts cmp_.
The compaction item
Section titled “The compaction item”{ "type": "compaction", "id": "cmp_01JA2K", "encrypted_content": "..."}encrypted_content is a reference to the summary, not its text. Treat it as
opaque. Sending the item back as input on its own conversation is accepted and
changes nothing, even after the summary was deleted, so a client that replays
its history keeps working. Sent on another conversation, on a conversation’s
first turn, or to the conversation items route, it is a 400.
The item sits on the first response that read the summary, not at the point in the conversation the summary covers: the last 6 turns before it are still read in full. It means a summary took effect there.
To read the summary the model now reads, use GET /v1/compactions/{id} with
the item’s cmp_ id. It answers {id, object: "compaction", created_at, model, summary}. A deleted summary, one on a deleted conversation, or one your
key cannot reach is a 404.
Summarizing models
Section titled “Summarizing models”A summary is written by a cheap model, so that no single call produces a large charge. These may write one:
| Provider | Models |
|---|---|
| Anthropic | anthropic/claude-haiku-5-5, anthropic/claude-sonnet-5-5 |
google/gemini-3.5-flash-lite, google/gemini-3.8-flash |
|
| OpenAI | openai/gpt-6-luna |
Each runs at its lowest reasoning setting, because a summary is a record, not reasoning. Gemini 3.5 Flash-Lite trades recall on cross-reference questions for speed.
Without model, the summary is written by the default summarizing model of
the conversation’s provider: anthropic/claude-haiku-5-5,
google/gemini-3.8-flash and openai/gpt-6-luna today.
Tool result clearing
Section titled “Tool result clearing”With compaction: "auto", a response whose prompt would overflow clears its
oldest tool results, once:
- Only when the prompt would not otherwise fit, after everything cheaper has been dropped. A response that fits clears nothing.
- Oldest first, until the prompt fits with room for the rest of the response. The newest 3 results, and the results the model is answering now, are never cleared.
- Once per response. Every later step of the same response reads the same cleared set, so the prompt does not change again.
- The call stays in the prompt, with its name and arguments. The result is replaced by a note naming the tool and how to read the result again, and the model can fetch it. Nothing stored changes.
- It runs under
truncation: "disabled"too, because you asked for it, and each cleared result is reported. If clearing is not enough, the request is refused as it would have been.
Clearing an earlier result costs the cached prefix of the prompt after it once, so it happens only when the alternative is an overflow.
What left the prompt
Section titled “What left the prompt”helpingio:context_omissions lists, on the response where it happened and only
there, what the model did not read:
"helpingio:context_omissions": [ { "reason": "compaction", "items": 41, "input_tokens": 90000, "compaction_id": "cmp_01JA2K" }, { "reason": "tool_result_cleared", "type": "function_call_output", "id": "fco_01J9Z3", "input_tokens": 3900 }, { "reason": "tool_result_cleared", "type": "system_tool_call", "input_tokens": 3700 }, { "reason": "tool_output_bounded", "type": "function_call_output", "id": "fco_01J9Z8", "input_tokens": 31000 }]reason |
Meaning |
|---|---|
compaction |
A summary replaced items items. compaction_id is the compaction item’s id. One line however many items it covers |
tool_result_cleared |
A tool result was cleared. One line per result |
tool_output_bounded |
The model read the first part of a long tool result. See Long tool results |
input_tokens is always an estimate of what the model did not read. A line
with "type": "system_tool_call" and no id is a result from one of this
API’s own tools, which is not an item. The key is absent when nothing was left
out.
Each summary is billed to you as its own line in your usage, at the summarizing model’s price, and never folded into the response that triggered it. Spend controls count it. A summary that was written and could not be used, because it was empty or longer than what it replaced, is billed, and the next one waits for the conversation to grow further. A long conversation is summarized in parts, one billed call each; if the summary so far grows past what the next part can carry, the summary stops there as unusable, the parts already summarized are billed and the refused one is not. Tool result clearing makes no model call and costs nothing beyond the cache effect above.
How it fits with truncation
Section titled “How it fits with truncation”truncation says what to do when a turn does not fit. Context management keeps
the conversation small enough that it usually does. You may send both:
- Under
disabled, a conversation that still does not fit after a summary is refused, as usual. - Under
auto, the oldest turns are still dropped when needed, as usual.
The Open Responses specification says disabled must not truncate any input.
A summary and a cleared result do not drop your input in silence: you asked
for them, and every one is reported.
Errors
Section titled “Errors”| Status | code | param | Meaning |
|---|---|---|---|
400 | compaction_model_not_allowed | The offending field | The model named to write a summary is not one of the affordable models compaction allows, so that no single call produces a surprise charge. |
409 | compaction_in_progress | Always null | A compaction of this conversation is in progress: another was already running, or this one outlasted the request's wait. One that outlasted the wait keeps running and is charged for the calls it makes. If it stores a summary, the same request sent again returns that summary at no charge while no turn has been added since; if it fails, the conversation's next response reports it in helpingio:warnings. |