跳至主要内容

圖像生成

本頁收錄 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