跳转到主要内容
Endpoint: POST /projects/cognition/locations/us/publishers/google/models/{model}:generateContent 通过 Google 的 Gemini 模型生成文本或多模态内容。
大多数集成场景仍建议优先使用 Create Chat Completion。只有当你明确需要 Google 原生 generateContent 请求格式时,才使用这个端点。
import requests

url = "https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-1.5-pro-latest:generateContent"

response = requests.post(
    url,
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
        "vendor": "google"
    },
    json={
        "contents": [
            {"role": "user", "parts": [{"text": "hello gemini"}]}
        ]
    }
)
print(response.json())

参数

model
string
必填
要使用的 Gemini 模型,例如 gemini-1.5-pro-latest
contents
array
必填
传给模型的文本或多媒体 parts。
safetySettings
object
可选的安全设置,用来控制内容阈值。

图片输入

对于图片内容,请使用 inlineData 传递 base64 编码后的图像字节。
curl https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-2.5-flash:generateContent \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "vendor: google" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          { "text": "Describe this image in one sentence." },
          {
            "inlineData": {
              "mimeType": "image/jpeg",
              "data": "<BASE64_IMAGE>"
            }
          }
        ]
      }
    ]
  }'
更完整的集成方式请参考 多模态指南