Anthropic enforces a strict alternating role contract within the messages array. Unlike other providers, you cannot send consecutive 'user' or 'assistant' messages. Every sequence must start with a user role. If your application logic requires multiple user interjections without assistant replies, you must concatenate these strings into a single content block or utilize the system prompt for persistent context.
The system parameter is physically isolated from the messages array. This isn't just a naming convention—it is a security boundary that helps Claude distinguish between developer-mandated constraints and potentially untrusted user data. When building for production, always place mission-critical behavioral rules in the system prompt to minimize the risk of 'prompt injection' where a user might attempt to override instructions within the conversation stream.
user content block must be an array of objects where each object explicitly defines its type as either "text" or "image".