openclaw - 💡(How to fix) Fix Bug: New session fails with anthropic-messages API models due to empty messages array [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#74388Fetched 2026-04-30 06:24:26
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Author
Timeline (top)
closed ×1commented ×1

When a new session starts with a model using the anthropic-messages API format (e.g., minimax-M2.7 via minimax-portal), the LLM request fails with "messages must not be empty". The fallback model (using openai-completions format) then succeeds.

Error Message

The Anthropic Messages API requires at least one message in the messages array, causing minimax to reject the request with error code 2013. error=LLM request rejected: invalid params, messages must not be empty (2013) 3. Observe the "messages must not be empty" error

Root Cause

During new session initialization, OpenClaw constructs the LLM request with:

  • messages: [] (empty array)
  • prompt: "" (empty string)
  • systemPrompt: populated (52KB in our case)

The Anthropic Messages API requires at least one message in the messages array, causing minimax to reject the request with error code 2013.

Models using openai-completions API format (e.g., xiaomi/mimo-v2.5) do not have this requirement and succeed with empty messages.

Code Example

{
  "messages": [],
  "prompt": "",
  "systemPrompt length": 52110
}

---

11:39:48 [agent/embedded] embedded run agent end: runId=a3db82ec 
  model=MiniMax-M2.7 provider=minimax-portal 
  error=LLM request rejected: invalid params, messages must not be empty (2013)

11:39:49 [model-fallback/decision] model fallback decision: 
  decision=candidate_failed requested=minimax-portal/MiniMax-M2.7 
  reason=format next=xiaomi/mimo-v2.5

11:39:54 [agent/embedded] session file repaired: 
  rewrote 1 assistant message(s), dropped 1 blank user message(s)

---

{"type": "message", "message": {"role": "user", "content": [{"type": "text", "text": ""}]}}
RAW_BUFFERClick to expand / collapse

Description

When a new session starts with a model using the anthropic-messages API format (e.g., minimax-M2.7 via minimax-portal), the LLM request fails with "messages must not be empty". The fallback model (using openai-completions format) then succeeds.

Root Cause

During new session initialization, OpenClaw constructs the LLM request with:

  • messages: [] (empty array)
  • prompt: "" (empty string)
  • systemPrompt: populated (52KB in our case)

The Anthropic Messages API requires at least one message in the messages array, causing minimax to reject the request with error code 2013.

Models using openai-completions API format (e.g., xiaomi/mimo-v2.5) do not have this requirement and succeed with empty messages.

Evidence

1. Trajectory Data (prompt.submitted)

{
  "messages": [],
  "prompt": "",
  "systemPrompt length": 52110
}

2. Gateway Logs

11:39:48 [agent/embedded] embedded run agent end: runId=a3db82ec 
  model=MiniMax-M2.7 provider=minimax-portal 
  error=LLM request rejected: invalid params, messages must not be empty (2013)

11:39:49 [model-fallback/decision] model fallback decision: 
  decision=candidate_failed requested=minimax-portal/MiniMax-M2.7 
  reason=format next=xiaomi/mimo-v2.5

11:39:54 [agent/embedded] session file repaired: 
  rewrote 1 assistant message(s), dropped 1 blank user message(s)

3. Session File Corruption

Session files contain blank user messages created during initialization:

{"type": "message", "message": {"role": "user", "content": [{"type": "text", "text": ""}]}}

The repair mechanism (repairUserEntryWithBlankTextContent) detects and removes these, but only AFTER the LLM call has already failed.

Reproduction

  1. Configure a model with "api": "anthropic-messages" as the primary model
  2. Start a new session (e.g., via /new command or first message in a group chat)
  3. Observe the "messages must not be empty" error
  4. Session falls back to the first openai-completions model in fallbacks list

Why Manual /model Switch Works

When a user manually sends /model minimax-portal/MiniMax-M2.7:

  1. The session already exists with conversation history
  2. The /model command itself becomes a user message in the messages array
  3. messages is not empty → minimax succeeds

Impact

  • Users cannot use minimax-M2.7 (or any anthropic-messages model) as the default primary model
  • The model only works after manual /model switch in an existing session
  • This affects any provider using the anthropic-messages API format

Suggested Fix

Ensure that when constructing the initial LLM request for a new session, the user message (the first message that triggered the session) is included in the messages array before making the API call.

The issue appears to be in the session initialization flow where context.compiled produces empty messages and prompt fields.

Environment

  • OpenClaw version: 2026.4.26 (be8c246)
  • Primary model: minimax-portal/MiniMax-M2.7 (api: "anthropic-messages")
  • Fallback: xiaomi/mimo-v2.5 (api: "openai-completions")
  • Channel: Feishu group chat

extent analysis

TL;DR

Ensure the initial user message is included in the messages array when constructing the LLM request for a new session to fix the "messages must not be empty" error.

Guidance

  • Review the session initialization flow in OpenClaw to identify where the context.compiled object is being populated with empty messages and prompt fields.
  • Modify the code to include the first user message in the messages array before making the API call to the anthropic-messages model.
  • Verify that the messages array is not empty before sending the LLM request to prevent the "messages must not be empty" error.
  • Consider adding a check to handle cases where the user message is empty or blank to prevent similar issues in the future.

Example

No code snippet is provided as the issue is more related to the logic and flow of the session initialization rather than a specific code block.

Notes

The fix should be applied to the OpenClaw version 2026.4.26 (be8c246) and may need to be adapted for other versions. The issue is specific to models using the anthropic-messages API format.

Recommendation

Apply the suggested fix to ensure that the initial user message is included in the messages array when constructing the LLM request for a new session. This should resolve the "messages must not be empty" error and allow users to use minimax-M2.7 (or any anthropic-messages model) as the default primary model.

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 Bug: New session fails with anthropic-messages API models due to empty messages array [1 comments, 2 participants]