Gemini API 400 Invalid Argument Error Fix
The 400 INVALID_ARGUMENT response is almost always a malformed request body — here is how to find it.
Updated August 13, 2026
HTTP 400 with INVALID_ARGUMENT means the request never reached the model. Something in the URL or body was rejected by validation. These are the causes worth checking, in order.
1. The model name
Model identifiers are exact and versioned. A name that worked last quarter may have been retired. Call the list-models endpoint and use a name from the response verbatim rather than one copied from a blog post.
2. The contents array shape
Every entry needs a role and a parts array, and every part needs exactly one populated field. An empty string part, a null, or a part containing both text and inline data will fail validation.
3. Unsupported parameters for the model
Not every generation config field is valid for every model. Sending a JSON response schema, a thinking budget, or a tool declaration to a model that does not support it produces a 400 rather than a graceful ignore.
4. Inline data encoding
Images and audio must be base64 without a data URI prefix, with the MIME type declared separately. Leaving data:image/png;base64, at the front of the string is a very common cause.
5. API key against the wrong endpoint
An AI Studio key sent to a Vertex AI endpoint, or the reverse, is rejected at validation. Confirm the base URL matches the key you are using.
The error body includes a details field naming the offending property. Log the full response body — the message alone rarely identifies the field.
Related help
Related help
Independent resource. Not affiliated with, endorsed by, or sponsored by Google.