1. Gemini v1beta
梧柏API使用文档
WHBAI · Google Gemini 原生
  • WHBAI · Google Gemini 原生 (v1alpha)
  • WHBAI · Google Gemini 原生
  • WHBAI · Ideogram
  • WHBAI · Ideogram V3
  • WHBAI · Midjourney
  • WHBAI · Jimeng
  • WHBAI · Kling
  • WHBAI · Luma
  • WHBAI · Luma V1
  • WHBAI · Omni 视频
  • WHBAI · Pixverse
  • WHBAI · Runway
  • WHBAI · Sora2
  • WHBAI · 统一视频 VEO
  • WHBAI · Vidu
  • WHBAI · 豆包 Volc
  • WHBAI · Suno
  • WHBAI · Playground
  • WHBAI · 账号与令牌
  • WHBAI · 阿里 Pix
  • WHBAI · 阿里百炼
  • WHBAI · 私域人像
  • WHBAI · Fal.ai
  • WHBAI · Replicate
  • WHBAI · 腾讯云 VOD
  • WHBAI · MiniMax
  • WHBAI · 支持模型列表
  • WHBAI · Grok Imagine
  • WHBAI · Seedance 2.0
  • WHBAI · TypeSafe
  • WHBAI · OpenAI 兼容
  • Gemini v1beta
    • Gemini 原生内容生成
      POST
    • 视频理解-url [原生格式] 开发中
      POST
    • 文本生成-流
      POST
    • 文本生成+思考-流
      POST
    • 图片生成
      POST
    • 图片生成 gemini-2.5-flash-image 控制宽高比
      POST
    • 图片生成 gemini-3-pro-image-preview 控制宽高比 +清晰度
      POST
    • 图片编辑
      POST
    • 谷歌联网搜索
      POST
    • TTS 文本转语音
      POST
    • 文本生成 gemini-3-pro-preview:generateContent
      POST
    • Imagen 生成图片
      POST
    • Imagen 4 开发中
      POST
    • gemini-tts文本转语音
      POST
    • 文本嵌入
      POST
    • gemini-3.1-flash-lite-image
      POST
  • 数据模型
    • PostV1betaModelsModeNameGenerateContentRequest
    • PostV1betaModelsGemini25FlashImageGenerateContentRequest
    • PostV1betaModelsGemini3ProImagePreviewGenerateContentRequest
    • PostV1betaModelsGemini20FlashExpImageGenerationGenerateContentRequest
    • PostV1betaModelsGemini25FlashPreviewTtsGenerateContentRequest
    • PostV1betaModelsImagen40UltraGenerate001PredictRequest
    • PostV1betaModelsImagen40Generate001PredictRequest
    • PostV1betaModelsGemini25ProPreviewTtsGenerateContentRequest
    • PostV1betaModelsGeminiEmbedding001EmbedContentRequest
    • Gemini 3.1 Flash-Lite Image generateContent Request
    • PostV1betaModelsGemini31FlashLiteImageGenerateContentResponse
    • NewApiError
  1. Gemini v1beta

图片生成

POST
/v1beta/models/{modeName}:generateContent
官方文档:https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn

网站中的模型与调用示例#

图片生成#

官方文档:https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn

请求参数#

{
  "contentType": "application/json",
  "properties": {
    "contents": {
      "items": {
        "properties": {
          "parts": {
            "items": {
              "properties": {
                "inline_data": {
                  "description": "图片内嵌数据",
                  "properties": {
                    "data": {
                      "description": "图片 base64 追多支持传入 14 张图片",
                      "type": "string",
                      "x-i18n": {
                        "en-US": {
                          "description": "Image base64 supports incoming 14 images."
                        }
                      }
                    },
                    "mime_type": {
                      "description": "图片MIME类型",
                      "type": "string",
                      "x-i18n": {
                        "en-US": {
                          "description": "Image MIME type"
                        }
                      }
                    }
                  },
                  "required": [
                    "mime_type",
                    "data"
                  ],
                  "type": "object",
                  "x-i18n": {
                    "en-US": {
                      "description": "Image embedded data"
                    }
                  }
                },
                "text": {
                  "description": "提示词",
                  "type": "string",
                  "x-i18n": {
                    "en-US": {
                      "description": "Prompt"
                    }
                  }
                }
              },
              "required": [
                "text"
              ],
              "type": "object"
            },
            "type": "array"
          }
        },
        "required": [
          "parts"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "generationConfig": {
      "description": "生成配置",
      "properties": {
        "imageConfig": {
          "description": "图片配置",
          "properties": {
            "aspectRatio": {
              "description": "宽高比:\n1:1、2:3、3:2、3:4、4:3、4:5、5:4、9:16、16:9、21:9 支持所有模型\n1:4、1:8、4:1、8:1  这几个仅支持Gemini 3.1模型",
              "type": "string",
              "x-i18n": {
                "en-US": {
                  "description": "Aspect ratio:\n1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 support all models\n1:4, 1:8, 4:1, and 8:1 only support Gemini 3.1 models."
                }
              }
            },
            "imageSize": {
              "description": "分辨率:\n0.5K、1K、2K、4K\n默认值:1K\n注意:Gemini 2.5只支持1K,0.5K仅支持Gemini 3.1模型,值须填“512”",
              "type": "string",
              "x-i18n": {
                "en-US": {
                  "description": "Resolution:\n0.5K, 1K, 2K, 4K\nDefault: 1K\nNote: Gemini 2.5 only supports 1K, 0.5K only supports Gemini 3.1 model, the value must be filled in \"512\""
                }
              }
            }
          },
          "type": "object",
          "x-i18n": {
            "en-US": {
              "description": "Picture configuration"
            }
          }
        },
        "responseModalities": {
          "description": "响应模式:\nText、Image\n默认:[\"Text\", \"Image\"]",
          "items": {
            "type": "string"
          },
          "type": "array",
          "x-i18n": {
            "en-US": {
              "description": "Response mode:\nText, Image\nDefault: [\"Text\", \"Image\"]"
            }
          }
        }
      },
      "type": "object",
      "x-i18n": {
        "en-US": {
          "description": "Generate configuration"
        }
      }
    },
    "response_format": {
      "description": "填url返回url,不填默认base64",
      "type": "string",
      "x-i18n": {
        "en-US": {
          "description": "Fill in the url and return the url, if not fill in the default base64"
        }
      }
    }
  },
  "required": [
    "contents"
  ]
}

请求示例 · 默认#

{
  "contents": [
    {
      "parts": [
        {
          "text": "Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ]
  },
  "response_format": "url"
}

请求示例 · 文生图#

{
  "contents": [
    {
      "parts": [
        {
          "text": "HA [style] sticker of a [subject], featuring [key characteristics] and a [color palette]. The design should have [line style] and [shading style]. The background must be transparent."
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "imageConfig": {
      "aspectRatio": "9:16",
      "imageSize": "1K"
    },
    "responseModalities": [
      "IMAGE"
    ]
  }
}

请求示例 · 图生图(图片编辑)#

{
  "contents": [
    {
      "parts": [
        {
          "text": "Turn this rough [medium] sketch of a [subject] into a [style description] photo. Keep the [specific features] from the sketch but add [new details/materials]."
        },
        {
          "inline_data": {
            "data": "image_base64",
            "mime_type": "image/jpeg"
          }
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "imageConfig": {
      "aspectRatio": "9:16",
      "imageSize": "1K"
    },
    "responseModalities": [
      "IMAGE"
    ]
  }
}

请求示例 · 多图生图#

{
  "contents": [
    {
      "parts": [
        {
          "text": "Using the provided images, place [element from image 2] onto [element from image 1]. Ensure that the features of [element from image 1] remain completely unchanged. The added element should [description of how the element should integrate]."
        },
        {
          "inline_data": {
            "data": "image_base64_1",
            "mime_type": "image/jpeg"
          }
        },
        {
          "inline_data": {
            "data": "image_base64_2",
            "mime_type": "image/jpeg"
          }
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "imageConfig": {
      "aspectRatio": "9:16",
      "imageSize": "1K"
    },
    "responseModalities": [
      "IMAGE"
    ]
  }
}

请求参数

Authorization
Bearer Token
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
or
Path 参数

Query 参数

Header 参数

Body 参数application/json

示例
{
    "contents": [
        {
            "role": "user",
            "parts": [
                {
                    "text": "Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
                }
            ]
        }
    ],
    "generationConfig": {
        "responseModalities": [
            "IMAGE"
        ]
    }
}

请求示例代码

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
cURL
curl --location --globoff '/v1beta/models/gemini-2.5-flash-image-preview:generateContent?key={{YOUR_API_KEY}}' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
    "contents": [
        {
            "role": "user",
            "parts": [
                {
                    "text": "Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
                }
            ]
        }
    ],
    "generationConfig": {
        "responseModalities": [
            "IMAGE"
        ]
    }
}'

返回响应

🟢200成功
application/json
Bodyapplication/json

示例
{
    "id": "resp_example",
    "object": "response",
    "status": "completed"
}
🟠400请求有误
🟠401没有权限
修改于 2026-10-24 18:33:06
上一页
文本生成+思考-流
下一页
图片生成 gemini-2.5-flash-image 控制宽高比
Built with