Midjourney 绘图大模型 API 文档
概念介绍
Midjourney 是一款强大的AI绘图工具,可以通过文本描述(prompt)生成高质量的图像。本API提供了与Midjourney交互的接口。
提交绘图任务接口
提交任务接口地址
POST https://www.dmxapi.cn/mj/submit/imagine
请求头
参数 | 类型 | 说明 |
---|---|---|
Authorization | string | Bearer token认证,值为Bearer {API_KEY} |
Content-Type | string | 必须设置为application/json |
请求参数
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
botType | string | 是 | 固定值"MID_JOURNEY" |
prompt | string | 是 | 图像生成提示词 |
base64Array | array | 否 | 基础图像数组 |
accountFilter | object | 否 | 账户过滤条件 |
notifyHook | string | 否 | 回调通知地址 |
state | string | 否 | 自定义状态 |
示例代码
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 | 服务器错误 |