Request schema or API-version mismatch
Two failure families share this status. The first is the boring one: a typo in a field name, a required field left out, a string where a number belongs. You'll find these by reading your payload against the reference docs, slowly, the way you'd proofread a contract.
The request can also be valid for a different API version. Google may expose a capability in v1beta before v1, so copied examples and an unpinned default can produce a field the selected endpoint does not recognize. Check the version in both the documentation and the actual request URL.
The response
A representative body, in the standard Google envelope where the numeric code repeats the HTTP status and status holds the gRPC name:
{
"error": {
"code": 400,
"message": "The request body is malformed.",
"status": "INVALID_ARGUMENT"
}
}
Exact wording differs by failure, and the message rarely names the guilty field. That silence is why the rebuild method below beats staring at logs.
Rebuild from a minimal request
Prove the plumbing first. The smallest valid generateContent call puts the model in the URL path and sends one contents entry:
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{ "parts": [ { "text": "Say hello." } ] }
]
}'
If this passes, your schema drifted somewhere above it: add your real fields back one at a time and the 400 will reappear on the exact addition that breaks. If even the minimal call fails, suspect the URL before the body — the model name and the version segment cause more of these than any payload does.
Pin your versions
Three practices reduce this error. Put the API version in the URL explicitly and treat it as configuration so each environment calls the intended endpoint. Validate payloads against a schema before sending; a JSON Schema check in CI can catch changed or misspelled fields before deployment.
When moving between model lines, read the release notes instead of assuming the request shape carried over. Fields can appear, change name, or use a different type. If a switch to Gemini 3.1 Pro surfaced the error, the tracker shows other changes recorded around that model.