Files
NianAIGC/lib/server/minimax-billing.ts
2026-09-11 15:33:18 +08:00

32 lines
1.2 KiB
TypeScript

export const MINIMAX_H3_MODEL = "MiniMax-H3";
export function minimaxH3VideoPriceFenPerSecond(resolution: unknown) {
return String(resolution || "").trim().toUpperCase() === "2K" ? 80 : 50;
}
export function calculateMinimaxH3ActualAmountFen(input: {
resolution?: unknown;
outputSeconds: number;
inputVideoSeconds?: number;
inputImageCount?: number;
markupMultiplier: number;
}) {
const outputSeconds = integer(input.outputSeconds);
const inputVideoSeconds = nonNegativeInteger(input.inputVideoSeconds);
const inputImageCount = nonNegativeInteger(input.inputImageCount);
if (outputSeconds <= 0) throw new Error("MiniMax H3 实际输出时长必须大于 0。");
if (!Number.isFinite(input.markupMultiplier) || input.markupMultiplier < 1) throw new Error("MiniMax H3 计费倍率不能低于 1.00。");
const standardAmountFen = (outputSeconds + inputVideoSeconds) * minimaxH3VideoPriceFenPerSecond(input.resolution)
+ Math.max(0, inputImageCount - 5) * 20;
return Math.ceil(standardAmountFen * input.markupMultiplier);
}
function integer(value: unknown) {
const number = Number(value);
return Number.isInteger(number) ? number : 0;
}
function nonNegativeInteger(value: unknown) {
return Math.max(0, integer(value));
}