Solution skill
Anthropic Messages API: system is top-level, messages use user and assistant roles, tool_result needs its tool_use_id
Complete solution
Shows how to fix anthropic Messages API: system is top-level, messages use user and assistant roles, tool_result needs its tool_use_id. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Every tool\result block must carry the tool\use\id of the tool\use block it answers.
Steps
systemis a top-level request parameter (a string, or a list of content blocks when you need cache breakpoints on it). It is not a message. The API reference listssystemalongsidemessagesandtoolsat the top level of the request.messagescontains onlyuserandassistantroles. There is nosystemrole insidemessages; putting one there is rejected.- Every
tool_resultblock must carry thetool_use_idof thetool_useblock it answers. The documented user message shape is{"role": "user", "content": [{"type": "tool_result", "tool_use_id": ..., "content": ...}]}. A result without the matching id is rejected. - Assistant messages you construct yourself (for re-sending history) must reproduce the content blocks exactly as the API returned them, including thinking blocks with signatures and tool_use blocks with their ids.
max_tokensis required on every request and bounds the model's output. In manual thinking mode, keep the thinking budget belowmax_tokensso the final answer has room.- Validate the payload client-side before sending: system at top level, no system role in messages, every toolresult has a tooluseid that matches a tooluse id from the previous assistant message.
- Failure modes this prevents: the system-role-in-messages 400; orphaned tool_result blocks; re-sent assistant messages with dropped blocks that break the conversation.
When to use
You are seeing this: 1. system is a top-level request parameter (a string, or a list of content blocks when you need cache breakpoints on it). Use this skill when you run into "Anthropic Messages API: system is top-level, messages use user and assistant roles, toolresult needs its tooluse_id".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
The Messages API reference defines system as a top-level parameter and the tool-use docs define the toolresult with tooluse_id shape. Verified live at https://docs.anthropic.com/en/api/messages and https://docs.anthropic.com/en/docs/build-with-claude/tool-use.
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_mHdJ0UcTZz6z3mc1wes8SQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Anthropic Messages API: system is top-level, messages use user and assistant roles, tool_result needs its tool_use_id <span>— Vectle</span></a>