跳到主要内容

图像生成

本页收录 Midjourney 的图像工作流,以及 OpenAI、Gemini、阿里通义等图像生成与编辑接口。

Apifox 覆盖范围补充

  • Midjourney:简介、Imagine、Action、Blend、Modal、Describe、Shorten、FaceSwap、Upload、任务查询、Seed、Edit、Video、OpenAI 兼容文生图
  • OpenAI 图像:gpt-image-1.5dall-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"
}

请求参数

名称位置类型必选说明
bodybodyanynone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
201CreatednoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

POST 2.按钮点击(Action)接口

POST /mj/submit/action

该接口是用于点击图片下方的按钮,customId通过任务查询接口可以获取到。

Body 请求参数

{
"customId": "MJ::JOB::upsample::1::0bc41848-dc7f-42f9-893c-9c33b00ebdf3",
"taskId": "1734937261701345"
}

请求参数

名称位置类型必选说明
bodybodyanynone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
201CreatednoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

POST 3.图片融合(Blend)接口

POST /mj/submit/blend

执行Blend操作,提交融图任务。

Body 请求参数

{
"mode": "RELAX",
"base64Array": [
"data:image/png;base64,xxx1",
"data:image/png;base64,xxx2"
],
"dimensions": "SQUARE"
}

请求参数

名称位置类型必选说明
bodybodyanynone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
201CreatednoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

POST 4.窗口执行(Modal)接口

POST /mj/submit/modal

当执行其他任务,code返回21时,需要执行modal接口,传入新的提示词用来修改细节。

Body 请求参数

{
"maskBase64": "data:image/png;base64,xxx1",
"prompt": "Cat",
"taskId": "1712204995849324"
}

请求参数

名称位置类型必选说明
bodybodyanynone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
201CreatednoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

POST 6.缩短提示词(Shorten)接口

POST /mj/submit/shorten

执行shorten操作,识别在关键词中有哪些单词在生成图像时发挥关键因素,哪些单词则不太重要。

Body 请求参数

{
"mode": "RELAX",
"prompt": "Cat"
}

请求参数

名称位置类型必选说明
bodybodyanynone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
201CreatednoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

POST 8.上传(upload)接口

POST /mj/submit/upload-discord-images

上传图片到discord,可用于垫图、serf、cerf等使用

Body 请求参数

{
"mode": "RELAX",
"base64Array": [
"data:image/png;base64,xxx1"
]
}

请求参数

名称位置类型必选说明
bodybodyanynone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
201CreatednoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

GET 9.查询接口

GET /mj/task/{id}/fetch

通过任务id,查询任务信息。(可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取)

请求参数

名称位置类型必选说明
idpathstring任务ID
Content-Typeheaderstringnone
Acceptheaderstringnone
Authorizationheaderstringnone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

POST 10.批量查询接口

POST /mj/task/list-by-condition

通过任务id数组,查询任务信息。(可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取)

Body 请求参数

{
"ids": [
"1749688282741136"
]
}

请求参数

名称位置类型必选说明
Content-Typeheaderstringnone
Acceptheaderstringnone
Authorizationheaderstringnone
bodybodyanynone

返回示例

200 Response

[
null
]

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
201CreatednoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

GET 11.获取种子(Seed)接口

GET /mj/task/{id}/image-seed

获取图片的seed值,用于绘图时--seed参数使用

请求参数

名称位置类型必选说明
idpathstring任务ID
Content-Typeheaderstringnone
Acceptheaderstringnone
Authorizationheaderstringnone

返回示例

200 Response

null

返回结果

状态码状态码含义说明数据模型
200OKnoneInline
401UnauthorizednoneInline
403ForbiddennoneInline
404Not FoundnoneInline

返回数据结构

模型接口/图像(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"
}

请求参数

名称位置类型必选说明
Authorizationheaderstringnone
bodybodyobjectnone
» promptbodystring所需图像的文本描述。最大长度为 1000 个字符。
» nbodyinteger要生成的图像数。必须介于 1 和 10 之间。
» sizebodystring生成图像的大小。必须是256x256、512x512或 1024x1024之一。

返回示例

200 Response

{
"created": 0,
"data": [
{
"url": "string"
}
]
}

返回结果

状态码状态码含义说明数据模型
200OKnoneInline

返回数据结构

状态码 200

名称类型必选约束中文名说明
» createdintegertruenonenone
» data[object]truenonenone
»» urlstringtruenonenone

模型接口/图像(Images)/OpenAI格式

POST 图片变体生成

POST /images/variations

创建给定图片的变体。

官方文档:https://platform.openai.com/docs/api-reference/images/createVariation

Body 请求参数

image: ""
n: "2"
size: 1024x1024

请求参数

名称位置类型必选说明
Authorizationheaderstringnone
bodybodyobjectnone
» imagebodystring(binary)作为变体基础的图片。必须是有效的 PNG 文件,小于 4MB,且为正方形。
» nbodystring1024x1024
» sizebodystring生成图片的尺寸。dall-e-2 必须是 256x256、512x512 或 1024x1024 之一。dall-e-3 必须是 1024x1024、1792x1024 或 1024x1792 之一。

返回示例

200 Response

{
"created": 0,
"data": [
{
"url": "string"
}
]
}

返回结果

状态码状态码含义说明数据模型
200OKnoneInline

返回数据结构

状态码 200

名称类型必选约束中文名说明
» createdintegertruenonenone
» data[object]truenonenone
»» urlstringtruenonenone

模型接口/图像(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"
}
}
}

请求参数

名称位置类型必选说明
modelpathstring模型名称
keyquerystringnone
Content-Typeheaderstringnone
bodybodyobjectnone
» contentsbody[object]none
»» partsbody[object]none
»»» textbodystringnone

返回示例

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
}
}

返回结果

状态码状态码含义说明数据模型
200OKnoneInline

返回数据结构

状态码 200

名称类型必选约束中文名说明
» idstringtruenonenone
» objectstringtruenonenone
» createdintegertruenonenone
» choices[object]truenonenone
»» indexintegerfalsenonenone
»» messageobjectfalsenonenone
»»» rolestringtruenonenone
»»» contentstringtruenonenone
»» finish_reasonstringfalsenonenone
» usageobjecttruenonenone
»» prompt_tokensintegertruenonenone
»» completion_tokensintegertruenonenone
»» total_tokensintegertruenonenone

模型接口/图像(Images)/阿里通义千问

POST 通用图像编辑2.5

POST /images/edits

官方文档:https://help.aliyun.com/zh/model-studio/wan2-5-image-edit-api-reference?spm=a2c4g.11186623.help-menu-2400256.d_2_2_7.36fa95e52PaUYv&scm=20140722.H_2982258._.OR_help-T_cn~zh-V_1

Body 请求参数

image: ""
prompt: 转个圈
model: wan2.5-i2i-preview

请求参数

名称位置类型必选说明
Authorizationheaderstringnone
bodybodyobjectnone
» imagebodystring(binary)none
» promptbodystring期望生成图片的文本描述。
» modelbodystring用于图像生成的模型

返回示例

200 Response

{
"created": 0,
"data": [
{
"url": "string"
}
]
}

返回结果

状态码状态码含义说明数据模型
200OKnoneInline

返回数据结构

状态码 200

名称类型必选约束中文名说明
» createdintegertruenonenone
» data[object]truenonenone
»» urlstringtruenonenone