图像生成
本页收录 Midjourney 的图像工作流,以及 OpenAI、Gemini、阿里通义等图像生成与编辑接口。
Apifox 覆盖范围补充
- Midjourney:简介、Imagine、Action、Blend、Modal、Describe、Shorten、FaceSwap、Upload、任务查询、Seed、Edit、Video、OpenAI 兼容文生图
- OpenAI 图像:
gpt-image-1.5、dall-e-3、edits、网页版编辑、变体生成、xAI - Google Gemini:Nano-banana2、Imagen 4、图像生成、图像编辑、Gemini 原生图像生成
- 其他供应商:豆包、阿里通义千问、Minimax、flux、flux-kontext-pro、stable-diffusion、ideogram、recraftv3
Midjourney
POST 1.文生图(Imagine)接口
POST /mj/submit/imagine
执行Imagine操作,提交绘图任务。提交任务后,获取到任务id,使用查询接口查询任务状态。
Body 请求参数
{
"mode": "RELAX",
"prompt": "Cat"
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| body | body | any | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 201 | Created | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
POST 2.按钮点击(Action)接口
POST /mj/submit/action
该接口是用于点击图片下方的按钮,customId通过任务查询接口可以获取到。
Body 请求参数
{
"customId": "MJ::JOB::upsample::1::0bc41848-dc7f-42f9-893c-9c33b00ebdf3",
"taskId": "1734937261701345"
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| body | body | any | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 201 | Created | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
POST 3.图片融合(Blend)接口
POST /mj/submit/blend
执行Blend操作,提交融图任务。
Body 请求参数
{
"mode": "RELAX",
"base64Array": [
"data:image/png;base64,xxx1",
"data:image/png;base64,xxx2"
],
"dimensions": "SQUARE"
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| body | body | any | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 201 | Created | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
POST 4.窗口执行(Modal)接口
POST /mj/submit/modal
当执行其他任务,code返回21时,需要执行modal接口,传入新的提示词用来修改细节。
Body 请求参数
{
"maskBase64": "data:image/png;base64,xxx1",
"prompt": "Cat",
"taskId": "1712204995849324"
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| body | body | any | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 201 | Created | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
POST 6.缩短提示词(Shorten)接口
POST /mj/submit/shorten
执行shorten操作,识别在关键词中有哪些单词在生成图像时发挥关键因素,哪些单词则不太重要。
Body 请求参数
{
"mode": "RELAX",
"prompt": "Cat"
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| body | body | any | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 201 | Created | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
POST 8.上传(upload)接口
POST /mj/submit/upload-discord-images
上传图片到discord,可用于垫图、serf、cerf等使用
Body 请求参数
{
"mode": "RELAX",
"base64Array": [
"data:image/png;base64,xxx1"
]
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| body | body | any | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 201 | Created | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
GET 9.查询接口
GET /mj/task/{id}/fetch
通过任务id,查询任务信息。(可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取)
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| id | path | string | 是 | 任务ID |
| Content-Type | header | string | 否 | none |
| Accept | header | string | 否 | none |
| Authorization | header | string | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
POST 10.批量查询接口
POST /mj/task/list-by-condition
通过任务id数组,查询任务信息。(可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取)
Body 请求参数
{
"ids": [
"1749688282741136"
]
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| Content-Type | header | string | 否 | none |
| Accept | header | string | 否 | none |
| Authorization | header | string | 否 | none |
| body | body | any | 否 | none |
返回示例
200 Response
[
null
]
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 201 | Created | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
GET 11.获取种子(Seed)接口
GET /mj/task/{id}/image-seed
获取图片的seed值,用于绘图时--seed参数使用
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| id | path | string | 是 | 任务ID |
| Content-Type | header | string | 否 | none |
| Accept | header | string | 否 | none |
| Authorization | header | string | 否 | none |
返回示例
200 Response
null
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
| 401 | Unauthorized | none | Inline |
| 403 | Forbidden | none | Inline |
| 404 | Not Found | none | Inline |
返回数据结构
模型接口/图像(Images)
POST flux携带参考图 / OpenAI兼容接口
POST /images/generations
仅部分模型支持 图片 参考 例如: seededit flux-kontext
Body 请求参数
{
"prompt": "https://replicate.delivery/pbxt/N55l5TWGh8mSlNzW8usReoaNhGbFwvLeZR3TX1NL4pd2Wtfv/replicate-prediction-f2d25rg6gnrma0cq257vdw2n4c.png Make this a 90s cartoon",
"n": 1,
"model": "flux-kontext-pro",
"size": "1024x1024"
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| Authorization | header | string | 否 | none |
| body | body | object | 否 | none |
| » prompt | body | string | 是 | 所需图像的文本描述。最大长度为 1000 个字符。 |
| » n | body | integer | 否 | 要生成的图像数。必须介于 1 和 10 之间。 |
| » size | body | string | 否 | 生成图像的大小。必须是256x256、512x512或 1024x1024之一。 |
返回示例
200 Response
{
"created": 0,
"data": [
{
"url": "string"
}
]
}
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
返回数据结构
状态码 200
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| » created | integer | true | none | none | |
| » data | [object] | true | none | none | |
| »» url | string | true | none | none |
模型接口/图像(Images)/OpenAI格式
POST 图片变体生成
POST /images/variations
创建给定图片的变体。
官方文档:https://platform.openai.com/docs/api-reference/images/createVariation
Body 请求参数
image: ""
n: "2"
size: 1024x1024
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| Authorization | header | string | 否 | none |
| body | body | object | 否 | none |
| » image | body | string(binary) | 是 | 作为变体基础的图片。必须是有效的 PNG 文件,小于 4MB,且为正方形。 |
| » n | body | string | 否 | 1024x1024 |
| » size | body | string | 否 | 生成图片的尺寸。dall-e-2 必须是 256x256、512x512 或 1024x1024 之一。dall-e-3 必须是 1024x1024、1792x1024 或 1024x1792 之一。 |
返回示例
200 Response
{
"created": 0,
"data": [
{
"url": "string"
}
]
}
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
返回数据结构
状态码 200
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| » created | integer | true | none | none | |
| » data | [object] | true | none | none | |
| »» url | string | true | none | none |
模型接口/图像(Images)/Google Gemini/Gemini原生格式
POST 图像生成
POST /v1beta/models/{model}:generateContent/
Body 请求参数
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "draw a cat"
}
]
}
],
"generationConfig": {
"responseModalities": [
"TEXT",
"IMAGE"
],
"imageConfig": {
"aspectRatio": "16:9",
"imageSize": "4K"
}
}
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model | path | string | 是 | 模型名称 |
| key | query | string | 是 | none |
| Content-Type | header | string | 是 | none |
| body | body | object | 否 | none |
| » contents | body | [object] | 是 | none |
| »» parts | body | [object] | 否 | none |
| »»» text | body | string | 否 | none |
返回示例
200 Response
{
"id": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
返回数据结构
状态码 200
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| » id | string | true | none | none | |
| » object | string | true | none | none | |
| » created | integer | true | none | none | |
| » choices | [object] | true | none | none | |
| »» index | integer | false | none | none | |
| »» message | object | false | none | none | |
| »»» role | string | true | none | none | |
| »»» content | string | true | none | none | |
| »» finish_reason | string | false | none | none | |
| » usage | object | true | none | none | |
| »» prompt_tokens | integer | true | none | none | |
| »» completion_tokens | integer | true | none | none | |
| »» total_tokens | integer | true | none | none |
模型接口/图像(Images)/阿里通义千问
POST 通用图像编辑2.5
POST /images/edits
Body 请求参数
image: ""
prompt: 转个圈
model: wan2.5-i2i-preview
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| Authorization | header | string | 否 | none |
| body | body | object | 否 | none |
| » image | body | string(binary) | 是 | none |
| » prompt | body | string | 是 | 期望生成图片的文本描述。 |
| » model | body | string | 否 | 用于图像生成的模型 |
返回示例
200 Response
{
"created": 0,
"data": [
{
"url": "string"
}
]
}
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | none | Inline |
返回数据结构
状态码 200
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| » created | integer | true | none | none | |
| » data | [object] | true | none | none | |
| »» url | string | true | none | none |