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

Configuration parameters

POST
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent
Every prompt you send to the model includes parameters that control how the model generates responses. You can configure these parameters, or let the model use the default options.
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": [
      {
        "parts": [
          {
            "text": "Explain how AI works"
          }
        ]
      }
    ],
    "generationConfig": {
      "stopSequences": [
        "Title"
      ],
      "temperature": 1.0,
      "maxOutputTokens": 800,
      "topP": 0.8,
      "topK": 10
    }
  }'
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 {1}] 
required
parts
array [object {1}] 
optional
generationConfig
object 
required
stopSequences
array[string]
required
指定一组将停止生成输出的字符序列(最多 5 个)。如果指定,API 会在 stop_sequence 首次出现时停止。停止序列不会包含在响应中。
temperature
integer 
required
控制输出的随机性。使用较高的值可获得更具创造性的回答,使用较低的值可获得更具确定性的回答。值的范围为 [0.0, 2.0]。
maxOutputTokens
integer 
required
设置候选项中包含的词元数上限。
topP
number 
required
更改模型选择输出词元的方式。系统会按照概率从最高到最低的顺序选择 token,直到所选 token 的概率总和等于 topP 的值。默认的 topP 值为 0.95。
topK
integer 
required
更改模型选择输出词元的方式。如果 topK 设为 1,则表示所选 token 是模型词汇表的所有 token 中概率最高的 token;如果 topK 设为 3,则表示系统将从 3 个概率最高的 token 中选择下一个 token(通过温度确定)。系统会根据 topP 进一步过滤词元,并使用温度采样选择最终的词元。
Examples

Responses

🟢200成功
application/json
Body
object {0}
Previous
Multi-turn conversations (Streaming)
Next
Generate images using Gemini
Built with