function resolveDurationSeconds(value: number | undefined): number { if (typeof value !== "number" || !Number.isFinite(value)) { return5;
} return Math.max(2, Math.min(MAX_DURATION_SECONDS, Math.round(value)));
}
function resolveEndpoint(
req: VideoGenerationRequest,
): "/v1/text_to_video" | "/v1/image_to_video" | "/v1/video_to_video" { const imageCount = req.inputImages?.length ?? 0; const videoCount = req.inputVideos?.length ?? 0; if (imageCount > 0 && videoCount > 0) { thrownew Error("Runway video generation does not support image and video inputs together.");
} if (imageCount > 1 || videoCount > 1) { thrownew Error("Runway video generation supports at most one input image or one input video.");
} if (videoCount > 0) { return"/v1/video_to_video";
} if (imageCount > 0) { return"/v1/image_to_video";
} return"/v1/text_to_video";
}
function buildCreateBody(req: VideoGenerationRequest): Record<string, unknown> { const endpoint = resolveEndpoint(req); const duration = resolveDurationSeconds(req.durationSeconds); const ratio = resolveRunwayRatio(req); const model = normalizeOptionalString(req.model) ?? DEFAULT_RUNWAY_MODEL; if (endpoint === "/v1/text_to_video") { if (!TEXT_ONLY_MODELS.has(model)) { thrownew Error(
`Runway text-to-video does not support model ${model}. Use one of: ${[...TEXT_ONLY_MODELS].join(", ")}.`,
);
} return {
model,
promptText: req.prompt,
ratio,
duration,
};
}
if (endpoint === "/v1/image_to_video") { if (!IMAGE_MODELS.has(model)) { thrownew Error(
`Runway image-to-video does not support model ${model}. Use one of: ${[...IMAGE_MODELS].join(", ")}.`,
);
} const promptImage = resolveSourceUri(req.inputImages?.[0], "image/png"); if (!promptImage) { thrownew Error("Runway image-to-video input is missing image data.");
} return {
model,
promptText: req.prompt,
promptImage,
ratio,
duration,
};
}
if (!VIDEO_MODELS.has(model)) { thrownew Error("Runway video-to-video currently requires model gen4_aleph.");
} const videoUri = resolveSourceUri(req.inputVideos?.[0], "video/mp4"); if (!videoUri) { thrownew Error("Runway video-to-video input is missing video data.");
} return {
model,
promptText: req.prompt,
videoUri,
ratio,
};
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet am 2026-06-06)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.