BerriAI/litellm · error · AnthropicContextManagementError
context_management.compact_20260112.trigger.value must be at
Error message
context_management.compact_20260112.trigger.value must be at least {COMPACT_MIN_TRIGGER_TOKENS} tokens What it means
Raised by the in-gateway context_management polyfill when validating the compact_20260112 edit specification. The trigger threshold ('context_management.compact_20260112.trigger.value') must be an int of at least 50,000 tokens (COMPACT_MIN_TRIGGER_TOKENS); smaller values are rejected outright rather than clamped, because too-low thresholds would fire compaction constantly. Non-int values get a warning and fall back to the 150,000 default instead.
Source
Thrown at litellm/llms/anthropic/experimental_pass_through/context_management/editors/compact.py:562
"""
warnings: Final[list[str]] = []
trigger: Final = edit_spec.get("trigger") or {}
if not isinstance(trigger, dict):
warnings.append("trigger_not_a_dict_using_default")
return COMPACT_DEFAULT_TRIGGER_TOKENS, warnings
trigger_type: Final = trigger.get("type", "input_tokens")
if trigger_type != "input_tokens":
warnings.append(f"unsupported_trigger_type_{trigger_type}_using_input_tokens")
value: Final = trigger.get("value")
if value is None:
return COMPACT_DEFAULT_TRIGGER_TOKENS, warnings
if not isinstance(value, int):
warnings.append("trigger_value_not_int_using_default")
return COMPACT_DEFAULT_TRIGGER_TOKENS, warnings
if value < COMPACT_MIN_TRIGGER_TOKENS:
raise AnthropicContextManagementError(
status_code=400,
message=(
f"context_management.compact_20260112.trigger.value must be at "
f"least {COMPACT_MIN_TRIGGER_TOKENS} tokens"
),
)
return value, warnings
def _build_summary_prompt(edit_spec: Mapping[str, object], tools: Sequence[Mapping[str, object]] | None) -> str:
custom: Final = edit_spec.get("instructions")
if isinstance(custom, str) and custom.strip():
return custom
prompt = COMPACT_DEFAULT_INSTRUCTIONS
if tools:
prompt = f"{prompt}{COMPACT_NO_TOOL_CALLS_SUFFIX}"
return prompt
View on GitHub (pinned to 6c2dcb801b)
Solutions
- Set trigger.value to an int >= 50,000, e.g. 50_000 is the minimum accepted.
- For local testing of compaction, you cannot lower the threshold; instead send a long conversation that exceeds it.
- Omit trigger entirely to accept the 150,000 default.
- Keep the value a plain int (not a float or string) or the default is silently used with a warning.
Example fix
# before
context_management = {
"edits": [{"type": "compact_20260112", "trigger": {"type": "input_tokens", "value": 5000}}]
}
# after
context_management = {
"edits": [{"type": "compact_20260112", "trigger": {"type": "input_tokens", "value": 50000}}]
} Defensive patterns
Strategy: validation
Validate before calling
COMPACT_MIN_TRIGGER_TOKENS = 50_000
def validate_compact_trigger(trigger: dict) -> int:
value = trigger.get("value", 150_000)
if not isinstance(value, int) or isinstance(value, bool):
return 150_000 # gateway will warn and use default
if value < COMPACT_MIN_TRIGGER_TOKENS:
raise ValueError(f"trigger.value must be >= {COMPACT_MIN_TRIGGER_TOKENS}")
return value Type guard
def is_valid_compact_trigger(trigger: object) -> bool:
if not isinstance(trigger, dict):
return False
v = trigger.get("value")
return v is None or (isinstance(v, int) and not isinstance(v, bool) and v >= 50_000) Try / catch
try:
resp = litellm.anthropic_messages(**body)
except Exception as e:
if "must be at least" in str(e) and "trigger.value" in str(e):
body["context_management"]["edits"][0]["trigger"]["value"] = 50_000
resp = litellm.anthropic_messages(**body)
else:
raise Prevention
- Treat trigger.value as an absolute token count, never a percentage.
- Never try to force compaction in tests via a tiny threshold — build a long conversation instead.
- Keep the value a plain int; floats silently fall back to the 150k default.
When it happens
Trigger: Sending an Anthropic /v1/messages request with context_management={"edits": [{"type": "compact_20260112", "trigger": {"value": 10000}}]} — any int below 50,000. Note float values like 50000.0 hit the 'not int' warning path instead and use the default.
Common situations: Developers testing compaction with small token counts to force it to trigger; porting configs from providers with lower compaction thresholds; assuming the value is a percentage or a ratio rather than an absolute token count.
Related errors
- WebSearchInterception: missing follow-up messages
- Invalid first message. Should always start with 'role'='user
- Unable to parse anthropic tool result for message: {message}
- Unable to parse anthropic file message: {message}
- Either file_data or file_id must be present in the file mess
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/d50db9ec8261be53.
Report an issue: GitHub.