Skip to main content
Handle growing history before it exceeds the model’s context window. The standalone compaction endpoint returns a new context window; it does not produce the final answer and is not a universal summarization API. Confirm that the same model and channel support both /responses/compact and /responses, including preservation and replay of compaction items.

Compact and continue

Install the existing Python example dependencies. The script uses a fixed demonstration conversation, compacts it, then appends a question and generates text: two requests. In a real application, supply your complete saved inputs, outputs, tool results, and reasoning items.

Retention and replay

Standalone compaction returns object: response.compaction and output; do not read it using the usual Responses status / output_text contract. Preserve the entire ordered output, including additional fields. Use it as the next context window and append new input. Do not keep only the compaction item or append the old transcript again. encrypted_content is opaque state, not a readable summary to decode or modify. The input to compaction must still fit the model’s context window. See the OpenAI compaction guide for these protocol rules. The example supplies instructions explicitly on each request and continues with store: false. That is not a retention guarantee for the gateway, logs, or upstream. Compaction does not synchronize your database, business state, or permission rules.

Failure and compatibility

  • Keep the original history if compaction fails or returns an empty window. Do not continue generation or automatically delete history.
  • If compaction succeeds but continuation fails, retain the original history and valid compacted window so the application can choose a recovery point. Do not automatically rerun the entire flow.
  • Load balancing may send the two requests to incompatible upstreams. Confirm routing, credentials, and state compatibility with the administrator; the same model ID alone does not guarantee replay.
  • Automatic context_management, stored response IDs, and background execution are separate capabilities. Responses retrieval covers only plugin task responses, not general upstream retrieval or REST deletion / cancellation. See API coverage.
This text example checks window structure and final text completion, not preservation of every fact. Evaluate important constraints, tool associations, and long-conversation quality against a real deployment. The local fixture does not validate encrypted state. Multi-turn conversations · Production integration 阅读中文 Prompt caching · Reasoning models · Context management