openclaw - 💡(How to fix) Fix xAI models report incorrect context window (200k instead of 1M) — long_context_threshold misinterpreted

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

The xAI /v1/models API response does not include a context_length field. Instead it returns:

{
  "id": "grok-4.3",
  "long_context_threshold": 200000,
  ...
}

long_context_threshold is a pricing breakpoint (input tokens above this threshold are charged at 2x rate), not the actual context window size. OpenClaw's model discovery appears to use this value as the context window.

Fix Action

Workaround

Adding explicit model overrides in openclaw.json under models.providers correctly overrides the discovered values (since applyConfiguredContextWindows runs after applyDiscoveredContextWindows):

{
  "models": {
    "providers": {
      "xai": {
        "models": [
          {"id": "grok-4.3", "name": "Grok 4.3", "contextWindow": 1000000, "input": ["text", "image"]},
          {"id": "grok-build-0.1", "name": "Grok Build 0.1", "contextWindow": 256000, "input": ["text", "image"]}
        ]
      }
    }
  }
}

After restart, openclaw models list shows the correct values.

Code Example

{
  "id": "grok-4.3",
  "long_context_threshold": 200000,
  ...
}

---

$ openclaw models list --json
{
  "key": "xai/grok-4.3",
  "input": "text",           <-- should be "text+image"
  "contextWindow": 200000,   <-- should be 1000000
  ...
}

---

{
  "models": {
    "providers": {
      "xai": {
        "models": [
          {"id": "grok-4.3", "name": "Grok 4.3", "contextWindow": 1000000, "input": ["text", "image"]},
          {"id": "grok-build-0.1", "name": "Grok Build 0.1", "contextWindow": 256000, "input": ["text", "image"]}
        ]
      }
    }
  }
}

---

XAI_DEFAULT_CONTEXT_WINDOW = 1e6    // grok-4.3
XAI_LARGE_CONTEXT_WINDOW = 2e6     // grok-4.20
XAI_CODE_CONTEXT_WINDOW = 256e3    // grok-build
RAW_BUFFERClick to expand / collapse

Bug Description

The xAI provider reports incorrect context window values for all xAI models. grok-4.3 shows 195k/200k context instead of the actual 1,000,000 tokens documented by xAI. Similarly, grok-build-0.1 shows correctly at 256k but the display for grok-4.3 is wrong.

Root Cause

The xAI /v1/models API response does not include a context_length field. Instead it returns:

{
  "id": "grok-4.3",
  "long_context_threshold": 200000,
  ...
}

long_context_threshold is a pricing breakpoint (input tokens above this threshold are charged at 2x rate), not the actual context window size. OpenClaw's model discovery appears to use this value as the context window.

Actual xAI Model Specs (from console.x.ai)

ModelContext WindowInput Modalities
grok-4.31,000,000text + image
grok-build-0.1256,000text + image
grok-4.20-0309-reasoning1,000,000text + image
grok-4.20-0309-non-reasoning1,000,000text + image
grok-4.20-multi-agent-03091,000,000text + image

Observed Behavior

$ openclaw models list --json
{
  "key": "xai/grok-4.3",
  "input": "text",           <-- should be "text+image"
  "contextWindow": 200000,   <-- should be 1000000
  ...
}

Workaround

Adding explicit model overrides in openclaw.json under models.providers correctly overrides the discovered values (since applyConfiguredContextWindows runs after applyDiscoveredContextWindows):

{
  "models": {
    "providers": {
      "xai": {
        "models": [
          {"id": "grok-4.3", "name": "Grok 4.3", "contextWindow": 1000000, "input": ["text", "image"]},
          {"id": "grok-build-0.1", "name": "Grok Build 0.1", "contextWindow": 256000, "input": ["text", "image"]}
        ]
      }
    }
  }
}

After restart, openclaw models list shows the correct values.

Suggested Fix

In the xAI model definition catalog (model-definitions-*.js), the constants are already correct:

XAI_DEFAULT_CONTEXT_WINDOW = 1e6    // grok-4.3
XAI_LARGE_CONTEXT_WINDOW = 2e6     // grok-4.20
XAI_CODE_CONTEXT_WINDOW = 256e3    // grok-build

The issue is that the API probe/discovery step overwrites these with the long_context_threshold value from the xAI API. The fix should either:

  1. Not use long_context_threshold as a context window source, or
  2. Ensure the built-in catalog values take priority over API-probed values when the API doesn't provide a proper context_length field

Environment

  • OpenClaw: 2026.5.28 (also confirmed on 2026.5.26)
  • OS: Ubuntu 26.04 LTS
  • Node.js: 24.14.1

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix xAI models report incorrect context window (200k instead of 1M) — long_context_threshold misinterpreted