Home / Blog / Pricing

Pricing

Gemini CLI "API Error 400: Request Contains an Invalid Argument"

Gemini CLI throws 'API Error 400: Request contains an invalid argument'? The usual causes, what to check first, and fixes, cited to issues and Google docs.

8 min read

Error text from Gemini CLI’s official GitHub repo: #29235, #29794 and #29574 (verified Oct 31, 2026, re-read Nov 1, 2026). Causes and fixes from Gemini CLI’s troubleshooting guide, Google’s Gemini API troubleshooting and Google Cloud’s API errors reference, all verified Nov 1, 2026. Every source is listed at the bottom. No affiliate links on this page (how we work).

The exact error: API error 400 Request contains an invalid argument.

This is how it shows up in Gemini CLI, pasted by a user into the project’s issue tracker:

[API Error: [{
    "error": {
      "code": 400,
      "message": "Request contains an invalid argument.",
      "errors": [
        {
          "message": "Request contains an invalid argument.",
          "domain": "global",
          "reason": "badRequest"
        }
      ],
      "status": "INVALID_ARGUMENT"
    }
  }
  ]]

Source: gemini-cli #29235, opened Sep 7, 2026 on CLI 0.58.0 (verified Oct 31, 2026). Another report, #29794, titles it API Error: 400 'INVALID_ARGUMENT' (Oct 16, 2026, CLI 0.64.0).

The one-line answer, as of Nov 1, 2026: Google’s API rejected the shape of the request, not your quota. Google Cloud’s reference says a 400 INVALID_ARGUMENT means the “Request fails API validation”, and gives “Request exceeds the model’s input token limit” as an example (verified Nov 1, 2026). Out of quota is a different code, 429; that one has its own page: Gemini CLI 429 error.

We haven’t tested this ourselves. Everything below is from Google’s docs and the Gemini CLI repo, quoted and dated.

Common causes, each with a source

The 400 is a catch-all, so the cause depends on when it appears. Here are the four patterns with a public source behind them.

1. It appears at sign-in. Gemini CLI’s troubleshooting guide lists Error: Failed to sign in. Message: Request contains an invalid argument and gives the cause: “Users with Google Workspace accounts or Google Cloud accounts associated with their Gmail accounts may not be able to activate the free tier of the Google Code Assist plan” (page last updated Jun 18, 2026; verified Nov 1, 2026). This is the only version of the message Google documents directly.

2. It appears mid-session, then on every request. That’s #29235: the error lands at the end of a response, and “After the first error message the AI answer with this error at every request, i have to close the session and resume it.” Other commenters saw it after the agent finished a set of tasks, and one says it happens “mostly on the Pro 2.5 model”. The issue is open, with no maintainer diagnosis as of Nov 1, 2026. A community commenter posted a theory about chat history not being cleaned before it’s sent; it’s unconfirmed, so treat it as a theory.

3. It appears after loading an MCP server or skill. #29794 came from a first-time user who installed a third-party reverse-engineering MCP server and skill, then got API Error: 400 'INVALID_ARGUMENT'. Also open, also undiagnosed by maintainers. What Google’s MCP docs do say: the CLI “automatically removes certain schema properties ($schema, additionalProperties) for Gemini API compatibility” and sanitizes tool names (verified Nov 1, 2026), so tool definitions do get reshaped before they reach the API.

4. It appears after reading an image. #29574 shows a 400 with "message": "Requests ending with a model turn are not supported." and "status": "INVALID_ARGUMENT" after the CLI’s ReadFile tool opened .png files. That one has a fix: pull request #29612, “enforce terminal user turn invariant and normalize request contents”, was merged on Oct 7, 2026, and the issue was closed as completed on Oct 13, 2026 (verified Nov 1, 2026).

Then there are the API-level causes Google lists for any 400: unsupported model parameters, a model name that isn’t on the supported list, or the wrong API version. Google’s troubleshooting page flags one coming change: “Gemini 4 and Gemini 3.6+ models ignore custom values for temperature, top_p, and top_k and return deprecation warning headers (and will return 400 errors in a future release)” (verified Nov 1, 2026).

What we’ve got here is failure to communicate, Cool Hand Luke style: the CLI sends something, the API says “invalid argument”, and neither tells you which argument. Google’s error says what happened but not why.

Fixes, in order

Legit fixes only, from Google’s docs and the issues above.

  1. Update Gemini CLI. Google’s documented command is npm install -g @google/gemini-cli@latest; if you run from source, pull and npm run build (troubleshooting guide, verified Nov 1, 2026). The latest release on GitHub was v0.66.0, published Oct 27, 2026. The image-reading 400 was fixed in code on Oct 7, so anyone on an older build should update first. Run /about to see your version.
  2. Start a fresh session. In #29235, once the error appeared, every following request failed until the reporter closed the session. Clearing out of a broken session is the reporter’s own workaround, not an official fix, but it’s free.
  3. Check your model and settings. Google’s API troubleshooting says to verify “that you are using a supported model listed on our models page” and that parameters are in range; for Gemini 3.6+ and Gemini 4, drop custom temperature, top_p and top_k (verified Nov 1, 2026). A typo in a model name in settings.json is worth ruling out.
  4. Trim the input. If you pasted a huge file or log, cut it down. Google Cloud’s example of a 400 is a request that “exceeds the model’s input token limit” (verified Nov 1, 2026).
  5. Disable a suspect MCP server. Gemini CLI has gemini mcp disable <name>, or /mcp disable <name> inside a session; add --session to apply it to that session only. Disabled servers “won’t connect or provide tools” (MCP docs, verified Nov 1, 2026). If the 400 goes away, you’ve found the trigger. That’s the troubleshooting guide’s general advice too: isolate the issue “by running the simplest possible version” of the operation.
  6. For the sign-in version, fix the account setup. Google’s documented options: for Google Cloud accounts, set GOOGLE_CLOUD_PROJECT to your project ID, or get a Gemini API key from Google AI Studio, “which also includes a separate free tier” (verified Nov 1, 2026). Note that personal “Login with Google” for Gemini CLI ended on June 18, 2026 (verified Oct 29, 2026); see Gemini CLI free tier limits for what’s left.

Don’t bother retrying the same request in a loop. Google’s API troubleshooting says: “Do not retry on client errors (like 400, 402, or 403) as they indicate issues like invalid API keys, depleted Prepay credits, or bad syntax” (verified Nov 1, 2026).

Still stuck? Run with --debug, or press F12 in interactive mode for the debug console (troubleshooting guide). #29574’s output also points to /settings → “Error Verbosity” set to full for complete error details. Then search the issue tracker before filing a new report.

Hi, I’m Troy McClure. You may remember this error from such sign-in screens as “Failed to sign in”. Same words, different cause, which is exactly why reading when it appears matters more than reading the error.

400 vs 403 vs 429 vs 503 at a glance

CodeMeansFirst fix
400Bad requestUpdate, trim, check
403No permissionCheck key, project
429Quota or rateWait, back off
503OverloadedRetry with backoff

From Google’s Gemini API errors page and Google Cloud API errors reference, verified Nov 1, 2026.

The short version: 400 and 403 are about what you sent or who you are, so retrying won’t help. 429 and 503 are about capacity, so waiting will.

Here’s what I’d do

Update to the latest Gemini CLI, then start a new session. If the error came back right after you added an MCP server or skill, disable it for one session and see. If it only happens at sign-in, follow Google’s account fix or move to an API key.

If Gemini CLI keeps getting in your way, compare it with others: Gemini CLI vs Claude Code and AI coding tools compared. For plan prices, see Gemini pricing, and for the Code Assist situation, Is Gemini Code Assist free?

If the error is 503 UNAVAILABLE rather than 400, see Gemini CLI 503 “The model is overloaded”.

For a 403 PERMISSION_DENIED from Gemini CLI, see the Gemini CLI 403 permission denied fix.

A 500 is a server fault, not a bad request. Gemini CLI Error 500 covers retry and session-trim fixes.

If the CLI dies with a JavaScript heap error instead of a 400, see Gemini CLI heap out of memory.

FAQ

What does “Request contains an invalid argument” mean in Gemini CLI? The Gemini API rejected the request as invalid (status INVALID_ARGUMENT, code 400), for example a bad parameter, an unsupported model or an input that’s too large.

Is Gemini CLI error 400 a quota problem? No, quota and rate limits return 429 RESOURCE_EXHAUSTED; a 400 means the request itself was rejected.

How do I update Gemini CLI? Run npm install -g @google/gemini-cli@latest, or pull and run npm run build if you use it from source.

What does “API Error: 400 ‘INVALID_ARGUMENT’” mean after adding an MCP server? Google hasn’t diagnosed that report yet; disable the server with gemini mcp disable and see if the error stops.

Why does Gemini CLI say “Requests ending with a model turn are not supported”? It was a bug after reading image files; a fix was merged on Oct 7, 2026, so update to the latest version.

Should I retry a Gemini 400 error? No, Google says not to retry 400 errors because the same request will fail again; change the request instead.

Sources

  1. gemini-cli issue #29235, “API error 400 Request contains an invalid argument.” (error JSON, repeats every request): https://github.com/google-gemini/gemini-cli/issues/29235 (verified 2026-10-31, re-read 2026-11-01)
  2. gemini-cli issue #29794, “API Error: 400 ‘INVALID_ARGUMENT’” with an MCP server and skill: https://github.com/google-gemini/gemini-cli/issues/29794 (verified 2026-10-31, re-read 2026-11-01)
  3. gemini-cli issue #29574, “Requests ending with a model turn are not supported”: https://github.com/google-gemini/gemini-cli/issues/29574 (verified 2026-10-31, re-read 2026-11-01)
  4. gemini-cli pull request #29612 (fix merged Oct 7, 2026): https://github.com/google-gemini/gemini-cli/pull/29612 (verified 2026-11-01)
  5. gemini-cli releases (v0.66.0, Oct 27, 2026): https://github.com/google-gemini/gemini-cli/releases (verified 2026-11-01)
  6. Gemini CLI troubleshooting guide (sign-in 400, update command, debug tips): https://geminicli.com/docs/resources/troubleshooting/ (verified 2026-11-01)
  7. Gemini CLI MCP server docs (schema processing, gemini mcp disable): https://geminicli.com/docs/tools/mcp-server/ (verified 2026-11-01)
  8. Gemini API troubleshooting (don’t retry 400s, model parameters, supported models): https://ai.google.dev/gemini-api/docs/troubleshooting (verified 2026-11-01)
  9. Gemini API errors (400, 403, 429, 503 codes): https://ai.google.dev/gemini-api/docs/api-errors (verified 2026-11-01)
  10. Google Cloud API errors (400 INVALID_ARGUMENT, input token limit example): https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/api-errors (verified 2026-11-01)
  11. Gemini Code Assist consumer accounts (Login with Google ended June 18, 2026): https://codeassist.google/ (verified 2026-10-29)

Related reading