Streaming REST
Copyright 2025 Google LLC.
Gemini API: Streaming Quickstart with REST
If you want to quickly try out the Gemini API, you can use curl commands to call the methods in the REST API.
This notebook contains curl commands you can run in Google Colab, or copy to your terminal.
To run this notebook, your API key must be stored it in a Colab Secret named GOOGLE_API_KEY. If you are running in a different environment, you can store your key in an environment variable. See Authentication to learn more.
Stream Generate Content
By default, the model returns a response after completing the entire generation process. You can achieve faster interactions by not waiting for the entire result, and instead use streaming to handle partial results.
Important: Set alt=sse in your URL parameters when running the cURL command (streamGenerateContent?alt=sse below). With sse each stream chunk is a GenerateContentResponse object with a portion of the output text in candidates[0].content.parts[0].text. Without sse it str