Gemini INVALID_ARGUMENT: meaning, cause, and fix

This 400 means the request failed validation. Common causes are a wrong field, a missing value, an incorrect type, or a feature unavailable in the API version being called.

By the benchr team · · Verified against Google's Gemini API troubleshooting docs, June 12, 2026

Google GeminiHTTP 400severity: mediumrequest format

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.

Frequently asked

The same code works in one project and 400s in another. Why?

The two projects are almost certainly calling different API versions, or one depends on a feature that only exists on v1beta. Print the full request URL from both environments and compare the version segment before touching the payload.

Which API version should I call?

The one whose documentation describes the feature you need, pinned explicitly in the URL. Letting an SDK default pick for you is how the mismatch sneaks in.

Is INVALID_ARGUMENT ever a server-side problem?

Rarely. Treat it as a client problem until a minimal request fails too. Server trouble tends to surface as 500 INTERNAL or 503 UNAVAILABLE, and oversized input context is the usual 500 trigger.

Changelog

  • — Published. Malformed-body semantics, version-mismatch cause, and error envelope verified against Google's Gemini API troubleshooting guide.

Sources

  • Gemini API troubleshooting: ai.google.dev/gemini-api/docs/troubleshooting (verified June 12, 2026)
  • benchr api-errors.json (structured entry for this error)