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 16 k and must be changed manually.
An OpenClaw error screen showing “API rate limit reached. Please try aga…
The MiniMax-M2.5 model settings in an OpenClaw configuration file. A red…
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. Both the official configuration reference and the MiniMax example support this format.
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. The official configuration reference states that OpenClaw’s main configuration file is ~/.openclaw/openclaw.json and that you can also place a separate models.json file in an agent directory. When matching a model, OpenClaw uses the higher contextWindow and maxTokens values from the explicit configuration and the implicit catalog.
On the web configuration page, search for contextWindow and change it to 128000.
The Settings tab on the OpenClaw configuration page. A red box highlight…
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": 4096You 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
The official OpenClaw documentation explains that contextWindow and maxTokens can be set explicitly in the configuration. The main configuration file is located at ~/.openclaw/openclaw.json, and a separate models.json file in an agent directory can also override these settings.
Two. Configuration File Locations
1) Main Configuration File
OpenClaw’s default main configuration file is:
~/.openclaw/openclaw.jsonThis location is specified in the official documentation.
2) Agent Model Configuration
If models are configured separately for each agent, the path is usually:
~/.openclaw/agents/<agentId>/agent/models.jsonThe official documentation states that a custom provider can be added under models.providers or defined in ~/.openclaw/agents/<agentId>/agent/models.json.
3) Custom Agent Root Directory
If you have set the following environment variable:
OPENCLAW_AGENT_DIRThat environment variable overrides the agent configuration directory. The official documentation also states that OPENCLAW_AGENT_DIR, or PI_CODING_AGENT_DIR, can change the agent configuration root.
Three. How to Change the Values
Option A: Update the Main Configuration
openclaw.json
Open:
~/.openclaw/openclaw.jsonFind the configuration for your current model provider, for example:
{
models: {
mode: "merge",
providers: {
minimax: {
baseUrl: "https://api.minimax.io/anthropic",
api: "anthropic-messages",
apiKey: "你的 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
}
]
}
}
}
}The official MiniMax-M2.5 example uses contextWindow: 196608 and maxTokens: 8192.
Option B: Update the Agent-Level File
models.json
Open:
~/.openclaw/agents/<agentId>/agent/models.jsonChange the relevant model values from:
"contextWindow": 16000,
"maxTokens": 4096To more appropriate values, for example:
"contextWindow": 196608,
"maxTokens": 8192Four. 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": 8192Five. 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.5The official documentation also provides these commands for checking and switching models.
If OpenClaw runs as a service, restart the relevant service as well, for example:
openclaw gateway restartOr restart your systemd service, pm2 process, or Docker container.
Six. Additional Notes
The official OpenClaw configuration reference also notes that:
- 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".
The current official documentation also states that when these fields are omitted for custom providers, the defaults are contextWindow: 200000 and maxTokens: 8192. If a customer still sees 16k or 4k, it probably does not mean that OpenClaw now defaults to only 16k. More likely, their local model configuration was manually set too low or an old configuration is still present.