# Flux Kontext Pro 图像生成/编辑

> 图像生成

调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。

## 请求地址

`POST https://api.modelverse.cn/v1/flux-kontext-pro`

## 请求体

## 响应

- **200** — Image response containing Base64 image data.
- **400** — 请求参数无效或图像生成失败。
- **default** — 错误响应。

## OpenAPI 定义

```json
{
  "openapi": "3.1.0",
  "x-language": "zh-CN",
  "info": {
    "title": "flux-kontext-pro接口文档",
    "version": "1.0.0",
    "description": "这是 ModelVerse 上 `flux-kontext-pro` 的图片接口文档，说明如何发起图片生成或编辑请求、填写参数、读取结果以及处理错误。\n接口路径包括 `POST /v1/flux-kontext-pro`。\n"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "该模型文档中使用的 ModelVerse API 端点。"
    }
  ],
  "tags": [
    {
      "name": "flux-kontext-pro",
      "description": "Image creation and contextual image editing with flux-kontext-pro."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/flux-kontext-pro": {
      "post": {
        "tags": [
          "flux-kontext-pro"
        ],
        "operationId": "createFluxKontextProImage",
        "summary": "Flux Kontext Pro 图像生成/编辑",
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FluxKontextProRequest"
              },
              "examples": {
                "textOnly": {
                  "summary": "源文档 document 仅 prompt 请求",
                  "value": {
                    "prompt": "A photograph of a red fox in an autumn forest"
                  }
                },
                "contextualEdit": {
                  "summary": "Contextual edit带input images and 固定 seed",
                  "value": {
                    "prompt": "Place the subject from the first image into the autumn forest scene",
                    "input_image": "{image_base64_string}",
                    "input_image_2": "{reference_image_base64_string}",
                    "seed": 12345,
                    "aspect_ratio": "16:9",
                    "output_format": "jpg",
                    "prompt_upsampling": true,
                    "safety_tolerance": "3"
                  }
                },
                "webhook": {
                  "summary": "带 webhook 回调字段 的请求",
                  "value": {
                    "prompt": "A clean product photo on a white background",
                    "input_image": "{product_image_base64_string}",
                    "output_format": "png",
                    "webhook_url": "https://example.com/modelverse/webhook",
                    "webhook_secret": "{webhook_secret}"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Image response containing Base64 image data.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FluxKontextProResponse"
                },
                "examples": {
                  "generatedImage": {
                    "summary": "图像生成响应",
                    "value": {
                      "createed": 1750667997,
                      "data": [
                        {
                          "b64_json": "{image_base64_string}"
                        }
                      ]
                    }
                  },
                  "editedImage": {
                    "summary": "上下文编辑响应",
                    "value": {
                      "createed": 1750668123,
                      "data": [
                        {
                          "b64_json": "{edited_image_base64_string}"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "请求参数无效或图像生成失败。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FluxKontextProErrorResponse"
                },
                "examples": {
                  "invalidRequest": {
                    "$ref": "#/components/examples/FluxKontextProError"
                  }
                }
              }
            }
          },
          "default": {
            "description": "错误响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FluxKontextProErrorResponse"
                },
                "examples": {
                  "error": {
                    "$ref": "#/components/examples/FluxKontextProError"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n"
      }
    },
    "schemas": {
      "FluxKontextProPrompt": {
        "type": "string",
        "minLength": 1,
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n",
        "examples": [
          "A photograph of a red fox in an autumn forest"
        ]
      },
      "FluxKontextProBase64Image": {
        "type": "string",
        "minLength": 1,
        "contentEncoding": "base64",
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n",
        "examples": [
          "{image_base64_string}"
        ]
      },
      "FluxKontextProSeed": {
        "type": "integer",
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n",
        "examples": [
          12345
        ]
      },
      "FluxKontextProAspectRatio": {
        "type": "string",
        "pattern": "^[1-9][0-9]*:[1-9][0-9]*$",
        "x-min-aspect-ratio": "9:21",
        "x-max-aspect-ratio": "21:9",
        "description": "图像宽高比，范围为 21:9 到 9:21。\n",
        "examples": [
          "1:1",
          "16:9",
          "9:16",
          "21:9",
          "9:21"
        ]
      },
      "FluxKontextProOutputFormat": {
        "type": "string",
        "enum": [
          "png",
          "jpg"
        ],
        "default": "png",
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n"
      },
      "FluxKontextProWebhookUrl": {
        "type": "string",
        "format": "uri",
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n",
        "examples": [
          "https://example.com/modelverse/webhook"
        ]
      },
      "FluxKontextProWebhookSecret": {
        "type": "string",
        "minLength": 1,
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n"
      },
      "FluxKontextProPromptUpsampling": {
        "type": "boolean",
        "default": false,
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n"
      },
      "FluxKontextProSafetyTolerance": {
        "type": "string",
        "enum": [
          "0",
          "1",
          "2",
          "3",
          "4",
          "5",
          "6"
        ],
        "description": "调用该模型的图片接口。请求中填写提示词、图片输入和控制参数，响应返回生成或编辑后的图片结果。\n"
      },
      "FluxKontextProRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "$ref": "#/components/schemas/FluxKontextProPrompt"
          },
          "input_image": {
            "$ref": "#/components/schemas/FluxKontextProBase64Image"
          },
          "input_image_2": {
            "$ref": "#/components/schemas/FluxKontextProBase64Image"
          },
          "input_image_3": {
            "$ref": "#/components/schemas/FluxKontextProBase64Image"
          },
          "input_image_4": {
            "$ref": "#/components/schemas/FluxKontextProBase64Image"
          },
          "seed": {
            "$ref": "#/components/schemas/FluxKontextProSeed"
          },
          "aspect_ratio": {
            "$ref": "#/components/schemas/FluxKontextProAspectRatio"
          },
          "output_format": {
            "$ref": "#/components/schemas/FluxKontextProOutputFormat"
          },
          "webhook_url": {
            "$ref": "#/components/schemas/FluxKontextProWebhookUrl"
          },
          "webhook_secret": {
            "$ref": "#/components/schemas/FluxKontextProWebhookSecret"
          },
          "prompt_upsampling": {
            "$ref": "#/components/schemas/FluxKontextProPromptUpsampling"
          },
          "safety_tolerance": {
            "$ref": "#/components/schemas/FluxKontextProSafetyTolerance"
          }
        }
      },
      "FluxKontextProResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "createed",
          "data"
        ],
        "properties": {
          "createed": {
            "type": "integer",
            "format": "int64",
            "description": "Creation timestamp. The source document spells this response field as `createed`."
          },
          "data": {
            "type": "array",
            "minItems": 1,
            "description": "Image data returned by the API.",
            "items": {
              "$ref": "#/components/schemas/FluxKontextProImageData"
            }
          }
        }
      },
      "FluxKontextProImageData": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "b64_json"
        ],
        "properties": {
          "b64_json": {
            "type": "string",
            "contentEncoding": "base64",
            "description": "Base64-encoded output image data."
          }
        }
      },
      "FluxKontextProErrorResponse": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/FluxKontextProError"
          }
        }
      },
      "FluxKontextProError": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "message": {
            "type": "string",
            "description": "错误信息。"
          },
          "type": {
            "type": "string",
            "description": "错误类型。"
          },
          "param": {
            "type": "string",
            "description": "请求 ID 或相关参数。"
          },
          "code": {
            "type": "string",
            "description": "错误码。"
          }
        }
      }
    },
    "examples": {
      "FluxKontextProError": {
        "summary": "错误响应",
        "value": {
          "error": {
            "message": "error_message",
            "type": "error_type",
            "param": "request_id",
            "code": "error_code"
          }
        }
      }
    }
  }
}
```
