Skip to content

Midjourney 绘图大模型 API 文档

概念介绍

Midjourney 是一款强大的AI绘图工具,可以通过文本描述(prompt)生成高质量的图像。本API提供了与Midjourney交互的接口。

提交绘图任务接口

提交任务接口地址

POST https://www.dmxapi.cn/mj/submit/imagine

请求头

参数类型说明
AuthorizationstringBearer token认证,值为Bearer {API_KEY}
Content-Typestring必须设置为application/json

请求参数

参数类型必填说明
botTypestring固定值"MID_JOURNEY"
promptstring图像生成提示词
base64Arrayarray基础图像数组
accountFilterobject账户过滤条件
notifyHookstring回调通知地址
statestring自定义状态

示例代码

python
import json
import requests

# API配置
url = "https://www.dmxapi.cn/mj/submit/imagine"
API_KEY = "sk-********************************"  # 替换为你 DMXAPI 令牌

# 请求体
payload = json.dumps({
    "botType": "MID_JOURNEY",
    "prompt": "cat and dog",  # 提示词,描述想要生成的图像
    "base64Array": [],  # 可选的初始图像数组
	#"base64Array": [
	#	"data:image/png;base64,xxx1",
	#	"data:image/png;base64,xxx2"
	#],	
	
    "accountFilter": {  # 账户过滤条件
        "channelId": "",
        "instanceId": "",
        "modes": [],
        "remark": "",
        "remix": True,
        "remixAutoConsidered": True,
    },
    "notifyHook": "",  # 回调通知地址
    "state": "",  # 自定义状态
})

# 请求头
headers = {
    "Authorization": f"Bearer {API_KEY}",  # 认证头
    "Accept": "application/json",
    "Content-Type": "application/json",
}

# 发送请求
response = requests.request("POST", url, headers=headers, data=payload)

# 输出响应
print(response.text)

返回示例

json
{
  "code": 1,
  "description": "Submit Success",
  "properties": null,
  "result": "1755752048939155"  # 这个就是 任务ID,下一步查询会用到
}

常见状态码

状态码说明
200请求成功
401认证失败
400参数错误
500服务器错误

一个 Key 用全球大模型