图片生成

POST /v1beta/models/{modeName}:generateContent

MethodPOST
Path/v1beta/models/{modeName}:generateContent
Typehttp
Status1
Module2102810
Folder61214320

说明

概览

MethodPOST
Path/v1beta/models/{modeName}:generateContent
Typehttp
Status1
Module2102810
Folder61214320

参数

{
  "query": [
    {
      "name": "key",
      "required": true,
      "description": "",
      "id": "wjBaUFZqF1",
      "type": "string",
      "enable": true,
      "sampleValue": "{{YOUR_API_KEY}}"
    }
  ],
  "path": [
    {
      "id": "modeName#0",
      "name": "modeName",
      "required": 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",
      "enable": true,
      "sampleValue": "gemini-2.5-flash-image-preview"
    }
  ],
  "header": [
    {
      "name": "Content-Type",
      "required": true,
      "description": "",
      "id": "2iNJqLqBUZ",
      "type": "string",
      "enable": true,
      "sampleValue": "application/json"
    }
  ]
}

请求体

{
  "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"
    ]
  },
  "required": false,
  "mediaType": "",
  "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"
    }
  ],
  "oasExtensions": ""
}

响应

[
  {
    "id": 692086684,
    "name": "成功",
    "code": 200,
    "contentType": "json",
    "jsonSchema": {
      "type": "object",
      "properties": {}
    },
    "itemSchema": {},
    "description": "",
    "mediaType": "",
    "headers": [],
    "oasExtensions": ""
  }
]