-
-
Notifications
You must be signed in to change notification settings - Fork 52.6k
Description
Summary
Setting contextWindow: 1000000 for claude-opus-4-6 in openclaw.json does not enable the 1M context window. The Anthropic API requires a beta header (e.g., context-1m-2025-08-07) to unlock 1M context, but the pi-ai provider (@mariozechner/pi-ai v0.51.6) does not send it.
This creates a dangerous mismatch: the gateway internally uses the configured 1M context window for compaction thresholds and pruning decisions, but the API enforces the default 200K limit. Sessions overflow at 200K while the gateway thinks there's 800K of headroom remaining.
Steps to Reproduce
- Configure
claude-opus-4-6withcontextWindow: 1000000inopenclaw.json:
"models": {
"providers": {
"anthropic": {
"models": [{
"id": "claude-opus-4-6",
"contextWindow": 1000000,
"maxTokens": 128000
}]
}
}
}- Start a conversation and let context grow past 200K tokens
- API rejects with
request_too_largeeven though gateway thinks there's room
Root Cause
In pi-ai/providers/anthropic.js (createClient, ~line 337), the anthropic-beta header is hardcoded to:
fine-grained-tool-streaming-2025-05-14interleaved-thinking-2025-05-14(conditionally)
There is no logic to add a context extension beta header based on the model's context window or model ID.
The contextWindow value from config is consumed only internally (compaction thresholds, pruning config, context window guard) — it is never included in API request headers or parameters.
Expected Behavior
When contextWindow > 200000 is configured for a model that supports extended context (e.g., claude-opus-4-6), the gateway should:
- Automatically add the appropriate
anthropic-betaheader to enable the extended context window, OR - Warn at startup that the configured context window exceeds what the API will accept without a beta header, OR
- Provide a config option to specify additional beta headers per model (e.g.,
betaHeaders: ["context-1m-2025-08-07"])
Impact
Without the beta header, the mismatch between configured (1M) and actual (200K) context limits causes:
- Safeguard compaction triggers far too late (at ~940K instead of ~180K)
- Sessions overflow repeatedly with no intervention
- Users see "Context overflow: prompt too large" errors despite having configured 1M context
Workaround
Set contextWindow: 200000 for claude-opus-4-6 until the beta header is supported.
Environment
- OpenClaw version: 2026.2.4
- pi-ai version: 0.51.6
- Model: claude-opus-4-6
- OS: macOS