Fixing OpenClaw's 16k Context Window

Explains the OpenClaw 16k context error and how to fix the local configuration.

Fixing OpenClaw's 16k Context Window

If OpenClaw reports an API rate limit error, the local context window may be set to 16k and must be changed manually.

An OpenClaw model's context window is not fixed at 16k; it mainly depends on your local configuration. Check ~/.openclaw/openclaw.json or ~/.openclaw/agents/<agentId>/agent/models.json, then change contextWindow and maxTokens for the relevant model to values it actually supports. For MiniMax-M2.5, for example, you can set contextWindow: 196608 and maxTokens: 8192. Restart OpenClaw after making the change.

The underlying issue is that contextWindow has been set to 16000, or even lower, for a custom provider or custom model. OpenClaw relies heavily on these configuration values. If the model actually supports a larger context window, increase the value. Otherwise, you may see errors such as API rate limit reached, run out of context, or encounter erratic behavior during long conversations.

How to Update OpenClaw's Context Configuration

One. Symptoms

If the context window in a custom or third-party gateway model configuration is set too low, for example:

"contextWindow": 16000, "maxTokens": 4096

You may encounter the following problems:

  • Long conversations fail easily
  • Tool calls produce errors more often
  • The page displays API rate limit reached
  • OpenClaw continues to use the lower value even though the model supports a larger context window

Two. Configuration File Locations

1) Main Configuration File

OpenClaw's default main configuration file is:

~/.openclaw/openclaw.json

2) Agent Model Configuration

If models are configured separately for each agent, the path is usually:

~/.openclaw/agents/<agentId>/agent/models.json

3) Custom Agent Root Directory

If you have set the OPENCLAW_AGENT_DIR environment variable, it overrides the agent configuration directory.

Three. How to Change the Values

Option A: Update the Main Configuration

Open ~/.openclaw/openclaw.json. Find the configuration for your current model provider and adjust contextWindow and maxTokens values:

{
  "models": {
    "mode": "merge",
    "providers": {
      "minimax": {
        "baseUrl": "https://api.minimax.io/anthropic",
        "api": "anthropic-messages",
        "apiKey": "your-api-key",
        "models": [
          {
            "id": "MiniMax-M2.5",
            "name": "MiniMax-M2.5",
            "reasoning": false,
            "input": ["text"],
            "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
            "contextWindow": 196608,
            "maxTokens": 8192
          }
        ]
      }
    }
  }
}

Option B: Update the Agent-Level File

Open ~/.openclaw/agents/<agentId>/agent/models.json. Change the relevant model values from:

"contextWindow": 16000, "maxTokens": 4096

To more appropriate values, for example:

"contextWindow": 196608, "maxTokens": 8192

Four. Recommended Values

Do not enter arbitrary values. Setting 1000000 just because you want a 1M context window does not make the model support it.

Recommended Guidelines

  • contextWindow: Use the model's actual supported context window
  • maxTokens: Use the model's actual maximum output length
  • If you use an API gateway, check the limit that the gateway actually allows, not just the original provider's advertised limit

MiniMax-M2.5 Example

The official OpenClaw example recommends:

"contextWindow": 196608, "maxTokens": 8192

Five. After Updating the Configuration

Save the configuration, then restart OpenClaw or the relevant gateway process.

Common commands include:

openclaw models list
openclaw models set minimax/MiniMax-M2.5

If OpenClaw runs as a service, restart the relevant service as well, for example:

openclaw gateway restart

Or restart your systemd service, pm2 process, or Docker container.

Six. Additional Notes

  • Custom providers can be defined directly under models.providers
  • contextWindow and maxTokens can be set explicitly
  • For a matching model, OpenClaw uses the higher values from the explicit configuration and the implicit catalog
  • To completely replace models.json with your own configuration, use models.mode: "replace"
  • When these fields are omitted for custom providers, the defaults are contextWindow: 200000 and maxTokens: 8192. If you still see 16k or 4k, your local model configuration was likely set too low or an old configuration is still present.