图像与视频 API 接入指南
在可信后端通过 OOMOL Fusion API 生成和编辑图片、创建视频。各厂商保留已支持的请求参数和响应格式。支持范围以具体模型和操作为准,不代表兼容厂商的所有 API。
创建 API key
在 OOMOL Console 创建个人 API key,然后在后端运行环境中设置下方环境变量。将这个 OOMOL key 用作 SDK 的 apiKey 或 HTTP Bearer token,示例不需要填写厂商密钥。不要把 key 放进浏览器代码、公开仓库或日志。
export FUSION_API_TOKEN="<your-oomol-api-key>"
选择接入地址
服务域名是 https://fusion-api.oomol.com。请使用下表中对应厂商的完整 Base URL,保留其中的版本路径,不要替换成 Connector 或 ProjectConnector 地址。发起付费请求前,确认所需模型已开放,并查看价格。
| 厂商 | Base URL |
|---|---|
| OpenAI Images | https://fusion-api.oomol.com/v1/provider/openai/v1 |
| Seedream | https://fusion-api.oomol.com/v1/provider/seedream/api/v3 |
| Seedance | https://fusion-api.oomol.com/v1/provider/seedance/api/v3 |
| Wanx | https://fusion-api.oomol.com/v1/provider/wanx/api/v1 |
| Kling | https://fusion-api.oomol.com/v1/provider/kling/ |
| MiniMax | https://fusion-api.oomol.com/v1/provider/minimax/ |
运行示例
只安装所选厂商需要的依赖。将对应示例保存为 example.ts,在服务端 TypeScript 环境运行。下方依赖版本与仓库本地兼容测试一致,不代表支持所有 SDK 版本。配置有效凭证且入口可用时,运行示例会发起真实生成请求。
OpenAI Images
图片生成与编辑;不包含其他 OpenAI API。
npm install openai@7.23.0
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.FUSION_API_TOKEN,
baseURL: "https://fusion-api.oomol.com/v1/provider/openai/v1",
maxRetries: 0,
timeout: 1_080_000,
});
const result = await client.images.generate({
model: "gpt-image-2",
prompt: "A ceramic mug on a wooden table",
size: "1536x864",
quality: "medium",
});
console.log(result);
Seedream
图片生成、参考图与部分 SSE 输出。
npm install @volcengine/ark-runtime@1.0.11
import { ArkRuntimeClient } from "@volcengine/ark-runtime";
const client = new ArkRuntimeClient({
apiKey: process.env.FUSION_API_TOKEN,
baseURL: "https://fusion-api.oomol.com/v1/provider/seedream/api/v3",
retryTimes: 0,
timeout: 125_000,
});
const result = await client.generateImages({
model: "doubao-seedream-5-0-260128",
prompt: "A ceramic mug on a wooden table",
size: "2K",
response_format: "url",
});
console.log(result);
Seedance
视频生成与任务查询。
npm install @volcengine/ark-runtime@1.0.11
import { ArkRuntimeClient } from "@volcengine/ark-runtime";
const client = new ArkRuntimeClient({
apiKey: process.env.FUSION_API_TOKEN,
baseURL: "https://fusion-api.oomol.com/v1/provider/seedance/api/v3",
retryTimes: 0,
timeout: 125_000,
});
const task = await client.createContentGenerationTask({
model: "doubao-seedance-2-0-260128",
content: [{ type: "text", text: "A boat on the ocean" }],
duration: 5,
resolution: "720p",
});
const status = await client.getContentGenerationTask(task.id);
console.log(task.id, status);
Wanx
视频生成与任务查询。
npm install dashscope-sdk-official@1.26.0
import { Configuration, VideoSynthesis } from "dashscope-sdk-official";
const client = new VideoSynthesis(new Configuration({
apiKey: process.env.FUSION_API_TOKEN,
basePath: "https://fusion-api.oomol.com/v1/provider/wanx/api/v1",
}));
const task = await client.asyncCall({
model: "wan3.0-video",
prompt: "A boat on the ocean",
resolution: "1080P",
duration: 5,
});
const status = await client.fetch(task.output.task_id);
console.log(task.output.task_id, status);
Kling
视频生成与任务查询。
npm install ky@1.11.0
import ky from "ky";
const client = ky.create({
prefixUrl: "https://fusion-api.oomol.com/v1/provider/kling/",
headers: { Authorization: `Bearer ${process.env.FUSION_API_TOKEN}` },
retry: 0,
redirect: "error",
timeout: 30_000,
});
const task = await client.post("text-to-video/kling-3.0-turbo", {
json: {
prompt: "A boat on the ocean",
settings: { duration: 5, resolution: "720p", aspect_ratio: "16:9" },
},
}).json<{ data: { id: string } }>();
const status = await client.get("tasks", {
searchParams: { task_ids: task.data.id },
}).json();
console.log(task.data.id, status);
MiniMax
视频生成与任务查询。
npm install ky@1.11.0
import ky from "ky";
const client = ky.create({
prefixUrl: "https://fusion-api.oomol.com/v1/provider/minimax/",
headers: { Authorization: `Bearer ${process.env.FUSION_API_TOKEN}` },
retry: 0,
redirect: "error",
timeout: 30_000,
});
const task = await client.post("v2/video_generation", {
json: {
model: "MiniMax-H3",
content: [{ type: "text", text: "A boat on the ocean" }],
duration: 5,
resolution: "768P",
ratio: "16:9",
},
}).json<{ task_id: string }>();
const status = await client.get(
`v2/query/video_generation/${encodeURIComponent(task.task_id)}`,
).json();
console.log(task.task_id, status);
查询视频结果
视频示例创建任务后只查询一次。请先保存返回的任务 ID。创建请求成功表示任务已受理,不代表视频已生成。使用同一 OOMOL 身份查询同一任务,直到厂商返回终态。查询之间留出间隔;成功或失败后停止查询,并读取对应的结果或错误字段。查询请求失败不等于生成任务失败,也不要为了检查进度重新创建任务。
处理错误和重试
同时检查 HTTP 错误和返回的任务状态。鉴权、余额检查可能返回网关错误,格式与厂商错误不同。鉴权失败时检查 OOMOL key;权限或余额错误时检查账号及账单;参数错误时核对模型、操作和参数值;遇到限流时降低并发,并遵循响应中提供的重试提示。
创建请求超时、连接断开或服务端错误时,生成结果可能尚不确定。保留任务 ID、请求 ID 和错误信息;已有任务 ID 时优先查询。不要自动重发生成请求,否则可能创建另一个付费任务。OpenAI 和方舟示例关闭了 SDK 重试,ky 还关闭了重定向;DashScope 沿用已验证的 SDK 配置。业务层可以设置等待上限,但超时后不要盲目重新提交。
文件、流式输出与结果数据
上传、参考素材和流式输出的限制因厂商而异。OpenAI 示例仅覆盖 Images API,不包含聊天、Responses 或其他 OpenAI API。Seedream 支持部分 SSE 操作,这里的 OpenAI 图片入口为同步返回。处理流式输出时,收到部分事件不代表已收到完成事件。
下载返回的媒体 URL 时使用独立客户端,不要携带 OOMOL Authorization 请求头,也不要假定媒体链接永久有效。客户端断开连接不保证取消已被上游受理的生成任务。遇到不支持的操作或结果不确定的请求,请联系支持,提供请求或任务 ID,不要发送密钥。