微信扫码
添加专属顾问
 
                        我要投稿
“ 先说好,midjourney本身是没有公开的api接口的,所以今天说的是一个叫mazeguru平台接入了midjourney,然后从mazeguru平台平台的api做成dify的自定义工具,实现将midjourney v6接入到dify中调用。”
https://maze.guru/
我们都知道,在github有midjourney的套壳项目,其本质还是用你的midjourney账户的token来抓数据的,这种行为对你的midjourney账户是不安全的,并且很不稳定,搞不好你的账户就嘎了。mazeguru这个平台就好用一些,因为它集成度已经很高了。
本次分享主要分两个方面:
dify自定义工具源码分享
使用细节
01
—
dify自定义工具源码分享
{"openapi": "3.1.0","info": {"title": "Mazeguru","description": "提供文生图和图生图功能,以及查询生成结果的API。","version": "1.0.0"},"tags": [{"name": "Image Generation","description": "文生图相关操作"},{"name": "Image-to-Image Generation","description": "图生图相关操作"},{"name": "Result Query","description": "查询生成结果"}],"paths": {"/api/v1/txt2img": {"post": {"summary": "生成图像","operationId": "文生图","tags": ["Image Generation"],"parameters": [{"name": "Authorization","in": "header","required": true,"description": "这里填写的是mazeguru平台的App Key。","schema": {"type": "string"}}],"requestBody": {"content": {"application/json": {"schema": {"type": "object","properties": {"num": {"type": "integer","description": "生成图像数量,默认为1","default": 1},"mj_stylize": {"type": "integer","description": "仅选择MJ型号生效,如果你确定使用midjourney,这里必须填写:100.如果填写的不是100,表示不调用midjourney模型。","default": 100},"seed": {"type": "string","description": "随机种子,这里建议填写不超过8位数的正整数。这个就不谈了,大家都懂。"},"art_genre": {"type": "string","description": "艺术风格,当你使用midjourney任何模型的时候,这里不填即可。当你使用非midjourney模型时,这里可以填,具体能填什么,看我公众号文章分享【公众号:提示日记】","example": "animal"},"width": {"type": "integer","description": "图像宽度,与高度参数搭配使用的。宽高取值只能是如下几个:1024x1024 、 768x1536 、 928x1232 、 1232x928 、 1456x816 、 816x1456","default": 1024},"height": {"type": "integer","description": "图像高度,与宽度参数搭配使用的。宽高取值只能是如下几个:1024x1024 、 768x1536 、 928x1232 、 1232x928 、 1456x816 、 816x1456","default": 1024},"style_id": {"type": "integer","description": "样式ID。请注意,这里不能乱填,如果你使用midjourney的模型,这里只有4个参数可以填写,任填一个:153 、 154 、20003 、 20006。【153对应MJv5】【154对应Niji】【20003对应MJv6】【20006对应Nijiv6】","default": 20003},"prompt": {"type": "string","description": "图像生成提示词。最大不能超过1000个单词。"}},"required": ["prompt"]}}}},"responses": {"200": {"description": "成功生成任务ID","content": {"application/json": {"schema": {"type": "object","properties": {"code": { "type": "string" },"data": {"type": "object","properties": {"jobs": {"type": "array","items": { "type": "string" }}}},"msg": { "type": "string" }}}}}}}}},"/api/v1/img2img": {"post": {"summary": "图生图生成图像","operationId": "图生图","tags": ["Image-to-Image Generation"],"parameters": [{"name": "Authorization","in": "header","required": true,"description": "这里填写的是mazeguru平台的App Key。","schema": {"type": "string"}}],"requestBody": {"content": {"application/json": {"schema": {"type": "object","properties": {"num": {"type": "integer","description": "生成图像数量","default": 1},"mj_stylize": {"type": "integer","description": "仅选择MJ型号生效,如果你确定使用midjourney,这里必须填写:100.如果填写的不是100,表示不调用midjourney模型。","default": 100},"style_id": {"type": "integer","description": "样式ID。请注意,这里不能乱填,如果你使用midjourney的模型,这里只有4个参数可以填写,任填一个:153 、 154 、20003 、 20006。【153对应MJv5】【154对应Niji】【20003对应MJv6】【20006对应Nijiv6】","default": 20003},"prompt": {"type": "string","description": "图像生成提示词。最大不能超过1000个单词。"},"width": {"type": "integer","description": "图像宽度,与高度参数搭配使用的。宽高取值只能是如下几个:1024x1024 、 768x1536 、 928x1232 、 1232x928 、 1456x816 、 816x1456","default": 1024},"height": {"type": "integer","description": "图像高度,与宽度参数搭配使用的。宽高取值只能是如下几个:1024x1024 、 768x1536 、 928x1232 、 1232x928 、 1456x816 、 816x1456","default": 1024},"art_genre": {"type": "string","description": "艺术风格,当你使用midjourney任何模型的时候,这里不填即可。当你使用非midjourney模型时,这里可以填,具体能填什么,看我公众号文章分享【公众号:提示日记】","example": "写真"},"seed": {"type": "string","description": "随机种子,这里建议填写不超过8位数的正整数。这个就不谈了,大家都懂。"},"init_image_url": {"type": "string","description": "种子图像URL,请注意填写完整的URL,并且确保mazeguru能访问并下载你的种子图像。"},"init_image_similarity": {"type": "integer","description": "与种子图像的相似度,值0-100的整数,数值越大相似度越高","default": 75}},"required": ["prompt", "init_image_url"]}}}},"responses": {"200": {"description": "成功生成任务ID","content": {"application/json": {"schema": {"type": "object","properties": {"code": { "type": "string" },"data": {"type": "object","properties": {"jobs": {"type": "array","items": { "type": "string" }}}},"msg": { "type": "string" }}}}}}}}},"/api/v1/generate-result": {"post": {"summary": "查询生成结果","operationId": "查询结果","tags": ["Result Query"],"parameters": [{"name": "Authorization","in": "header","required": true,"description": "这里填写的是mazeguru平台的App Key。","schema": {"type": "string"}}],"requestBody": {"content": {"application/json": {"schema": {"type": "object","properties": {"jobs": {"type": "array","items": { "type": "string" },"description": "任务ID列表"}},"required": ["jobs"]}}}},"responses": {"200": {"description": "成功查询结果","content": {"application/json": {"schema": { "type": "object","properties": {"code": { "type": "string" },"data": {"type": "array","items": {"type": "object","properties": {"job": { "type": "string" },"status": { "type": "integer" },"picture_url": { "type": "string" },"complete_percent": { "type": "string" },"audio_info": { "type": "string" }}}}}}}}}}}}},"components": {},"servers": [{"url": "https://open.maze.guru"}]}添加好了之后,就如上图所示。从mazeguru接入了3个工具,分别是文生图、图生图、查询结果。这三个工具都能在dify的工作流中使用。
请注意,无论是文生图还是图生图工具,后面都需要先提取任务ID,也就是返回数据中的jobid。然后将jobid传给查询结果的工具获取生成的图片URL。
为了方便大家理解不同工具的返回结果,下面我将各个工具的返回数据示例写出来,大家自行参考。
文生图:
{"code": "200","data": {"jobs": ["C5B5FE8DBF3679D9049342C130341BD9"]},"msg": ""}图生图:
{"code": "200","data": {"jobs": ["C5B5FE8DBF3679D9049342C130341BD9"]},"msg": ""}由此可见,文生图和图生图的返回结构是一样的,你需要提取jobs列表中的参数即可。请注意,如果你生成的是多张图,jobs列表中会出现多个参数哦。如果你是新手,我个人建议你生成图片的数量设置为1,这样方便你提取参数。如果你是编程老手,我个人强烈推荐大家使用dify v0.7.1以上的版本,搭配会话变量这个功能临时存储,然后分别查询结果,这样可以锻炼你使用会话变量这个功能的习惯。说实话,我认为这个功能真的很不错。
查询结果:
{"code": "200","data": [{"job": "1746803472390426624","status": 4,"picture_url": "https://cdn.maze.guru/ai/13tpaqf/8E76E92A9BF2B64ECE3F12690DA6FE43-01.jpg","complete_percent": "1","audio_info": "[{\"rate\":99.9,\"suggestion\":\"pass\",\"label\":\"normal\",\"scene\":\"porn\"},{\"rate\":99.91,\"suggestion\":\"pass\",\"label\":\"normal\",\"scene\":\"terrorism\"}]"}]}其中picture_url就是生成的图片地址。
当然,这个返回结果存在几个你没见过的参数,分别给大家解释一下,如下图所示:
一般来说,异步任务有这样的返回结果,显得还是很专业的,mazeguru跟fal平台生成图片是不一样的哈,大家要注意,fal平台是线性任务,获取图片的过程中是需要“在线等待”的,而mazeguru是异步生成,图片的结果是需要单独请求(也就是使用查询结果这个工具)才能获得。
02
—
使用细节
关于工具的使用细节,我上面基本上讲清楚了,但是如果你需要获得mazeguru平台更多的样式信息,那么你就需要看看这个,下面我提供一个样式对照表,方便你灵活使用。
Stable Style(适用于基础样式)
| style id | style name | 
|---|---|
| 29 | Girl Realistic | 
| 31 | Real Photo | 
| 43 | Fantasy | 
| 52 | Universal | 
| 71 | Scifi | 
| 90 | C4D | 
| 100 | Asian Portrait | 
| 111 | Any Portait | 
| 156 | 2.5D XL | 
| 192 | Interior Design XL | 
| 193 | Universal XL | 
| 20004 | Dalle3 | 
Anime Style(适用于基础样式)
| style id | style name | 
|---|---|
| 3 | Default V1 | 
| 46 | Semi Impasto | 
| 84 | TV002 | 
| 97 | Everything | 
| 112 | Lineless Art | 
| 113 | 2.2D Impasto | 
| 155 | Anime XL | 
MJ&NIJI(mj模型专用,开会员才能用)
| style id | style name | 
|---|---|
| 153 | MJv5 | 
| 154 | Niji | 
| 20003 | MJv6 | 
| 20006 | Nijiv6 | 
Exclusive(平台特殊样式,开会员才能用)
| style id | style name | 
|---|---|
| 115 | Emoji Mixed | 
| 116 | SD Figure | 
| 117 | Geometri c | 
| 118 | 1990s | 
| 119 | Chubby | 
| 120 | Flat Graphics | 
| 121 | Fairy | 
| 122 | Bokeh | 
| 123 | Childbook | 
| 124 | Papercut | 
| 125 | Sharpie | 
| 126 | Tshirt Printing | 
| 127 | Vector Graphics | 
| 128 | Hand Draw | 
| 129 | Minimal Logo | 
| 130 | Watercolor | 
| 131 | Felt Craft | 
| 132 | Hologram | 
| 133 | Vector Design | 
| 134 | Kawayi | 
| 140 | Glass Crack | 
| 141 | Genevieve Book | 
| 142 | Cute Animals | 
| 143 | Cobblestone | 
| 144 | Oriental Ink | 
| 145 | Mexican Sticker | 
| 146 | Zen Illustration | 
| 147 | Japan Minimalist | 
| 148 | 2D Chibi | 
| 149 | Star Warframe | 
| 150 | Low Poly | 
| 151 | Splatoon | 
| 152 | Fresh Punk | 
| 157 | Ukiyoe | 
| 158 | Yoshitaka Amano | 
| 160 | Goro Fujita | 
| 161 | Kintsugi | 
| 162 | Wabi-sabi | 
| 163 | Ikebana | 
| 164 | Trendy Toys | 
| 165 | Temari | 
| 166 | Surrealism | 
| 167 | Line Art | 
| 168 | Floral Art | 
| 169 | Gothic Fairy Tale | 
| 170 | Superhero Poster | 
| 171 | Superhero Comic | 
| 173 | Superhero Comic III | 
| 174 | Superhero Comic II | 
| 175 | Romantic Goth | 
| 176 | Pop Art | 
| 177 | Kawanabe Kyosai | 
| 178 | Japanese Vintage Poster | 
| 179 | Hina Doll | 
| 180 | Healing Cartoon | 
| 181 | Hasui Kawase | 
| 182 | Harajuku Fashion | 
| 183 | Future Punk | 
| 184 | Cement Design | 
| 185 | Broken Design | 
| 186 | Brazilian Modernism II | 
| 187 | Brazilian Modernism | 
| 188 | Balloon Art | 
| 189 | B&W Goth | 
好了,以上就是这个工具的使用全部教程了,请留意,这个平台调用mj的成本比mj官方是高的,好处就是不会封你的mj账户,起码比你直接使用mj代理平台抓数据要安全一些。
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-10-30
Dify流程暂停与人工干预:3种实现方案+避坑指南
2025-10-16
告别升级噩梦:Dify 二次开发的无缝适配策略与实战案例(基于 v1.9.1)
2025-10-13
用Dify搭建企业知识库:5个实战技巧提升检索准确率90%
2025-10-13
Dify接口调用实战指南:从入门到精通的避坑手册,收藏了!
2025-10-12
Dify1.6.0升级1.9.1步骤及踩坑记
2025-10-10
用 Dify 零代码搭建 AI 用研助理,5分钟完成100个虚拟用户调研
2025-09-30
重大消息,刚刚Dify 1.9.1发布了!我们聊聊带来了哪些吸引人的功能特性?
2025-09-26
内网环境下Dify1.9.0版本镜像构建过程记录
 
            2025-10-13
2025-09-03
2025-09-16
2025-09-06
2025-08-19
2025-09-23
2025-09-02
2025-08-18
2025-09-04
2025-10-12
2025-09-30
2025-09-23
2025-09-06
2025-09-05
2025-08-29
2025-08-18
2025-08-02
2025-07-30