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

POST
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent
The Gemini SDK lets you collect multiple rounds of questions and responses into a chat. The chat format enables users to step incrementally toward answers and to get help with multipart problems. This SDK implementation of chat provides an interface to keep track of conversation history, but behind the scenes it uses the same generateContent method to create the response.
The following code example shows a basic chat implementation:
Request Request Example
Shell
JavaScript
Java
Swift
curl --location -g --request POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?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
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}
Modified at 2025-04-24 09:48:03
Previous
Streaming output
Next
Multi-turn conversations (Streaming)
Built with