原生 Gemini 接口
POST /v1beta/models/{model}:generateContent
兼容 Google 原生 generateContent 协议,鉴权改为 Authorization: Bearer。文本与图片生成都走这个端点,适合已有 Gemini 代码直接迁移。
请求体(generateContent)
| 字段 | 类型 | 必填 | 说明 | |
|---|---|---|---|---|
contents | object[] | 必填 | 对话内容,元素为 {role, parts:[{text\ | inline_data}]} |
systemInstruction | object | 可选 | 系统指令 | |
generationConfig | object | 可选 | 生成参数:temperature / maxOutputTokens / topP / topK 等 | |
safetySettings | object[] | 可选 | 安全过滤设置 | |
| 字段 | 类型 | 必填 | 说明 | |
generationConfig.responseModalities | string[] | 必填 | 响应模态。生成图片传 ["IMAGE"];如需同时返回文字用 ["TEXT","IMAGE"] | |
generationConfig.imageConfig | object | 必填 | 图片生成配置(aspectRatio + imageSize) | |
imageConfig.aspectRatio | string | 必填 | 图片比例:1:1 / 3:2 / 2:3 / 4:3 / 3:4 / 5:4 / 4:5 / 16:9 / 9:16 / 21:9 | |
imageConfig.imageSize | string | 必填 | 图片质量档:1K / 2K / 4K | |
parts[].inline_data | object | 可选 | 图生图输入图:{ mime_type, data(base64) },放进 contents[].parts |
curl "https://gsnails.xyz/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{ "role": "user", "parts": [{ "text": "a neon fox, cinematic" }] }],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": { "aspectRatio": "16:9", "imageSize": "2K" }
}
}'
支持的模型
图片生成模型见下;文本生成可用标准 Gemini 模型(如 gemini-3-pro-image-preview)。
gemini-3.1-flash-image-preview
gemini-3-pro-image-preview