官方文档:https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn
POST
/v1beta/models/{modeName}:generateContent图片生成
API Key application/json
请求示例
curl -X POST https://top.qingyuntop.ai/v1beta/models/{modeName}:generateContent \
-H "Authorization: Bearer ${QINGYUN_TOP_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"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"
]
}
}'请求参数
| 参数 | 位置 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|---|
modeName | Path | string | 是 | 模型名称: gemini-2.5-flash-image gemini-2.5-flash-image-preview gemini-3-pro-image-preview gemini-3.1-flash-image-preview | gemini-2.5-flash-image-preview |
key | Query | string | 是 | - | {{YOUR_API_KEY}} |
Content-Type | Header | string | 是 | - | application/json |
contents | JSON body | array<object> | 是 | - | - |
contents[].parts | JSON body | array<object> | 是 | - | - |
contents[].parts[].text | JSON body | string | 是 | 提示词 | - |
contents[].parts[].inline_data | JSON body | object | 否 | 图片内嵌数据 | - |
contents[].parts[].inline_data.mime_type | JSON body | string | 是 | 图片MIME类型 | - |
contents[].parts[].inline_data.data | JSON body | string | 是 | 图片 base64 追多支持传入 14 张图片 | - |
generationConfig | JSON body | object | 否 | 生成配置 | - |
generationConfig.responseModalities | JSON body | array<string> | 否 | 响应模式: Text、Image 默认:["Text", "Image"] | - |
generationConfig.imageConfig | JSON body | object | 否 | 图片配置 | - |
generationConfig.imageConfig.aspectRatio | JSON body | string | 否 | 宽高比: 1:1、2:3、3:2、3:4、4:3、4:5、5:4、9:16、16:9、21:9 支持所有模型 1:4、1:8、4:1、8:1 这几个仅支持Gemini 3.1模型 | - |
generationConfig.imageConfig.imageSize | JSON body | string | 否 | 分辨率: 0.5K、1K、2K、4K 默认值:1K 注意:Gemini 2.5只支持1K,0.5K仅支持Gemini 3.1模型,值须填“512” | - |
返回响应 (200)
此部分没有定义参数。
来源原始接口定义(用于追溯)
以下内容来自 Apifox 快照,可能包含兼容层字段或旧示例;公开调用请以本页的协议说明和当前模型列表为准。
{
"id": 497673447,
"name": "图片生成",
"type": "http",
"serverId": "",
"preProcessors": [],
"postProcessors": [],
"inheritPreProcessors": {},
"inheritPostProcessors": {},
"description": "官方文档:https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn",
"operationId": "",
"sourceUrl": "",
"method": "post",
"path": "/v1beta/models/{modeName}:generateContent",
"tags": [],
"status": 1,
"requestBody": {
"type": "application/json",
"parameters": [],
"jsonSchema": {
"type": "object",
"properties": {
"contents": {
"type": "array",
"items": {
"type": "object",
"properties": {
"parts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "提示词"
},
"inline_data": {
"type": "object",
"properties": {
"mime_type": {
"type": "string",
"description": "图片MIME类型"
},
"data": {
"type": "string",
"description": "图片 base64 追多支持传入 14 张图片"
}
},
"x-apifox-orders": [
"mime_type",
"data"
],
"description": "图片内嵌数据",
"required": [
"mime_type",
"data"
]
}
},
"x-apifox-orders": [
"text",
"inline_data"
],
"required": [
"text"
]
}
}
},
"x-apifox-orders": [
"parts"
],
"required": [
"parts"
]
}
},
"generationConfig": {
"type": "object",
"properties": {
"responseModalities": {
"type": "array",
"items": {
"type": "string"
},
"description": "响应模式:\nText、Image\n默认:[\"Text\", \"Image\"]"
},
"imageConfig": {
"type": "object",
"properties": {
"aspectRatio": {
"type": "string",
"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模型"
},
"imageSize": {
"type": "string",
"description": "分辨率:\n0.5K、1K、2K、4K\n默认值:1K\n注意:Gemini 2.5只支持1K,0.5K仅支持Gemini 3.1模型,值须填“512”"
}
},
"x-apifox-orders": [
"aspectRatio",
"imageSize"
],
"description": "图片配置"
}
},
"x-apifox-orders": [
"responseModalities",
"imageConfig"
],
"description": "生成配置"
}
},
"required": [
"contents"
],
"x-apifox-orders": [
"contents",
"generationConfig"
]
},
"examples": [
{
"mediaType": "application/json",
"value": "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"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?\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"responseModalities\": [\n \"IMAGE\"\n ]\n }\n}",
"name": "默认"
},
{
"name": "文生图",
"value": "{\r\n \"contents\": [\r\n {\r\n \"role\": \"user\",\r\n \"parts\": [\r\n {\r\n \"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.\"\r\n }\r\n ]\r\n }\r\n ],\r\n \"generationConfig\": {\r\n \"responseModalities\": [\r\n \"IMAGE\"\r\n ],\r\n \"imageConfig\": {\r\n \"aspectRatio\": \"9:16\",\r\n \"imageSize\": \"1K\"\r\n }\r\n }\r\n}",
"mediaType": "application/json"
},
{
"name": "图生图(图片编辑)",
"value": "{\r\n \"contents\": [\r\n {\r\n \"role\": \"user\",\r\n \"parts\": [\r\n {\r\n \"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].\"\r\n },\r\n {\r\n \"inline_data\": {\r\n \"mime_type\": \"image/jpeg\",\r\n \"data\": \"image_base64\"\r\n }\r\n }\r\n ]\r\n }\r\n ],\r\n \"generationConfig\": {\r\n \"responseModalities\": [\r\n \"IMAGE\"\r\n ],\r\n \"imageConfig\": {\r\n \"aspectRatio\": \"9:16\",\r\n \"imageSize\": \"1K\"\r\n }\r\n }\r\n}",
"mediaType": "application/json"
},
{
"name": "多图生图",
"value": "{\r\n \"contents\": [\r\n {\r\n \"role\": \"user\",\r\n \"parts\": [\r\n {\r\n \"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].\"\r\n },\r\n {\r\n \"inline_data\": {\r\n \"mime_type\": \"image/jpeg\",\r\n \"data\": \"image_base64_1\"\r\n }\r\n },\r\n {\r\n \"inline_data\": {\r\n \"mime_type\": \"image/jpeg\",\r\n \"data\": \"image_base64_2\"\r\n }\r\n }\r\n ]\r\n }\r\n ],\r\n \"generationConfig\": {\r\n \"responseModalities\": [\r\n \"IMAGE\"\r\n ],\r\n \"imageConfig\": {\r\n \"aspectRatio\": \"9:16\",\r\n \"imageSize\": \"1K\"\r\n }\r\n }\r\n}",
"mediaType": "application/json"
}
],
"mediaType": "",
"oasExtensions": "",
"required": false,
"additionalContentTypes": []
},
"parameters": {
"path": [
{
"id": "modeName#0",
"name": "modeName",
"required": true,
"enable": true,
"description": "模型名称:\ngemini-2.5-flash-image\ngemini-2.5-flash-image-preview\ngemini-3-pro-image-preview\ngemini-3.1-flash-image-preview",
"type": "string",
"sampleValue": "gemini-2.5-flash-image-preview"
}
],
"query": [
{
"id": "wjBaUFZqF1",
"name": "key",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "{{YOUR_API_KEY}}"
}
],
"cookie": [],
"header": [
{
"id": "2iNJqLqBUZ",
"name": "Content-Type",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "application/json"
}
]
},
"commonParameters": {
"query": [],
"body": [],
"cookie": [],
"header": []
},
"auth": {},
"responses": [
{
"id": 141600775,
"name": "成功",
"code": 200,
"contentType": "json",
"jsonSchema": {
"type": "object",
"properties": {},
"x-apifox-orders": []
},
"itemSchema": {},
"description": "",
"mediaType": "",
"headers": [],
"oasExtensions": ""
}
],
"responseExamples": [],
"codeSamples": [],
"projectId": 8662722,
"moduleId": 8310462,
"folderId": 92749360,
"ordering": 18,
"responsibleId": 0,
"commonResponseStatus": {},
"advancedSettings": {
"disabledSystemHeaders": {}
},
"customApiFields": {},
"oasExtensions": "",
"mockScript": {},
"createdAt": "2026-08-05T14:40:23.000Z",
"updatedAt": "2026-08-06T12:15:55.000Z",
"creatorId": 2863449,
"editorId": 2863449,
"creatorUserId": 2863449,
"editorUserId": 2863449,
"responseChildren": [],
"visibility": "INHERITED",
"securityScheme": {},
"callbacks": ""
}