# Grok Imagine 图像编辑

> 图像生成

发起图片编辑请求。支持单张图片编辑或多张图片风格迁移。
- 单张图片编辑：使用 `image` 参数传入图片 URL
- 多张图片编辑：使用 `images` 参数传入图片 URL 数组（如风格迁移）
支持模型：`grok-imagine-image`、`grok-imagine-image-quality`

## 请求地址

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

## 请求体

## 响应

- **200** — 图像编辑响应。
- **400** — 
- **default** — 

## OpenAPI 定义

```json
{
  "openapi": "3.1.0",
  "x-language": "zh-CN",
  "info": {
    "title": "grok-imagine接口文档",
    "version": "1.0.0",
    "description": "这是 ModelVerse 上 `grok-imagine-image` 和 `grok-imagine-image-quality` 的图片接口文档，说明如何发起图片生成请求、填写参数、读取结果以及处理错误。\n接口路径包括 `POST /v1/images/generations`。\n"
  },
  "servers": [
    {
      "url": "https://api.modelverse.cn",
      "description": "ModelVerse API endpoint for Grok Imagine models."
    }
  ],
  "tags": [
    {
      "name": "GrokImagine",
      "description": "OpenAI-compatible image generation APIs for Grok Imagine models."
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/images/generations": {
      "post": {
        "tags": [
          "GrokImagine"
        ],
        "operationId": "createGrokImagineImageGeneration",
        "summary": "Grok Imagine 图像生成",
        "description": "发起图片生成请求。请求体包含模型、提示词和可选生成参数，响应返回图片 URL 列表。\n支持模型：`grok-imagine-image`、`grok-imagine-image-quality`\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GrokImagineGenerateRequest"
              },
              "examples": {
                "grokImagineImage": {
                  "summary": "使用 grok-imagine-image 生成图像",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "生成幼儿园、六一儿童节的欢乐画面",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 2
                  }
                },
                "grokImagineImageQuality": {
                  "summary": "使用 grok-imagine-image-quality 生成高质量图像",
                  "value": {
                    "model": "grok-imagine-image-quality",
                    "prompt": "生成幼儿园、六一儿童节的欢乐画面",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 2
                  }
                },
                "grokImagineImageB64Json": {
                  "summary": "使用 grok-imagine-image 生成图像并返回 Base64 格式",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "生成幼儿园、六一儿童节的欢乐画面",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 2,
                    "response_format": "b64_json"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "图像生成响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GrokImagineImageResponse"
                },
                "examples": {
                  "imageUrls": {
                    "summary": "返回图片 URL 列表",
                    "value": {
                      "created": 1782875947,
                      "data": [
                        {
                          "url": "https://xxxxx/xxxx.png"
                        },
                        {
                          "url": "https://xxxxx/xxxx.png"
                        }
                      ]
                    }
                  },
                  "imageB64Json": {
                    "summary": "返回 Base64 编码的图片数据",
                    "value": {
                      "created": 1782875947,
                      "data": [
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        },
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/images/edits": {
      "post": {
        "tags": [
          "GrokImagine"
        ],
        "operationId": "createGrokImagineImageEdit",
        "summary": "Grok Imagine 图像编辑",
        "description": "发起图片编辑请求。支持单张图片编辑或多张图片风格迁移。\n- 单张图片编辑：使用 `image` 参数传入图片 URL\n- 多张图片编辑：使用 `images` 参数传入图片 URL 数组（如风格迁移）\n支持模型：`grok-imagine-image`、`grok-imagine-image-quality`\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GrokImagineEditRequest"
              },
              "examples": {
                "singleImageEdit": {
                  "summary": "单张图片编辑",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "Render this as a pencil sketch with detailed shading",
                    "image": "https://xxxxx/xxxx.png",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 1
                  }
                },
                "multiImageEdit": {
                  "summary": "多张图片风格迁移",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "将第一张图中的风格应用到第二章图中的内容上",
                    "images": [
                      "https://xxxxx/xxxx.png",
                      "https://xxxxx/xxxx.jpg"
                    ],
                    "size": "1k",
                    "aspect_ratio": "4:3",
                    "n": 2
                  }
                },
                "singleImageEditB64Json": {
                  "summary": "单张图片编辑并返回 Base64 格式",
                  "value": {
                    "model": "grok-imagine-image",
                    "prompt": "Render this as a pencil sketch with detailed shading",
                    "image": "https://xxxxx/xxxx.png",
                    "size": "2k",
                    "aspect_ratio": "1:1",
                    "n": 1,
                    "response_format": "b64_json"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "图像编辑响应。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GrokImagineImageResponse"
                },
                "examples": {
                  "editedImageUrls": {
                    "summary": "返回编辑后的图片 URL 列表",
                    "value": {
                      "created": 1782877070,
                      "data": [
                        {
                          "url": "https://xxxxx/xxxx.jpeg"
                        },
                        {
                          "url": "https://xxxxx/xxxx.jpeg"
                        }
                      ]
                    }
                  },
                  "editedImageB64Json": {
                    "summary": "返回 Base64 编码的编辑后图片数据",
                    "value": {
                      "created": 1782877070,
                      "data": [
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        },
                        {
                          "b64_json": "/9j/4AAQSkZJRgABAQEASABIAAD...",
                          "mime_type": "image/jpeg"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key",
        "description": "API 密钥认证，格式为 `Bearer {API_KEY}`"
      }
    },
    "responses": {
      "BadRequest": {
        "description": "请求参数无效或图像生成失败。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "invalidRequest": {
                "summary": "无效请求参数",
                "value": {
                  "error": {
                    "message": "Invalid request parameters",
                    "type": "invalid_request_error",
                    "param": "model",
                    "code": "param_error"
                  }
                }
              }
            }
          }
        }
      },
      "Error": {
        "description": "错误响应。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "requestError": {
                "summary": "请求错误",
                "value": {
                  "error": {
                    "message": "error_message",
                    "type": "error_type",
                    "param": "request_id",
                    "code": "error_code"
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "GrokImagineGenerateRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "grok-imagine-image",
              "grok-imagine-image-quality"
            ],
            "description": "模型名称。支持以下两种模型：\n- `grok-imagine-image`: 标准图像生成模型\n- `grok-imagine-image-quality`: 高质量图像生成模型\n"
          },
          "prompt": {
            "type": "string",
            "description": "描述要生成图像的文本提示词。"
          },
          "n": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 1,
            "description": "要生成的图像数量。"
          },
          "size": {
            "type": "string",
            "enum": [
              "1k",
              "2k"
            ],
            "default": "1k",
            "description": "生成图像的尺寸规格。"
          },
          "aspect_ratio": {
            "type": "string",
            "enum": [
              "1:1",
              "3:4",
              "4:3",
              "9:16",
              "16:9",
              "2:3",
              "3:2",
              "9:19.5",
              "19.5:9",
              "9:20",
              "20:9",
              "1:2",
              "2:1",
              "auto"
            ],
            "default": "4:3",
            "description": "生成图像的宽高比。"
          },
          "response_format": {
            "type": "string",
            "enum": [
              "b64_json"
            ],
            "default": "",
            "description": "响应格式：\n- `b64_json`: 返回 Base64 编码的图片数据\n"
          }
        }
      },
      "GrokImagineImageResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "created",
          "data"
        ],
        "properties": {
          "created": {
            "type": "integer",
            "format": "int64",
            "description": "Unix 时间戳（秒），表示请求创建时间。"
          },
          "data": {
            "type": "array",
            "description": "生成的图像结果列表。",
            "items": {
              "$ref": "#/components/schemas/GrokImagineImageData"
            }
          }
        }
      },
      "GrokImagineImageData": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "生成图像的 URL 地址。当 `response_format` 为 `url` 时返回。"
          },
          "b64_json": {
            "type": "string",
            "description": "Base64 编码的图像数据。当 `response_format` 为 `b64_json` 时返回。"
          },
          "mime_type": {
            "type": "string",
            "description": "图像的 MIME 类型（如 `image/jpeg`、`image/png`）。当 `response_format` 为 `b64_json` 时返回。"
          }
        }
      },
      "GrokImagineEditRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "grok-imagine-image",
              "grok-imagine-image-quality"
            ],
            "description": "模型名称。支持以下两种模型：\n- `grok-imagine-image`: 标准图像生成模型\n- `grok-imagine-image-quality`: 高质量图像生成模型\n"
          },
          "prompt": {
            "type": "string",
            "description": "描述编辑操作的文本提示词。"
          },
          "image": {
            "type": "string",
            "format": "uri",
            "description": "单张图片的 URL 地址。用于单张图片编辑，与 `images` 参数互斥。"
          },
          "images": {
            "type": "array",
            "description": "多张图片的 URL 地址数组。用于多张图片风格迁移等场景，与 `image` 参数互斥。",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "n": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 1,
            "description": "要生成的图像数量。"
          },
          "size": {
            "type": "string",
            "enum": [
              "1k",
              "2k"
            ],
            "default": "1k",
            "description": "生成图像的尺寸规格。"
          },
          "aspect_ratio": {
            "type": "string",
            "enum": [
              "1:1",
              "3:4",
              "4:3",
              "9:16",
              "16:9",
              "2:3",
              "3:2",
              "9:19.5",
              "19.5:9",
              "9:20",
              "20:9",
              "1:2",
              "2:1",
              "auto"
            ],
            "default": "4:3",
            "description": "生成图像的宽高比。"
          },
          "response_format": {
            "type": "string",
            "enum": [
              "b64_json"
            ],
            "default": "",
            "description": "响应格式：\n- `b64_json`: 返回 Base64 编码的图片数据\n"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorObject"
          }
        }
      },
      "ErrorObject": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "message",
          "type"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "错误信息。"
          },
          "type": {
            "type": "string",
            "description": "错误类型。"
          },
          "param": {
            "type": [
              "string",
              "null"
            ],
            "description": "与错误相关的请求参数或请求 ID。"
          },
          "code": {
            "type": [
              "string",
              "null"
            ],
            "description": "机器可读的错误码。"
          }
        }
      }
    }
  }
}
```
