Skip to content

[Bug]: 1M context window for Claude Opus 4.6 — beta header not sent by pi-ai provider #10647

@ClumsyWizardHands

Description

@ClumsyWizardHands

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

  1. Configure claude-opus-4-6 with contextWindow: 1000000 in openclaw.json:
"models": {
  "providers": {
    "anthropic": {
      "models": [{
        "id": "claude-opus-4-6",
        "contextWindow": 1000000,
        "maxTokens": 128000
      }]
    }
  }
}
  1. Start a conversation and let context grow past 200K tokens
  2. API rejects with request_too_large even 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-14
  • interleaved-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:

  1. Automatically add the appropriate anthropic-beta header to enable the extended context window, OR
  2. Warn at startup that the configured context window exceeds what the API will accept without a beta header, OR
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions