原生 Gemini 格式
Endpoint
POST /v1beta/models/{modeName}:generateContent
Header 参数
| Name | Type | Required | Description | Example |
|---|---|---|---|---|
Authorization | string | No | Bearer {your_token} |
Path 参数
| Name | Type | Required | Description | Example |
|---|---|---|---|---|
modeName | string | Yes | gemini-3-pro-image-preview-1k, gemini-3-pro-image-preview-2k, gemini-3-pro-image-preview-4k, gemini-3.1-flash-image-preview-512, gemini-3.1-flash-image-preview-1k, gemini-3.1-flash-image-preview-2k, gemini-3.1-flash-image-preview-4k | 模型名称: |
请求体参数
| Field | Type | Required | Title | Description |
|---|---|---|---|---|
generationConfig.imageConfig.aspectRatio | string | Yes | 画幅比例 | 可选:1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
generationConfig.imageConfig.outputFormat | string | Yes | 输出格式 | 可选:jpeg,png |
contents | array | No | Example field | Appears in a request example; no separate field description is provided. |
generationConfig | object | No | Example field | Appears in a request example; no separate field description is provided. |
请求示例
默认
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "一直可爱的小狗"
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
]
}
}
curl -X POST "{BASE_URL}/v1beta/models/{modeName}:generateContent" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "一直可爱的小狗"
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
]
}
}'
文生图
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "[主题]的HA[风格]贴纸,具有[关键特征]和[色调]。设计应采用[线条风格]和[阴影风格]。背景必须透明。"
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
],
"imageConfig": {
"aspectRatio": "9:16",
"imageSize": "1K"
}
}
}
curl -X POST "{BASE_URL}/v1beta/models/{modeName}:generateContent" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "[主题]的HA[风格]贴纸,具有[关键特征]和[色调]。设计应采用[线条风格]和[阴影风格]。背景必须透明。"
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
],
"imageConfig": {
"aspectRatio": "9:16",
"imageSize": "1K"
}
}
}'
图片编辑
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "将这幅关于[主题]的粗略[中等]草图转换成一张[风格描述]照片。保留草图中的[特定特征],但添加[新的细节/材料]"
},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "image_base64"
}
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
],
"imageConfig": {
"aspectRatio": "9:16",
"imageSize": "1K"
}
}
}
curl -X POST "{BASE_URL}/v1beta/models/{modeName}:generateContent" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "将这幅关于[主题]的粗略[中等]草图转换成一张[风格描述]照片。保留草图中的[特定特征],但添加[新的细节/材料]"
},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "image_base64"
}
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
],
"imageConfig": {
"aspectRatio": "9:16",
"imageSize": "1K"
}
}
}'
多图生图
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "使用提供的图片,将[图片2中的元素]放置到[图片1中的元素]上。确保[图片1中的元素]的特征保持完全不变。添加的元素应[描述元素应如何整合]。"
},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "image_base64_1"
}
},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "image_base64_2"
}
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
],
"imageConfig": {
"aspectRatio": "9:16",
"imageSize": "1K"
}
}
}
curl -X POST "{BASE_URL}/v1beta/models/{modeName}:generateContent" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "使用提供的图片,将[图片2中的元素]放置到[图片1中的元素]上。确保[图片1中的元素]的特征保持完全不变。添加的元素应[描述元素应如何整合]。"
},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "image_base64_1"
}
},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "image_base64_2"
}
}
]
}
],
"generationConfig": {
"responseModalities": [
"IMAGE"
],
"imageConfig": {
"aspectRatio": "9:16",
"imageSize": "1K"
}
}
}'
响应字段
| Field | Type | Required | Title | Description |
|---|
响应示例
成功
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "image_base64"
}
}
]
},
"finishReason": "STOP",
"safetyRatings": []
}
],
"usageMetadata": {
"promptTokenCount": 0,
"candidatesTokenCount": 0,
"totalTokenCount": 0
}
}