✕ [API Error: Model stream ended without a finish reason.]

Gemini CLI started giving this error frequently:
✕ [API Error: Model stream ended without a finish reason.]

We’re working on something and suddenly this error pops up. It’s very annoying.

Has anyone else encountered this error frequently?

Hey there,

Ugh, that’s a really frustrating error, and you’re definitely not alone in seeing this pop up. I’ve encountered it as well, especially during long-running generations.

The error ✕ [API Error: Model stream ended without a finish reason.] is essentially the API’s way of saying the connection between your command line and Google’s servers was cut unexpectedly. Think of it like a phone call that just dropped without either person hanging up. The model was still “talking” (streaming the response), but the line went dead.

This usually points to a handful of potential causes, most often related to network stability or the nature of the request itself.

Here are the most common reasons and some troubleshooting steps that have helped me and others:

1. Intermittent Network Connection

This is the number one culprit. Even a very brief hiccup in your internet connection can be enough to terminate the stream.

  • Quick Test: When it happens, try running a continuous ping to a reliable server (like Google’s DNS) in another terminal window to see if you’re dropping packets: ping 8.8.8.8 -t (on Windows) or ping 8.8.8.8 (on macOS/Linux).

  • Solution: If you are on Wi-Fi, try switching to a wired ethernet connection if possible, as it’s generally more stable.

2. Long or Complex Prompts

If you’re asking the model to perform a very large or time-consuming task (e.g., generating a huge file, a complex piece of code, or a long narrative), the connection can time out. The server might be working hard on the response, but the connection itself might be idle for too long.

  • Solution:

    • Try breaking your prompt into smaller, more manageable chunks.

    • Be more specific in your request to help the model generate a response faster.

3. API Server Load or Transient Issues

Sometimes, the issue isn’t on your end at all. The Gemini API servers might be under heavy load, or there could be a temporary glitch causing them to drop connections. Since you mentioned this started happening frequently today (Friday, October 10, 2025), it’s worth checking if others are seeing a spike in errors.

  • Solution:

    • Check the Google Cloud Status Dashboard for any reported issues with Vertex AI or the Gemini API.

    • Give it a few minutes and simply retry the command. Often, the issue is very temporary.

4. Outdated CLI Version

An older version of the gcloud CLI or its components might have bugs or be less resilient to network issues.

  • Solution: Run an update to make sure you’re on the latest version.

    Bash

    gcloud components update
    
    

Summary of What to Try Next:

  1. Retry the command immediately. It often works the second time.

  2. Check your internet connection for stability.

  3. Break down your prompt if it’s very large or complex.

  4. Update your gcloud CLI using the command above.

If you continue to see the error consistently, it might be helpful to provide a bit more context (without sharing any private data), like the general nature of the command you’re running.

Hope this helps you get back on track without too many more interruptions!

Thank you very much for your reply.

  1. Sometimes it continues when I use the “Continue” command. Sometimes he makes the same mistake over and over again.
  2. I checked my connection during this problem and there doesn’t seem to be any problem with my connection.
  3. I get this error even in very simple prompts.
  4. When I Use This “gcloud components update” command. I got this error.
    ERROR: (gcloud.components.update) You cannot perform this action because this Google Cloud CLI installation is managed by an external package manager.
    Please consider using a separate installation of the Google Cloud CLI created through the default mechanism described at: ``https://cloud.google.com/sdk/

In addition, I get the following error:
✕ [API Error: Model stream ended with empty response text.]

Ah, that is the critical piece of information! Thank you.

The Root Cause: A Declarative (and Outdated) CLI

Your diagnosis in the original thread was spot on, but now we know the specific tool.

  1. Firebase Studio uses Nix: Your entire environment, including the gcloud CLI, is defined “declaratively” in your .idx/dev.nix file.

  2. gcloud Knows It’s Managed: The CLI is “locked” by this Nix configuration. This is why gcloud components update correctly fails and says it’s “managed by an external package manager” (that manager is Nix).

  3. The Error: The version of google-cloud-sdk specified in your Nix file is outdated and has a known bug in handling response streams. This is why you’re seeing both ...ended without a finish reason and ...ended with empty response text, even on simple prompts.

Your network is fine. The problem is a bug in an older version of the google-cloud-sdk package.


How to Fix It (The “Nix Way” in Firebase Studio)

You cannot use gcloud components update to fix this. You must update the Nix configuration file and let Firebase Studio rebuild your environment.

Here is the step-by-step solution:

  1. In your Firebase Studio workspace, find and open the environment configuration file, which is located at:

    .idx/dev.nix

  2. Inside this file, look for the line that defines the channel. It will look something like this:

    Nix

    channel = "stable-23.11";  # This might be 23.05 or another old version
    
    
  3. Update this channel to a more recent version. The simplest fix is to use the unstable channel, which will have the absolute latest bug fixes for the gcloud CLI.

    Change this:

    Nix

    channel = "stable-23.11";
    
    

    To this:

    Nix

    channel = "unstable";
    
    

    (Alternatively, you can try a newer stable channel, like "stable-25.05", but unstable is often best for getting the newest CLI tool fixes).

  4. Save the .idx/dev.nix file.

  5. As soon as you save, a notification will pop up in the bottom-right corner of Firebase Studio prompting you to “Rebuild the environment.” You must click this.

  6. Firebase Studio will re-run the Nix build, which may take a minute or two. It will download the new google-cloud-sdk package (and any other updates).

Once the environment is rebuilt, your terminal will be using the latest gcloud CLI. The gemini command streaming errors should now be resolved.

Thank you for your reply. So where can I find the newest version number and release notes? Is there a page where we can follow them?