# GPT Image 1 Mini 图像编辑

> 图像生成

发起图片编辑请求。通过 multipart 上传图片和可选 mask，响应返回编辑后的图片结果。

## 请求地址

`POST https://api.modelverse.cn/v1/images/edits`

## 请求体

## 响应

- **200** — 图像编辑响应。
- **400** — 无效请求参数或编辑错误。
- **default** — 错误响应。

## OpenAPI 定义

```json
{
  "openapi": "3.1.0",
  "x-language": "zh-CN",
  "info": {
    "title": "gpt-image-1-mini接口文档",
    "version": "1.0.0",
    "description": "这是 ModelVerse 上 `gpt-image-1-mini` 的图片接口文档，说明如何发起图片生成或编辑请求、填写参数、读取结果以及处理错误。\n接口路径包括 `POST /v1/images/generations`、`POST /v1/images/edits`。\n"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "该模型文档中使用的 ModelVerse API 端点。"
    }
  ],
  "tags": [
    {
      "name": "gpt-image-1-mini",
      "description": "使用 gpt-image-1-mini 进行图像生成和图像编辑。"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/images/generations": {
      "post": {
        "tags": [
          "gpt-image-1-mini"
        ],
        "operationId": "createGptImage1MiniImageGeneration",
        "summary": "GPT Image 1 Mini 图像生成",
        "description": "发起图片生成请求。请求体包含模型、提示词和可选生成参数，响应返回图片 URL 或 Base64 图像数据。\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GptImage1MiniGenerationRequest"
              },
              "examples": {
                "flower": {
                  "summary": "生成 PNG 图像",
                  "value": {
                    "model": "gpt-image-1-mini",
                    "prompt": "a beautiful flower",
                    "size": "1024x1024",
                    "quality": "high",
                    "output_format": "png",
                    "output_compression": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "图像生成响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GptImage1MiniImagesResponse"
                },
                "examples": {
                  "generatedImage": {
                    "summary": "带 token 用量的生成图像",
                    "value": {
                      "created": 1748484857,
                      "background": "opaque",
                      "output_format": "png",
                      "quality": "low",
                      "size": "1024x1024",
                      "data": [
                        {
                          "b64_json": "{image_base64_string}"
                        }
                      ],
                      "usage": {
                        "total_tokens": 280,
                        "input_tokens": 8,
                        "output_tokens": 272,
                        "input_tokens_details": {
                          "image_tokens": 0,
                          "text_tokens": 8
                        },
                        "output_tokens_details": {
                          "image_tokens": 272,
                          "text_tokens": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "无效请求参数或生成错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GptImage1MiniErrorResponse"
                },
                "examples": {
                  "documentedError": {
                    "$ref": "#/components/examples/GptImage1MiniError"
                  }
                }
              }
            }
          },
          "default": {
            "description": "错误响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GptImage1MiniErrorResponse"
                },
                "examples": {
                  "documentedError": {
                    "$ref": "#/components/examples/GptImage1MiniError"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/images/edits": {
      "post": {
        "tags": [
          "gpt-image-1-mini"
        ],
        "operationId": "createGptImage1MiniImageEdit",
        "summary": "GPT Image 1 Mini 图像编辑",
        "description": "发起图片编辑请求。通过 multipart 上传图片和可选 mask，响应返回编辑后的图片结果。\n",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/GptImage1MiniEditRequest"
              },
              "encoding": {
                "image": {
                  "contentType": "image/png"
                },
                "mask": {
                  "contentType": "image/png"
                }
              },
              "examples": {
                "editWithMask": {
                  "summary": "带可选遮罩编辑图像",
                  "value": {
                    "image": "/path/to/your/image.png",
                    "mask": "/path/to/your/mask.png",
                    "model": "gpt-image-1-mini",
                    "prompt": "Add a beach ball in the center",
                    "size": "1024x1024",
                    "n": 1,
                    "quality": "high",
                    "output_format": "png",
                    "output_compression": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "图像编辑响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GptImage1MiniImagesResponse"
                },
                "examples": {
                  "editedImage": {
                    "summary": "带 token 用量的编辑图像",
                    "value": {
                      "created": 1748484857,
                      "background": "opaque",
                      "output_format": "png",
                      "quality": "low",
                      "size": "1024x1024",
                      "data": [
                        {
                          "b64_json": "{image_base64_string}"
                        }
                      ],
                      "usage": {
                        "total_tokens": 280,
                        "input_tokens": 8,
                        "output_tokens": 272,
                        "input_tokens_details": {
                          "image_tokens": 0,
                          "text_tokens": 8
                        },
                        "output_tokens_details": {
                          "image_tokens": 272,
                          "text_tokens": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "无效请求参数或编辑错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GptImage1MiniErrorResponse"
                },
                "examples": {
                  "documentedError": {
                    "$ref": "#/components/examples/GptImage1MiniError"
                  }
                }
              }
            }
          },
          "default": {
            "description": "错误响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GptImage1MiniErrorResponse"
                },
                "examples": {
                  "documentedError": {
                    "$ref": "#/components/examples/GptImage1MiniError"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "发起图片编辑请求。通过 multipart 上传图片和可选 mask，响应返回编辑后的图片结果。\n"
      }
    },
    "schemas": {
      "GptImage1MiniModel": {
        "type": "string",
        "const": "gpt-image-1-mini",
        "description": "图像模型 ID。\n"
      },
      "GptImage1MiniPrompt": {
        "type": "string",
        "minLength": 1,
        "description": "描述要生成的图像或要应用的编辑的文本提示词。\n"
      },
      "GptImage1MiniImageCount": {
        "type": "integer",
        "minimum": 1,
        "maximum": 10,
        "default": 1,
        "description": "要生成的图像数量。文档中范围为 1 到 10。\n"
      },
      "GptImage1MiniSize": {
        "type": "string",
        "enum": [
          "1024x1024",
          "1024x1536",
          "1536x1024"
        ],
        "default": "1024x1536",
        "description": "`gpt-image-1-mini` 支持的图像分辨率。\n"
      },
      "GptImage1MiniQuality": {
        "type": "string",
        "enum": [
          "low",
          "medium",
          "high"
        ],
        "description": "图像质量。高质量可能需要更长时间。\n"
      },
      "GptImage1MiniBackground": {
        "type": "string",
        "enum": [
          "transparent",
          "opaque",
          "auto"
        ],
        "default": "auto",
        "description": "背景透明度设置。使用 `transparent` 配合 `output_format=png`。\n"
      },
      "GptImage1MiniModeration": {
        "type": "string",
        "enum": [
          "auto",
          "low"
        ],
        "default": "auto",
        "description": "内容审核级别。`low` 是文档中较宽松的审核模式。\n"
      },
      "GptImage1MiniOutputFormat": {
        "type": "string",
        "enum": [
          "png",
          "jpeg"
        ],
        "default": "png",
        "description": "输出图像格式。\n"
      },
      "GptImage1MiniOutputCompression": {
        "type": "integer",
        "minimum": 0,
        "maximum": 100,
        "description": "图像压缩强度。`0` 禁用压缩，`100` 应用最大压缩。\n"
      },
      "GptImage1MiniUser": {
        "type": "string",
        "description": "最终用户的唯一标识符。\n"
      },
      "GptImage1MiniGenerationRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "model",
          "prompt"
        ],
        "allOf": [
          {
            "$ref": "#/components/schemas/GptImage1MiniTransparentBackgroundConstraint"
          }
        ],
        "properties": {
          "model": {
            "$ref": "#/components/schemas/GptImage1MiniModel"
          },
          "prompt": {
            "$ref": "#/components/schemas/GptImage1MiniPrompt"
          },
          "n": {
            "$ref": "#/components/schemas/GptImage1MiniImageCount"
          },
          "size": {
            "$ref": "#/components/schemas/GptImage1MiniSize"
          },
          "quality": {
            "$ref": "#/components/schemas/GptImage1MiniQuality"
          },
          "background": {
            "$ref": "#/components/schemas/GptImage1MiniBackground"
          },
          "moderation": {
            "$ref": "#/components/schemas/GptImage1MiniModeration"
          },
          "output_format": {
            "$ref": "#/components/schemas/GptImage1MiniOutputFormat"
          },
          "output_compression": {
            "$ref": "#/components/schemas/GptImage1MiniOutputCompression"
          },
          "user": {
            "$ref": "#/components/schemas/GptImage1MiniUser"
          }
        }
      },
      "GptImage1MiniEditRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "image",
          "model",
          "prompt"
        ],
        "allOf": [
          {
            "$ref": "#/components/schemas/GptImage1MiniTransparentBackgroundConstraint"
          }
        ],
        "properties": {
          "image": {
            "type": "string",
            "format": "binary",
            "description": "要编辑的图像文件。"
          },
          "mask": {
            "type": "string",
            "format": "binary",
            "description": "可选的 PNG 遮罩文件。透明区域会被编辑，不透明区域会被保留。\n遮罩必须包含 alpha 通道，并且尺寸必须与 `image` 完全匹配。\n"
          },
          "model": {
            "$ref": "#/components/schemas/GptImage1MiniModel"
          },
          "prompt": {
            "$ref": "#/components/schemas/GptImage1MiniPrompt"
          },
          "n": {
            "$ref": "#/components/schemas/GptImage1MiniImageCount"
          },
          "size": {
            "$ref": "#/components/schemas/GptImage1MiniSize"
          },
          "quality": {
            "$ref": "#/components/schemas/GptImage1MiniQuality"
          },
          "background": {
            "$ref": "#/components/schemas/GptImage1MiniBackground"
          },
          "moderation": {
            "$ref": "#/components/schemas/GptImage1MiniModeration"
          },
          "output_format": {
            "$ref": "#/components/schemas/GptImage1MiniOutputFormat"
          },
          "output_compression": {
            "$ref": "#/components/schemas/GptImage1MiniOutputCompression"
          },
          "user": {
            "$ref": "#/components/schemas/GptImage1MiniUser"
          }
        }
      },
      "GptImage1MiniTransparentBackgroundConstraint": {
        "type": "object",
        "if": {
          "required": [
            "background"
          ],
          "properties": {
            "background": {
              "const": "transparent"
            }
          }
        },
        "then": {
          "properties": {
            "output_format": {
              "const": "png"
            }
          },
          "description": "当 `background=transparent` 时，必须使用 `output_format=png`。"
        }
      },
      "GptImage1MiniImagesResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "created",
          "data"
        ],
        "properties": {
          "created": {
            "type": "integer",
            "format": "int64",
            "description": "请求创建时的 Unix 时间戳（秒）。"
          },
          "background": {
            "type": "string",
            "description": "生成图像使用的背景类型。",
            "examples": [
              "opaque",
              "transparent"
            ]
          },
          "output_format": {
            "$ref": "#/components/schemas/GptImage1MiniOutputFormat"
          },
          "quality": {
            "$ref": "#/components/schemas/GptImage1MiniQuality"
          },
          "size": {
            "$ref": "#/components/schemas/GptImage1MiniSize"
          },
          "data": {
            "type": "array",
            "minItems": 1,
            "description": "生成的图像数据。文档中的响应返回 base64 图像数据。",
            "items": {
              "$ref": "#/components/schemas/GptImage1MiniImageData"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/GptImage1MiniUsage"
          }
        }
      },
      "GptImage1MiniImageData": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "b64_json"
        ],
        "properties": {
          "b64_json": {
            "type": "string",
            "description": "Base64 编码图像数据，可带 data URL 前缀。"
          }
        }
      },
      "GptImage1MiniUsage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "total_tokens": {
            "type": "integer",
            "description": "请求消耗的总 token 数。"
          },
          "input_tokens": {
            "type": "integer",
            "description": "请求消耗的总输入 token 数。"
          },
          "output_tokens": {
            "type": "integer",
            "description": "请求消耗的总输出 token 数。"
          },
          "input_tokens_details": {
            "$ref": "#/components/schemas/GptImage1MiniInputTokensDetails"
          },
          "output_tokens_details": {
            "$ref": "#/components/schemas/GptImage1MiniOutputTokensDetails"
          }
        }
      },
      "GptImage1MiniInputTokensDetails": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "text_tokens": {
            "type": "integer",
            "description": "文本提示词消耗的 token 数。"
          },
          "image_tokens": {
            "type": "integer",
            "description": "输入图像消耗的 token 数。"
          }
        }
      },
      "GptImage1MiniOutputTokensDetails": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "image_tokens": {
            "type": "integer",
            "description": "输出图像消耗的 token 数。"
          },
          "text_tokens": {
            "type": "integer",
            "description": "响应中存在的文本输出 token 数。"
          }
        }
      },
      "GptImage1MiniErrorResponse": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/GptImage1MiniError"
          }
        }
      },
      "GptImage1MiniError": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "message": {
            "type": "string",
            "description": "错误信息。"
          },
          "type": {
            "type": "string",
            "description": "错误类型。"
          },
          "param": {
            "type": "string",
            "description": "请求 ID 或相关参数。"
          },
          "code": {
            "type": "string",
            "description": "错误码。"
          }
        }
      }
    },
    "examples": {
      "GptImage1MiniError": {
        "summary": "文档中的错误响应",
        "value": {
          "error": {
            "message": "error_message",
            "type": "error_type",
            "param": "request_id",
            "code": "error_code"
          }
        }
      }
    }
  }
}
```
