Which Messages API conversation structure is correct?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Keep turns clean: system for instructions, then user → assistant → user… — don't mash roles or skip the human turn.
Full explanation below image
Full Explanation
Anthropic's Messages API expects system content in the system field and a messages array of user/assistant turns (with tool_result as user content when applicable). Consecutive assistants without user content and putting system only inside messages incorrectly are invalid patterns. Tool results are not the only allowed follow-ups.