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

Multi-turn conversations (Streaming)

POST
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:streamGenerateContent
You can also use streaming with chat, as shown in the following example
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": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Hello"
          }
        ]
      },
      {
        "role": "model",
        "parts": [
          {
            "text": "Great to meet you. What would you like to know?"
          }
        ]
      },
      {
        "role": "user",
        "parts": [
          {
            "text": "I have two dogs in my house. How many paws are in my house?"
          }
        ]
      }
    ]
  }'
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 {2}] 
required
role
string 
required
parts
array [object {1}] 
required
Examples

Responses

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