Generate Content

POST /gemini/v1beta/models/{model}:generateContent — Google Gemini 原生对话接口,调用 Gemini 模型生成文本回复。

请求示例

cURLBash
curl "https://www.ulovegpt.com/gemini/v1beta/models/google/gemini-3.1-flash:generateContent" \
  -H "x-goog-api-key: <你的 API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [{"text": "解释一下什么是量子纠缠"}]
    }],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 1024,
      "topP": 0.95,
      "topK": 40
    }
  }'
PythonPython
from google import genai

client = genai.Client(
    http_options={"base_url": "www.ulovegpt.com"},
    api_key="<你的 API_KEY>"
)

response = client.models.generate_content(
    model="google/gemini-3.1-flash",
    contents="解释一下什么是量子纠缠",
    config={
        "temperature": 0.7,
        "max_output_tokens": 1024,
        "top_p": 0.95,
        "top_k": 40
    }
)

print(response.text)

请求参数

参数类型必填说明
contentsarray对话内容,包含 parts 数组
contents[].partsarray内容片段,支持 text / inline_data
systemInstructionobject系统指令
generationConfig.temperaturenumber采样温度(0-2)
generationConfig.maxOutputTokensinteger最大输出 token 数
generationConfig.topPnumber核采样参数
generationConfig.topKintegerTop-K 采样
toolsarray工具定义(Gemini 格式)

响应格式

响应示例Json
{
  "candidates": [
    {
      "content": {
        "parts": [{
          "text": "量子纠缠是一种量子力学现象,当两个或多个粒子发生相互作用后..."
        }],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 8,
    "candidatesTokenCount": 128,
    "totalTokenCount": 136
  },
  "modelVersion": "google/gemini-3.1-flash"
}

认证

Gemini 协议使用 x-goog-api-key Header 进行认证:

认证 HeaderBash
curl "https://www.ulovegpt.com/gemini/v1beta/models/google/gemini-3.1-flash:generateContent" \
  -H "x-goog-api-key: sk-of-your-api-key"