high severityMistral chat completion API
HTTP 400 Bad Request with error: "Unexpected role received for serving. Expected 'User' or 'Tool' but got 'Assistant'." or "Expected last role User or Tool (or Assistant with prefix True) for serving but got assistant" when calling Mistral /v1/chat/completions endpoint.
Root cause
Mistral's chat completions API strictly enforces that the final message in the 'messages' array must have role 'user' or 'tool' (or 'assistant' only if prefix parameter is enabled/true), unlike OpenAI which allows ending with 'assistant'. This prevents invalid conversation states where the API is expected to generate after a previous assistant response without new input.
Mistral APIchat completionsrole validation400 errorlast messageprefix