Skip to content

OpenAIResponsesCompactionSessionOptions

type OpenAIResponsesCompactionSessionOptions = object;
optional client?: OpenAIClient;

OpenAI client used to call responses.compact.

When omitted, the session will use getDefaultOpenAIClient() if configured. Otherwise it creates a new OpenAI() instance via new OpenAI().


optional compactionMode?: OpenAIResponsesCompactionMode;

Controls how the compaction request is built.

  • auto (default): Uses input when the last response was not stored or no response id is available.
  • previous_response_id: Uses the server-managed response chain.
  • input: Sends the locally stored session items as input and does not require a response id.

optional maxRollbackItems?: number;

Optional positive integer budget for complete history snapshots used for rollback. The budget plus one must be a safe integer. Omitting the budget preserves unlimited reads.

Snapshot reads request at most this many items plus one overflow item. Oversized history throws a UserError before the compaction API call, including forced calls. The snapshot is refreshed and checked again after the API call, before replacing history. Automatic compaction that passes the ownership and model-visibility checks also honors this budget.

This does not limit bytes, tokens, stored history, model input, or ordinary candidate reads. Underlying retrieval defaults remain independent of this budget.


optional model?: OpenAI.ResponsesModel;

The OpenAI model to use for responses.compact.

Defaults to DEFAULT_OPENAI_MODEL. The value must resemble an OpenAI model name (for example gpt-*, o*, or a fine-tuned ft:gpt-* identifier), otherwise the constructor throws.


optional shouldTriggerCompaction?: (context) => boolean | Promise<boolean>;

Custom decision hook that determines whether to call responses.compact.

The default implementation compares the length of OpenAIResponsesCompactionDecisionContext.compactionCandidateItems to an internal threshold (10). Override this to support token-based triggers or other heuristics using OpenAIResponsesCompactionDecisionContext.compactionCandidateItems or OpenAIResponsesCompactionDecisionContext.sessionItems.

Parameter Type

context

OpenAIResponsesCompactionDecisionContext

boolean | Promise<boolean>


optional underlyingSession?: Session & object;

Session store that receives items and holds the compacted history.

The underlying session is the source of truth for persisted items. Compaction clears the underlying session and writes the output items returned by responses.compact.

This must not be an OpenAIConversationsSession, because compaction relies on locally stored items and replaces the underlying session history after responses.compact.

Defaults to an in-memory session for demos.

Name Type

[OPENAI_SESSION_API]?

"responses"