Google Gemini API
  1. Text generation
Google Gemini API
  • Get API key
  • Release notes
  • Libraries
  • Run Gemini on Google Cloud
  • Model Capabilities
    • Overview
    • Long context
    • Structured output
    • Document understanding
    • Image understanding
    • Video understanding
    • Audio understanding
    • Text generation
      • Text input
        POST
      • Image input
        POST
      • Streaming output
        POST
      • Multi-turn conversations
        POST
      • Multi-turn conversations (Streaming)
        POST
      • Configuration parameters
        POST
    • Generate images
      • Generate images using Gemini
      • Image editing with Gemini
      • Generate images using Imagen 3
    • Gemini thinking
      • Use thinking models
      • Set budget on thinking models
    • Function calling
      • Function Calling with the Gemini API
  • models
    • All Model
    • Pricing
    • Rate limits
    • Billing info
  • Safety
    • Safety settings
    • Safety guidance
  1. Text generation

Streaming output

POST
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent
By default, the model returns a response after completing the entire text generation process. You can achieve faster interactions by using streaming to return instances of GenerateContentResponse as they're generated.
Request Request Example
Shell
JavaScript
Java
Swift
curl --location -g --request POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent?alt=sse&key=' \
--header 'Content-Type: application/json' \
--data-raw '{
    "contents": [
      {
        "parts": [
          {
            "text": "Explain how AI works"
          }
        ]
      }
    ]
  }'
Response Response Example
{}

Request

Query Params
alt
string 
required
Example:
sse
key
string 
required
Example:
{{GEMINI_API_KEY}}
Header Params
Content-Type
string 
required
Example:
application/json
Body Params application/json
contents
array [object {1}] 
required
parts
array [object {1}] 
optional
Examples

Responses

🟢200成功
application/json
Body
object {0}
Previous
Image input
Next
Multi-turn conversations
Built with