openclaw - 💡(How to fix) Fix OpenRouter model context window not auto-detected from provider catalog [1 comments, 2 participants]

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…
GitHub stats
openclaw/openclaw#58059Fetched 2026-04-08 01:54:23
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
commented ×1

Error Message

No valid workaround found. The models block in agents.defaults.models does not accept contextWindow as a key (config validation error). The context1m param mentioned in docs also fails validation.

Fix Action

Workaround

No valid workaround found. The models block in agents.defaults.models does not accept contextWindow as a key (config validation error). The context1m param mentioned in docs also fails validation.

Code Example

"openrouter/qwen/qwen3.6-plus-preview:free": {}
RAW_BUFFERClick to expand / collapse

Issue

When a model is listed in agents.defaults.models (the allowlist/catalog), OpenClaw does not automatically resolve its contextWindow from the provider's API. Instead, it falls back to a default (200k).

Reproduction

  1. Add a model to agents.defaults.models:
    "openrouter/qwen/qwen3.6-plus-preview:free": {}
  2. OpenClaw reports context as 21k/200k in session status
  3. OpenRouter's /api/v1/models endpoint returns "context_length": 1000000 for this model

Expected

OpenClaw should auto-resolve contextWindow (1M) from OpenRouter's model catalog instead of using a hardcoded 200k fallback.

Observed

Session status card shows 21k/200k (11%) — the context window is capped at 200k despite the model supporting 1M.

Workaround

No valid workaround found. The models block in agents.defaults.models does not accept contextWindow as a key (config validation error). The context1m param mentioned in docs also fails validation.

Impact

Long sessions on 1M context models hit compaction/eviction 5x earlier than necessary.

Environment

  • OpenClaw: 2026.3.28
  • Provider: OpenRouter
  • Model: qwen/qwen3.6-plus-preview:free (1M context)
  • Config: models mode = "merge"

extent analysis

Fix Plan

To resolve the issue, we need to update the OpenClaw configuration to automatically resolve the contextWindow from the provider's API.

Here are the steps:

  • Update the agents.defaults.models configuration to include the contextWindow key.
  • Modify the OpenClaw code to fetch the context_length from the OpenRouter's /api/v1/models endpoint and update the contextWindow accordingly.

Example code snippet:

# Fetch model details from OpenRouter's API
model_details = requests.get(f"{openrouter_url}/api/v1/models/{model_name}").json()

# Update contextWindow in OpenClaw config
context_window = model_details.get("context_length", 200000)
openclaw_config["contextWindow"] = context_window
  • Add error handling to ensure that the contextWindow is updated correctly even if the API call fails.

Verification

To verify that the fix worked, check the session status card in OpenClaw. It should display the correct contextWindow value (1M) instead of the hardcoded 200k fallback.

Extra Tips

  • Ensure that the OpenRouter's API endpoint is correctly configured and accessible.
  • Handle cases where the context_length is not available in the model details API response.
  • Consider adding logging to track any errors that occur during the API call or config update.

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