Python 88.3%
TypeScript 7.6%
Shell 4.1%
1"""Server-side compaction configuration with the Python SDK (beta compact-2026-01-12): context_management.edits2[{type: compact_20260112, trigger: {input_tokens: 50000}}] on claude-sonnet-5. With a tiny prompt no compaction is3triggered, but the response shows the beta shape: usage.iterations[] and context_management.applied_edits [].4Also demonstrates the Haiku rejection (compact_20260112 is 4.6+ only).5STATUS: LIVE_VERIFIED 2026-09-18: Sonnet 5 200 with iterations [{type: message}]; Haiku 4006"'claude-haiku-4-5-20251001' does not support the 'compact_20260112' context management strategy." (~$0.0002).7Run: .venv/bin/python examples/anthropic/context-management/compaction_config.py8"""9from __future__ import annotations1011import os12import sys13from pathlib import Path1415sys.path.insert(0, str(Path(__file__).resolve().parents[3]))16from scripts import live # noqa: E4021718import anthropic # noqa: E4021920client = anthropic.Anthropic(max_retries=1)21MODEL = os.environ.get("ANTHROPIC_MODEL", "claude-sonnet-5")22EDITS = [{"type": "compact_20260112", "trigger": {"type": "input_tokens", "value": 50000},23 "instructions": "Summarize the conversation for continuation. Do not call any tools."}]2425msg = client.beta.messages.create(model=MODEL, max_tokens=8, betas=["compact-2026-01-12"],26 context_management={"edits": EDITS}, messages=[{"role": "user", "content": "Reply with OK."}])27print(MODEL, "->", msg.content[0].text, "| applied_edits:", msg.context_management.applied_edits if msg.context_management else None,28 "| iterations:", [(i.type, i.input_tokens, i.output_tokens) for i in (msg.usage.iterations or [])])29live.log_request("anthropic", "POST", "/v1/messages", 200, 0.0002, f"example context-management/compaction_config.py {MODEL} beta=compact-2026-01-12")3031try:32 client.beta.messages.create(model="claude-haiku-4-5-20251001", max_tokens=8, betas=["compact-2026-01-12"],33 context_management={"edits": EDITS}, messages=[{"role": "user", "content": "Reply with OK."}])34except anthropic.BadRequestError as e:35 print("haiku ->", e.status_code, e.body["error"]["message"])36 live.log_request("anthropic", "POST", "/v1/messages", e.status_code, 0, "example context-management/compaction_config.py haiku unsupported")37