Context window management
Definition
A model's context window is the maximum number of tokens it can read in one request. Context window management is the set of gateway mechanisms that keep a conversation inside that window, so a long conversation continues instead of failing.
Function
Every turn, tool call and tool result adds tokens. Without management, a long conversation eventually exceeds the window. The gateway condenses older history and bounds large inputs so the most recent turns stay intact.
Compaction
Compaction condenses the earlier part of a conversation into a summary and keeps the recent turns in full. There are two mechanisms:
- Summarize pass (chat surface) — a model-agnostic pass that condenses older turns in the background while the user keeps working. The chat shows a short indicator while it runs. It works with any model.
- Native compaction — for provider models that support a native compaction strategy, the gateway asks the provider to compact on the upstream call.
Rules:
- Compaction is enabled per gateway and triggers at a configured threshold.
- A compaction summary is a real model call. It is billed and counted against budgets like any other call. When the wallet cannot pay for it, the history stays unchanged and compaction is retried on a later turn.
Tool-loop safety limits
One turn can run several rounds of tool calls. The gateway caps each turn by wall-clock time, by number of rounds, and by repeated identical tool calls, so a turn can never hang. When the time limit is reached after tools have already returned results in this request, the gateway composes a final answer from those results and marks it as partial.
Long and data-file turns
- Data-file preview bounding — when a conversation re-sends a large attached file, its inline preview is trimmed so the preview alone cannot overflow the window. The full file stays available to tools such as the code interpreter.
- Automatic model upgrade for data-file turns — when a turn works over a data file and the chosen model is not suited to it, the gateway upgrades that one turn to a capable model. On the chat surface this happens under the Auto model setting.
See also
- Configuration reference — Context compaction — thresholds and settings.
- Anthropic — native compaction and the models that support it.
- Budgets — Wallet — paying for compaction on prepaid credit.