返回
项目与实践
用 MiniMax 为 Hermes Agent 接入图片与视频生成
记录 Hermes 的 MiniMax 图片与视频插件实现,包括 image-01、Hailuo 异步任务、CN 与 global endpoint fallback、端到端测试和 PyPI 发布。
这篇记录如何把 MiniMax 的图片和视频生成能力接入 Hermes,并在一个 pip 包中提供图片与视频两个后端。实现覆盖文生图、图生图、文生视频、图生视频和人物参考视频。
文中的返回时间、文件大小和分辨率来自当时的端到端测试记录。API 行为和模型限制会变化,实际接入时仍应以当前官方文档和接口返回为准。
为什么选 MiniMax#
Hermes Agent 内置的 image_generate 工具原本只支持少数几个海外后端(FAL、xAI、OpenAI、Krea、Replicate)。这次接入 MiniMax,主要为了补齐两个能力:
image-01:单 API 同时支持文生图和图生图(subject_reference单参考图),可以复用同一套 Hermes 图片后端接口- Hailuo 系列视频模型:采用异步任务模式,覆盖文生视频、图生视频、首尾帧和人物参考等路径。本文实际跑通的是 Hailuo-2.3 的 6 秒 768P 文生视频
而且 MiniMax 有两个 endpoint:
| 区域 | 域名 | 用户中心 |
|---|---|---|
| 国内(CN) | api.minimaxi.com | api.minimaxi.com ↗ |
| 国际(global) | api.minimax.io | minimax.io ↗ |
插件会自动选:CN 优先(你用的是国内账户就走国内),global 作为兜底。
实现一个插件要做什么#
Hermes 的 ImageGenProvider 和 VideoGenProvider 已经封装环境变量加载、URL 缓存和错误格式化。这个插件主要补两个 provider 的请求与响应逻辑:
~/.hermes/plugins/image_gen/minimax/
├── __init__.py # 业务逻辑
└── plugin.yaml # 插件元数据
~/.hermes/plugins/video_gen/minimax/
├── __init__.py
└── plugin.yamltextplugin.yaml 极简:
name: minimax
version: 1.0.0
description: 'MiniMax image generation backend. ...'
author: NousResearch
kind: backendyamlimage-01 后端实现要点#
主要工作是组装 HTTP 请求。文档里几个非显然的点:
-
路径用
aspect_ratio而不是 size(和 OpenAI、StepFun 不一样):
json{ "model": "image-01", "prompt": "a tiny red apple on a white plate, studio lighting", "aspect_ratio": "1:1", // 不是 "1024x1024" "response_format": "url", // 还可以是 "base64" "n": 1, "prompt_optimizer": true } -
图生图用
subject_reference包裹图片 URL:
json"subject_reference": [ { "type": "character", "image_file": "https://..." } ] -
返回结构是嵌套的:
json{ "data": { "image_urls": ["https://..."] }, "metadata": { "success_count": "1" }, "base_resp": { "status_code": 0, "status_msg": "success" } }
把请求组装好、调用 _call_api、拿到 URL 后用 Hermes 自带的 save_url_image 落盘到 ~/.hermes/cache/images/,整个 generate 流程就完了。
Hailuo 视频后端实现要点#
视频生成和图片最大的区别是异步:
1. POST /v1/video_generation → task_id
2. GET /v1/query/video_generation (10s 轮询) → file_id
3. GET /v1/files/retrieve?file_id=… → download_url
4. GET <download_url> → 字节流 → 本地缓存text超时策略:单次任务最长 5 分钟,10 秒轮询一次。Hailuo-2.3 6s 768P 实测 30-90 秒返回,10s 1080P 偶尔会 3-4 分钟。模型选择上要注意:
| 模型 | 6/10s | 768P/1080P | T2V | I2V | 人物参考 |
|---|---|---|---|---|---|
MiniMax-Hailuo-2.3 | ✅ | ✅ | ✅ | ✅ | ❌ |
MiniMax-Hailuo-02 | ✅ | ✅ | ✅ | ✅ | ❌ |
S2V-01 | 只 6s | 只 1080P | ❌ | ❌ | ✅ |
一个 API 参数兼容问题:官方文档示例里写的是 720P,但实际 API 不接受。提交 720P 会立刻报错 does not support resolution 720P, supported resolutions: 768P, 1080P。我的插件把 720P 自动 coerce 成 768P,调用方可以无感。
端到端测试效果#
image-01 文生图(1:1 方形)#
a tiny red apple on a white plate, studio lighting, photorealistic

单图 5 秒左右返回,~150KB。
image-01 文生图(16:9 横向)#
a cute cat astronaut floating in a colorful nebula, digital art, vibrant

futuristic tokyo cityscape at night, neon lights, rain reflections, cyberpunk

Hailuo-2.3 文生视频(6s @ 768P)#
a calico cat napping in a sunbeam, soft cinematic lighting, gentle breathing motion
视频演示 GIF 已从上游仓库移除;保留下方 MP4 原片链接作为可验证演示。
86 秒返回,输出 1366×768 h264 mp4,每帧都有微小变化(呼吸感)。
本地接入步骤#
1. 安装包#
pip install hermes-minimax-mediabash2. 配 key#
编辑 ~/.hermes/.env:
# CN endpoint(你目前在用的)
MINIMAX_CN_API_KEY=eyJ...
# 国际 endpoint(兜底)
MINIMAX_API_KEY=eyJ...bash3. 启用插件#
编辑 ~/.hermes/config.yaml:
plugins:
enabled:
- image_gen/minimax
- video_gen/minimax
# ... 其他插件
image_gen:
provider: minimax
minimax:
model: image-01
video_gen:
provider: minimax
minimax:
model: MiniMax-Hailuo-2.3 # 或 Hailuo-02 / S2V-01yaml4. 重启 Hermes#
hermes gateway restartbash之后直接对 Hermes 说:
- “画一只戴墨镜的猫” → 走 image-01
- “做一个 6 秒的城市黄昏延时摄影” → 走 Hailuo-2.3
- “让这张海浪照片动起来”(+ 传 image_url) → 走 Hailuo-2.3 I2V
- “让这个角色挥手”(+ 传人物照片) → 走 S2V-01
仓库里有什么#
整个项目都开源在 github.com/lora-sys/hermes-minimax-media ↗:
src/hermes_minimax_media/plugins/image_gen/minimax/— image-01 后端src/hermes_minimax_media/plugins/video_gen/minimax/— Hailuo 视频后端tests/— 20 个 pytest 用例(不需要 API key).github/workflows/ci.yml— py3.11/3.12 测试 + ruff lint + tag 时自动发 PyPIdocs/assets/— README 用的 3 张示例图 + 1 个 demo.gif
端到端验证记录#
我跑过的真实结果(不靠模拟):
| 验证项 | 结果 |
|---|---|
image-01 T2I 调 api.minimaxi.com | ✅ 5 秒返回 155KB jpg |
Hailuo-2.3 T2V 异步提交 | ✅ task_id 立即返回 |
| 10s 轮询 task status | ✅ 86 秒变 Success |
解析 file_id + download_url | ✅ 拿到 608KB mp4 |
| 双 endpoint 自动选 CN | ✅ env 设了 MINIMAX_CN_API_KEY 时走 api.minimaxi.com |
pip install -e . 包级导入 | ✅ 两个 provider 都能 import |
pytest tests/ | ✅ 20 passed |
ruff check src/ tests/ | ✅ All checks passed |
twine upload dist/* | ✅ https://pypi.org/project/hermes-minimax-media/ ↗ |
和之前 StepFun 那篇的关系#
我之前写过一篇 用 StepFun 给 Hermes 接入图片生成,流程上是同构的(本地插件 → PyPI → CI → 博客),但这两个插件互补:
两个 Hermes 媒体后端的侧重点
StepFun
- step-image-edit-2 在本文记录里约 1–2 秒,适合快速迭代
- 图编辑是这篇 StepFun 插件的重点能力
- 需要按账户类型选择计费 endpoint
MiniMax
- image-01 同时覆盖文生图与单参考图图生图
- 同一插件族增加 Hailuo 视频能力
- 本文验证了 CN endpoint 自动选择
依据两篇 Hermes 插件文章里的实际实现与验证记录
而且两个插件可以同时启用,在 config.yaml 里改 image_gen.provider 就能切换,不需要卸载任何一个。
下一步计划#
- 跑
image-01的 i2i(subject_reference)真实样例 - 跑
S2V-01人物参考视频的真实样例 - 适配
Hailuo-02的 start-end frame 模式(传 first_frame_image + last_frame_image 两个 url)
项目包已发布为 hermes-minimax-media ↗。仓库保留安装方式、当前支持范围和后续适配项。
评论
评论公开保存在 GitHub Discussions。
正在准备评论区…
评论框就绪后可以使用 GitHub 登录参与讨论,也可以直接打开仓库 Discussions。 打开 GitHub Discussions ↗评论会发布到 lora-sys/loraSys 仓库的公开 Discussions。