## Compatibility
The whole hunk
from line 2, old and new numbered
/
lines
from line 2
22title: Compaction at a token threshold
33url: https://platform.claude.com/docs/en/build-with-claude/compaction-threshold
44description: Have the API summarize older context automatically, inside an ordinary request, when the conversation reaches a token threshold you set.
5featureMetadata:
6 status: beta
7 betaHeader: compact-2026-01-12
8 zdr:
9 eligibility: eligible
10 note: Excludes [Covered Models](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#model-specific-data-retention-requirements).
11 supportedModels:
12 - claude-fable-5-1
13 - claude-mythos-5-1
14 - claude-fable-5
15 - claude-mythos-5
16 - claude-mythos-preview
17 - claude-opus-5
18 - claude-opus-4-8
19 - claude-opus-4-7
20 - claude-opus-4-6
21 - claude-sonnet-5
22 - claude-sonnet-4-6
23 supportedPlatforms:
24 Claude API: beta
25 Claude Platform on AWS: beta
26 Amazon Bedrock: beta
27 Google Cloud: beta
28 Microsoft Foundry: beta
529---
630
7## Compatibility
8- Status: Beta
9- [Beta header](https://platform.claude.com/docs/en/api/beta-headers): `compact-2026-01-12`
10- [ZDR](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention): eligible (excludes [Covered Models](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#model-specific-data-retention-requirements))
11- Supported models: `claude-fable-5-1`, `claude-mythos-5-1`, `claude-fable-5`, `claude-mythos-5`, `claude-mythos-preview`, `claude-opus-5`, `claude-opus-4-8`, `claude-opus-4-7`, `claude-opus-4-6`, `claude-sonnet-5`, `claude-sonnet-4-6`
12- Platforms: Claude API (beta), Claude Platform on AWS (beta), Amazon Bedrock (beta), Google Cloud (beta), Microsoft Foundry (beta)
13
1431Threshold compaction is the automatic kind of compaction: you set a token threshold on your ordinary requests, and the API summarizes older context partway through a request once the threshold is reached. It is supported alongside on-demand compaction, where you decide when the summary is written (see [Compaction on demand](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand)). To choose between them, see [Choose how to compact](https://platform.claude.com/docs/en/build-with-claude/compaction#choose-how-to-compact).
1532
1633Compaction extends the effective context length for long-running conversations and tasks by automatically summarizing older context when approaching the context window limit. It also keeps the active context small: as a conversation grows, response quality degrades, so compaction replaces older content with a concise summary.
from line 1701
16841701 puts next_response.content
16851702 ```
16861703</CodeGroup>
1704
1705In Python, use `client.beta.messages`, as the samples on this page do. If you call `client.messages` and serialize blocks yourself, a plain `model_dump()` adds `text: null` and `citations: null` to the `compaction` block. The API then rejects the request with a 400 error (`Extra inputs are not permitted`). Use `to_dict()` or `model_dump(exclude_none=True)` instead. [Continue from the summary](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#continue-from-the-summary) gives the same advice for on-demand compaction.
16871706
16881707When the API receives a `compaction` block, all content blocks before it are ignored. You can either:
16891708