Python 88.3%
TypeScript 7.6%
Shell 4.1%
1#!/usr/bin/env python32# STATUS: LIVE_VERIFIED — executed 2026-09-18 (exit 0 in 4.9s)3# Compaction with the SDK: (1) standalone /responses/compact then continue with the compacted window as input (store=False, ZDR-friendly);4# (2) server-side compaction is just `context_management=[{"type":"compaction","compact_threshold":N}]` on responses.create (N >= 1000).5import pathlib6import sys78ROOT = pathlib.Path(__file__).resolve().parents[3]9sys.path.insert(0, str(ROOT))10from scripts import live # noqa: E4021112from openai import OpenAI # noqa: E4021314client = OpenAI()15M = "gpt-5.4-nano"16window = [{"role": "user", "content": "Reply with OK."}, {"role": "assistant", "content": "OK"}, {"role": "user", "content": "Reply with OK again."}]1718compacted = client.responses.compact(model=M, input=window)19live.log_request("openai", "POST", "/v1/responses/compact", 200, 0.0003, "example responses/compaction.py")20print(compacted.object, [item.type for item in compacted.output], compacted.usage.model_dump())2122# next turn: compacted window (do not prune it) + new user message23next_input = [item.model_dump(exclude_none=True) for item in compacted.output] + [{"role": "user", "content": "Reply with OK."}]24follow = client.responses.create(model=M, input=next_input, store=False, max_output_tokens=32)25live.log_request("openai", "POST", "/v1/responses", 200, 0.00003, "example compaction.py follow-up")26print("follow-up:", follow.status, repr(follow.output_text), "input_tokens:", follow.usage.input_tokens)2728# server-side compaction flag (threshold far above this tiny context -> no compaction happens, but the parameter is accepted)29auto = client.responses.create(model=M, input="Reply with OK.", store=False, max_output_tokens=32,30 context_management=[{"type": "compaction", "compact_threshold": 100000}])31live.log_request("openai", "POST", "/v1/responses", 200, 0.00002, "example compaction.py context_management")32print("context_management accepted:", auto.status, [o.type for o in auto.output])33assert compacted.object == "response.compaction" and any(o.type == "compaction" for o in compacted.output)34