400 Error with @google/gemini-cli on Windows when connecting to API

Hello,

I am experiencing a persistent issue with the @google/gemini-cli tool on Windows. While the CLI installs correctly and local commands like --help work, any command that attempts to connect to the Gemini API fails with a 400 error.

Environment:

  • Operating System: Windows

Steps to Reproduce:

  1. Installed @google/gemini-cli locally in a dedicated project folder using npm install @google/gemini-cli.

  2. Configured the CLI with a valid Gemini API key and model name.

Expected Behavior: The CLI should be able to connect to the Gemini API and return a response. For example, npx gemini "hello world" should generate text.

Actual Behavior: The command fails with the following error:

Error when talking to Gemini API Full report available at: C:\Users\...\AppData\Local\Temp\gemini-client-error-....json

The error log points to a 400 Bad Request with the message: GenerateContentRequest.model: unexpected model name format.

Troubleshooting Steps Taken: We have tried the following troubleshooting steps without success:

  1. Global vs. Local Installation: Initially, the CLI was installed globally. It was then completely uninstalled (including clearing the npm cache) and reinstalled locally in a dedicated folder. The issue persists in both cases.

  2. API Key Configuration:

    • Set the GEMINI_API_KEY environment variable.

    • Created a .gemini/settings.json file in the project directory with the API key and model name.

  3. Model Configuration:

    • Set the GEMINI_MODEL environment variable.

    • Specified the model in the .gemini/settings.json file.

    • Tried different model names, including gemini-pro and gemini-1.5-flash.

  4. Verification:

    • The npx gemini --help command works correctly.

    • The issue only occurs with commands that require API interaction.

    • The API key has been verified to be correct and active.

Despite these efforts, the issue remains unresolved. It seems there might be a problem with how the CLI handles authentication or API requests on Windows.

Any help or guidance you could provide would be greatly appreciated.

Thank you.

Hello!
Welcome to the forum.

I have tested this on my end and it is working as expected. I would suggest adding the prefix when using the model instead of just the name. Also, please check for unnecessary spaces or quotes in your Windows environment variables.

You might also try using a different CLI version to see if that helps. If the issue persists, we recommend raising it directly on the Gemini CLI GitHub page for a more accurate and prompt response.

Thanks

1 Like