mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
new model - seedance 2.5
This commit is contained in:
1 parent
9737f0ef88
commit
84d683056c
4 files changed
+647
-9
No files matched your search
+438
@@ -0,0 +1,438 @@
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
use crate::requests::workflow_run_task::workflow_run_task::{
|
||||
workflow_run_task, KinoviAspectRatioRaw, KinoviBatchCountRaw, KinoviModelTypeRaw,
|
||||
KinoviOutputResolutionRaw, WorkflowRunTaskArgs, WorkflowRunTaskRequest,
|
||||
};
|
||||
|
||||
// ── Args ──
|
||||
|
||||
pub struct GenerateSeedance2p5PreviewArgs<'a> {
|
||||
pub request: GenerateSeedance2p5PreviewRequest,
|
||||
pub session: &'a KinoviWebSession,
|
||||
pub host_override: Option<KinoviHost>,
|
||||
}
|
||||
|
||||
// ── Request ──
|
||||
|
||||
/// Seedance 2.5 Preview only supports reference mode (there is no keyframe
|
||||
/// start/end frame mode), 480p/720p output, and durations of 4–30 seconds.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerateSeedance2p5PreviewRequest {
|
||||
pub prompt: String,
|
||||
pub aspect_ratio: Option<KinoviSeedance2p5PreviewAspectRatio>,
|
||||
pub output_resolution: Option<KinoviSeedance2p5PreviewOutputResolution>,
|
||||
pub duration_seconds: u8,
|
||||
/// Reference images, referenced in prompts as @image1, @image2, etc.
|
||||
pub reference_image_urls: Option<Vec<String>>,
|
||||
/// Reference videos, referenced in prompts as @video1, @video2, etc.
|
||||
pub reference_video_urls: Option<Vec<String>>,
|
||||
/// Reference audio, referenced in prompts as @audio1, @audio2, etc.
|
||||
pub reference_audio_urls: Option<Vec<String>>,
|
||||
/// Controls `faceBlurMode`: true sends "on"; false or None sends "off"
|
||||
/// (the model always sends the field, unlike older Seedance models).
|
||||
pub use_face_blur_hack: Option<bool>,
|
||||
}
|
||||
|
||||
// ── Enums ──
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum KinoviSeedance2p5PreviewAspectRatio {
|
||||
Landscape16x9,
|
||||
UltraWide21x9,
|
||||
Portrait9x16,
|
||||
Square1x1,
|
||||
Standard4x3,
|
||||
Portrait3x4,
|
||||
}
|
||||
|
||||
/// Output resolution. 2.5 Preview supports only 480p and 720p.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum KinoviSeedance2p5PreviewOutputResolution {
|
||||
FourEightyP,
|
||||
SevenTwentyP,
|
||||
}
|
||||
|
||||
// ── Pricing ──
|
||||
//
|
||||
// Seedance 2.5 Preview credit pricing (per second of output duration):
|
||||
//
|
||||
// | Resolution | Credits/sec |
|
||||
// |------------|-------------|
|
||||
// | 480p | 46.81 |
|
||||
// | 720p | 93.62 |
|
||||
//
|
||||
// References (images, videos, and audio) do NOT affect the cost — unlike the
|
||||
// Seedance 2.0 models, there is no video-reference surcharge. Default
|
||||
// resolution (None) is 720p.
|
||||
// Credit package: 525,000 credits for $2,159.0909 (~243 credits/$1).
|
||||
|
||||
impl GenerateSeedance2p5PreviewRequest {
|
||||
/// Calculate the cost of this generation request, in Kinovi credits
|
||||
/// (fractional) and USD cents.
|
||||
///
|
||||
/// The math is done in integer hundredths of a credit so the totals land
|
||||
/// exactly on the observed values (e.g. 480p × 15s = 702.15, not the
|
||||
/// 702.150000000001 float artifact Kinovi's own UI shows).
|
||||
pub fn calculate_costs(&self) -> KinoviFractionalGenerationCost {
|
||||
let credits_per_second_hundredths: u64 = match self.output_resolution {
|
||||
Some(KinoviSeedance2p5PreviewOutputResolution::FourEightyP) => 4_681,
|
||||
Some(KinoviSeedance2p5PreviewOutputResolution::SevenTwentyP) | None => 9_362,
|
||||
};
|
||||
|
||||
let total_hundredths = credits_per_second_hundredths * u64::from(self.duration_seconds);
|
||||
KinoviFractionalGenerationCost::from_kinovi_credits(total_hundredths as f64 / 100.0)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Response ──
|
||||
|
||||
pub struct GenerateSeedance2p5PreviewResponse {
|
||||
pub task_id: String,
|
||||
pub order_id: String,
|
||||
pub task_ids: Option<Vec<String>>,
|
||||
pub order_ids: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
// ── Entry point ──
|
||||
|
||||
pub async fn generate_seedance_2p5_preview(
|
||||
args: GenerateSeedance2p5PreviewArgs<'_>,
|
||||
) -> Result<GenerateSeedance2p5PreviewResponse, KinoviWebError> {
|
||||
let raw_response = workflow_run_task(WorkflowRunTaskArgs {
|
||||
request: to_raw_request(args.request),
|
||||
session: args.session,
|
||||
host_override: args.host_override,
|
||||
}).await?;
|
||||
|
||||
Ok(GenerateSeedance2p5PreviewResponse {
|
||||
task_id: raw_response.task_id,
|
||||
order_id: raw_response.order_id,
|
||||
task_ids: raw_response.task_ids,
|
||||
order_ids: raw_response.order_ids,
|
||||
})
|
||||
}
|
||||
|
||||
// ── Mapping helpers ──
|
||||
|
||||
fn to_raw_request(req: GenerateSeedance2p5PreviewRequest) -> WorkflowRunTaskRequest {
|
||||
WorkflowRunTaskRequest {
|
||||
model_type: KinoviModelTypeRaw::Seedance2p5Preview,
|
||||
prompt: req.prompt,
|
||||
aspect_ratio: map_aspect_ratio(req.aspect_ratio),
|
||||
output_resolution: req.output_resolution.map(map_output_resolution),
|
||||
duration_seconds: req.duration_seconds,
|
||||
batch_count: KinoviBatchCountRaw::One,
|
||||
start_frame_url: None,
|
||||
end_frame_url: None,
|
||||
reference_image_urls: req.reference_image_urls,
|
||||
reference_video_urls: req.reference_video_urls,
|
||||
reference_audio_urls: req.reference_audio_urls,
|
||||
character_ids: None,
|
||||
use_face_blur_hack: req.use_face_blur_hack,
|
||||
bitrate: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn map_aspect_ratio(ar: Option<KinoviSeedance2p5PreviewAspectRatio>) -> KinoviAspectRatioRaw {
|
||||
match ar {
|
||||
Some(KinoviSeedance2p5PreviewAspectRatio::Landscape16x9) => KinoviAspectRatioRaw::Landscape16x9,
|
||||
Some(KinoviSeedance2p5PreviewAspectRatio::UltraWide21x9) => KinoviAspectRatioRaw::UltraWide21x9,
|
||||
Some(KinoviSeedance2p5PreviewAspectRatio::Portrait9x16) => KinoviAspectRatioRaw::Portrait9x16,
|
||||
Some(KinoviSeedance2p5PreviewAspectRatio::Square1x1) => KinoviAspectRatioRaw::Square1x1,
|
||||
Some(KinoviSeedance2p5PreviewAspectRatio::Standard4x3) => KinoviAspectRatioRaw::Landscape4x3,
|
||||
Some(KinoviSeedance2p5PreviewAspectRatio::Portrait3x4) => KinoviAspectRatioRaw::Portrait3x4,
|
||||
None => KinoviAspectRatioRaw::Landscape16x9,
|
||||
}
|
||||
}
|
||||
|
||||
fn map_output_resolution(res: KinoviSeedance2p5PreviewOutputResolution) -> KinoviOutputResolutionRaw {
|
||||
match res {
|
||||
KinoviSeedance2p5PreviewOutputResolution::FourEightyP => KinoviOutputResolutionRaw::FourEightyP,
|
||||
KinoviSeedance2p5PreviewOutputResolution::SevenTwentyP => KinoviOutputResolutionRaw::SevenTwentyP,
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tests ──
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::test_utils::get_test_cookies::get_test_cookies;
|
||||
use crate::test_utils::setup_test_logging::setup_test_logging;
|
||||
use errors::AnyhowResult;
|
||||
use log::LevelFilter;
|
||||
|
||||
mod pricing_tests {
|
||||
use super::*;
|
||||
|
||||
const FLOAT_TOLERANCE: f64 = 1e-9;
|
||||
|
||||
fn build_request(
|
||||
duration_seconds: u8,
|
||||
output_resolution: Option<KinoviSeedance2p5PreviewOutputResolution>,
|
||||
) -> GenerateSeedance2p5PreviewRequest {
|
||||
GenerateSeedance2p5PreviewRequest {
|
||||
prompt: String::new(),
|
||||
aspect_ratio: None,
|
||||
output_resolution,
|
||||
duration_seconds,
|
||||
reference_image_urls: None,
|
||||
reference_video_urls: None,
|
||||
reference_audio_urls: None,
|
||||
use_face_blur_hack: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn r480(dur: u8) -> GenerateSeedance2p5PreviewRequest {
|
||||
build_request(dur, Some(KinoviSeedance2p5PreviewOutputResolution::FourEightyP))
|
||||
}
|
||||
|
||||
fn r720(dur: u8) -> GenerateSeedance2p5PreviewRequest {
|
||||
build_request(dur, None)
|
||||
}
|
||||
|
||||
fn with_all_reference_types(mut request: GenerateSeedance2p5PreviewRequest) -> GenerateSeedance2p5PreviewRequest {
|
||||
request.reference_image_urls = Some(vec![
|
||||
"https://example.com/a.jpg".to_string(),
|
||||
"https://example.com/b.png".to_string(),
|
||||
]);
|
||||
request.reference_video_urls = Some(vec!["https://example.com/ref.mp4".to_string()]);
|
||||
request.reference_audio_urls = Some(vec!["https://example.com/ref.wav".to_string()]);
|
||||
request
|
||||
}
|
||||
|
||||
// ── Full pricing table (credits) ──
|
||||
//
|
||||
// The exact per-duration table observed from Kinovi for Seedance 2.5
|
||||
// Preview: 480p = 46.81 credits/sec, 720p = 93.62 credits/sec.
|
||||
|
||||
mod kinovi_pricing_table {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn table_480p() {
|
||||
assert_eq!(r480(4).calculate_costs().kinovi_credits, 187.24);
|
||||
assert_eq!(r480(10).calculate_costs().kinovi_credits, 468.1);
|
||||
assert_eq!(r480(15).calculate_costs().kinovi_credits, 702.15);
|
||||
assert_eq!(r480(20).calculate_costs().kinovi_credits, 936.2);
|
||||
assert_eq!(r480(25).calculate_costs().kinovi_credits, 1170.25);
|
||||
assert_eq!(r480(30).calculate_costs().kinovi_credits, 1404.3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_720p() {
|
||||
assert_eq!(r720(4).calculate_costs().kinovi_credits, 374.48);
|
||||
assert_eq!(r720(10).calculate_costs().kinovi_credits, 936.2);
|
||||
assert_eq!(r720(15).calculate_costs().kinovi_credits, 1404.3);
|
||||
assert_eq!(r720(20).calculate_costs().kinovi_credits, 1872.4);
|
||||
assert_eq!(r720(25).calculate_costs().kinovi_credits, 2340.5);
|
||||
assert_eq!(r720(30).calculate_costs().kinovi_credits, 2808.6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_720p_same_as_default() {
|
||||
let default = r720(10).calculate_costs();
|
||||
let explicit = build_request(10, Some(KinoviSeedance2p5PreviewOutputResolution::SevenTwentyP)).calculate_costs();
|
||||
assert_eq!(default, explicit);
|
||||
}
|
||||
}
|
||||
|
||||
// ── References don't affect cost ──
|
||||
//
|
||||
// Unlike the Seedance 2.0 models, 2.5 Preview has no video-reference
|
||||
// surcharge: adding or removing references of any type leaves the cost
|
||||
// unchanged.
|
||||
|
||||
mod references_do_not_affect_cost {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn table_480p_with_references_is_identical() {
|
||||
for duration in [4u8, 10, 15, 20, 25, 30] {
|
||||
assert_eq!(
|
||||
with_all_reference_types(r480(duration)).calculate_costs(),
|
||||
r480(duration).calculate_costs(),
|
||||
"480p at {duration}s",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_720p_with_references_is_identical() {
|
||||
for duration in [4u8, 10, 15, 20, 25, 30] {
|
||||
assert_eq!(
|
||||
with_all_reference_types(r720(duration)).calculate_costs(),
|
||||
r720(duration).calculate_costs(),
|
||||
"720p at {duration}s",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn video_reference_alone_adds_no_surcharge() {
|
||||
let mut request = r720(10);
|
||||
request.reference_video_urls = Some(vec!["https://example.com/ref.mp4".to_string()]);
|
||||
assert_eq!(request.calculate_costs().kinovi_credits, 936.2);
|
||||
}
|
||||
}
|
||||
|
||||
// ── USD cents conversion ──
|
||||
//
|
||||
// usd_cents = credits × 100 / 243, computed on integer hundredths.
|
||||
|
||||
mod usd_cents {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cents_480p_4s() {
|
||||
// 187.24 credits; 18724/243 = 77.0535 cents.
|
||||
let cost = r480(4).calculate_costs();
|
||||
assert_eq!(cost.usd_cents_rounded_up, 78);
|
||||
assert_eq!(cost.usd_cents_rounded_down, 77);
|
||||
assert!((cost.usd_cents_fractional - (18724.0 / 243.0)).abs() < FLOAT_TOLERANCE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cents_480p_15s() {
|
||||
// 702.15 credits; 70215/243 = 288.9506 cents.
|
||||
let cost = r480(15).calculate_costs();
|
||||
assert_eq!(cost.usd_cents_rounded_up, 289);
|
||||
assert_eq!(cost.usd_cents_rounded_down, 288);
|
||||
assert!((cost.usd_cents_fractional - (70215.0 / 243.0)).abs() < FLOAT_TOLERANCE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cents_720p_4s() {
|
||||
// 374.48 credits; 37448/243 = 154.1070 cents.
|
||||
let cost = r720(4).calculate_costs();
|
||||
assert_eq!(cost.usd_cents_rounded_up, 155);
|
||||
assert_eq!(cost.usd_cents_rounded_down, 154);
|
||||
assert!((cost.usd_cents_fractional - (37448.0 / 243.0)).abs() < FLOAT_TOLERANCE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cents_720p_30s() {
|
||||
// 2808.6 credits; 280860/243 = 1155.8025 cents.
|
||||
let cost = r720(30).calculate_costs();
|
||||
assert_eq!(cost.usd_cents_rounded_up, 1156);
|
||||
assert_eq!(cost.usd_cents_rounded_down, 1155);
|
||||
assert!((cost.usd_cents_fractional - (280860.0 / 243.0)).abs() < FLOAT_TOLERANCE);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Relative pricing ──
|
||||
|
||||
mod relative_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn seven_twenty_is_exactly_double_480p() {
|
||||
for duration in [4u8, 10, 15, 20, 25, 30] {
|
||||
let c480 = r480(duration).calculate_costs().kinovi_credits;
|
||||
let c720 = r720(duration).calculate_costs().kinovi_credits;
|
||||
assert_eq!(c720, c480 * 2.0, "720p should be 2× 480p at {duration}s");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cost_scales_linearly_with_duration() {
|
||||
let per_second = r480(1).calculate_costs().kinovi_credits;
|
||||
assert_eq!(per_second, 46.81);
|
||||
for duration in [4u8, 10, 15, 20, 25, 30] {
|
||||
let expected = (4_681 * u64::from(duration)) as f64 / 100.0;
|
||||
assert_eq!(r480(duration).calculate_costs().kinovi_credits, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Aspect ratio doesn't affect cost ──
|
||||
|
||||
#[test]
|
||||
fn aspect_ratio_does_not_affect_credits() {
|
||||
let baseline = r720(10).calculate_costs().kinovi_credits;
|
||||
|
||||
let ratios = [
|
||||
KinoviSeedance2p5PreviewAspectRatio::Landscape16x9,
|
||||
KinoviSeedance2p5PreviewAspectRatio::UltraWide21x9,
|
||||
KinoviSeedance2p5PreviewAspectRatio::Portrait9x16,
|
||||
KinoviSeedance2p5PreviewAspectRatio::Square1x1,
|
||||
KinoviSeedance2p5PreviewAspectRatio::Standard4x3,
|
||||
KinoviSeedance2p5PreviewAspectRatio::Portrait3x4,
|
||||
];
|
||||
|
||||
for ar in &ratios {
|
||||
let mut request = r720(10);
|
||||
request.aspect_ratio = Some(*ar);
|
||||
assert_eq!(
|
||||
request.calculate_costs().kinovi_credits, baseline,
|
||||
"Aspect ratio {:?} should not change credits from baseline {}", ar, baseline,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod real_requests {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_text_to_video_480p() -> AnyhowResult<()> {
|
||||
setup_test_logging(LevelFilter::Trace);
|
||||
let session = test_session()?;
|
||||
let result = generate_seedance_2p5_preview(GenerateSeedance2p5PreviewArgs {
|
||||
session: &session,
|
||||
host_override: None,
|
||||
request: GenerateSeedance2p5PreviewRequest {
|
||||
prompt: "A man is running from a t-rex".to_string(),
|
||||
aspect_ratio: Some(KinoviSeedance2p5PreviewAspectRatio::Landscape16x9),
|
||||
output_resolution: Some(KinoviSeedance2p5PreviewOutputResolution::FourEightyP),
|
||||
duration_seconds: 4,
|
||||
reference_image_urls: None,
|
||||
reference_video_urls: None,
|
||||
reference_audio_urls: None,
|
||||
use_face_blur_hack: None,
|
||||
},
|
||||
}).await?;
|
||||
println!("t2v 480p — task_id={}, order_id={}", result.task_id, result.order_id);
|
||||
assert!(!result.task_id.is_empty());
|
||||
assert!(!result.order_id.is_empty());
|
||||
assert_eq!(1, 2, "Inspect output above");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_text_to_video_720p_default() -> AnyhowResult<()> {
|
||||
setup_test_logging(LevelFilter::Trace);
|
||||
let session = test_session()?;
|
||||
let result = generate_seedance_2p5_preview(GenerateSeedance2p5PreviewArgs {
|
||||
session: &session,
|
||||
host_override: None,
|
||||
request: GenerateSeedance2p5PreviewRequest {
|
||||
prompt: "A corgi and a shiba are playing chess against one another".to_string(),
|
||||
aspect_ratio: None,
|
||||
output_resolution: None,
|
||||
duration_seconds: 4,
|
||||
reference_image_urls: None,
|
||||
reference_video_urls: None,
|
||||
reference_audio_urls: None,
|
||||
use_face_blur_hack: None,
|
||||
},
|
||||
}).await?;
|
||||
println!("t2v 720p — task_id={}, order_id={}", result.task_id, result.order_id);
|
||||
assert!(!result.task_id.is_empty());
|
||||
assert!(!result.order_id.is_empty());
|
||||
assert_eq!(1, 2, "Inspect output above");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn test_session() -> AnyhowResult<KinoviWebSession> {
|
||||
let cookies = get_test_cookies()?;
|
||||
Ok(KinoviWebSession::from_cookies_string(cookies))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,3 +2,4 @@ pub mod generate_happy_horse_1p0;
|
||||
pub mod generate_seedance_2p0;
|
||||
pub mod generate_seedance_2p0_fast;
|
||||
pub mod generate_seedance_2p0_mini;
|
||||
pub mod generate_seedance_2p5_preview;
|
||||
@@ -49,6 +49,17 @@ pub (super) struct ApiParams {
|
||||
pub face_blur_mode: Option<&'static str>,
|
||||
#[serde(rename = "characterIds", skip_serializing_if = "Option::is_none")]
|
||||
pub character_ids: Option<Vec<String>>,
|
||||
/// Reference image URLs, for models that send references in split
|
||||
/// `imageUrls` / `videoUrls` fields (Seedance 2.5 Preview). Those models
|
||||
/// also mirror the image URLs into `uploadedUrls`. None for models that
|
||||
/// send a single combined `uploadedUrls` list.
|
||||
#[serde(rename = "imageUrls", skip_serializing_if = "Option::is_none")]
|
||||
pub image_urls: Option<Vec<String>>,
|
||||
/// Reference video URLs, for models that send references in split
|
||||
/// `imageUrls` / `videoUrls` fields (Seedance 2.5 Preview). None for
|
||||
/// models that send videos in the combined `uploadedUrls` list.
|
||||
#[serde(rename = "videoUrls", skip_serializing_if = "Option::is_none")]
|
||||
pub video_urls: Option<Vec<String>>,
|
||||
#[serde(rename = "uploadedUrls", skip_serializing_if = "Option::is_none")]
|
||||
pub uploaded_urls: Option<Vec<String>>,
|
||||
#[serde(rename = "audioUrls", skip_serializing_if = "Option::is_none")]
|
||||
|
||||
+197
-9
@@ -164,6 +164,17 @@ impl KinoviOutputResolutionRaw {
|
||||
Self::FourK => Some("4k"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The API string including the "720p" default, for models that always
|
||||
/// send `outputResolution` explicitly (Seedance 2.5 Preview).
|
||||
pub fn as_explicit_api_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::FourEightyP => "480p",
|
||||
Self::SevenTwentyP => "720p",
|
||||
Self::TenEightyP => "1080p",
|
||||
Self::FourK => "4k",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Number of videos to generate in a single request.
|
||||
@@ -203,6 +214,8 @@ pub enum KinoviModelTypeRaw {
|
||||
Seedance2Fast,
|
||||
/// Seedance 2.0 Mini (cheapest; 480p/720p only).
|
||||
Seedance2Mini,
|
||||
/// Seedance 2.5 Preview (480p/720p only).
|
||||
Seedance2p5Preview,
|
||||
/// Happy Horse 1.0.
|
||||
HappyHorse1p0,
|
||||
}
|
||||
@@ -213,24 +226,28 @@ impl KinoviModelTypeRaw {
|
||||
Self::Seedance2Pro => "seedance-20",
|
||||
Self::Seedance2Fast => "seedance2-fast",
|
||||
Self::Seedance2Mini => "seedance2.0-mini",
|
||||
Self::Seedance2p5Preview => "seedance2-5-preview",
|
||||
Self::HappyHorse1p0 => "happyhorse1.0",
|
||||
}
|
||||
}
|
||||
|
||||
/// The tRPC `businessType` for this model. Seedance 2.0 Mini uses its
|
||||
/// own business type; every other model uses the shared one.
|
||||
/// The tRPC `businessType` for this model. Seedance 2.0 Mini and 2.5
|
||||
/// Preview use their own business types; every other model uses the
|
||||
/// shared one.
|
||||
fn business_type(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Seedance2Mini => "seedance20-mini-video-generation",
|
||||
Self::Seedance2p5Preview => "seedance25-preview-video-generation",
|
||||
Self::HappyHorse1p0 => "happyhorse-video-generation",
|
||||
Self::Seedance2Pro | Self::Seedance2Fast => "wan22-video-generation",
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the aspect ratio is sent in an `aspectRatio` field (true)
|
||||
/// rather than the `resolution` field. Mini and Happy Horse use `aspectRatio`.
|
||||
/// rather than the `resolution` field. Mini, 2.5 Preview, and Happy Horse
|
||||
/// use `aspectRatio`.
|
||||
fn uses_aspect_ratio_field(&self) -> bool {
|
||||
matches!(self, Self::Seedance2Mini | Self::HappyHorse1p0)
|
||||
matches!(self, Self::Seedance2Mini | Self::Seedance2p5Preview | Self::HappyHorse1p0)
|
||||
}
|
||||
|
||||
/// Whether this model uses Happy Horse's `happyhorseMode` (t2v/i2v)
|
||||
@@ -238,6 +255,27 @@ impl KinoviModelTypeRaw {
|
||||
fn uses_happyhorse_mode(&self) -> bool {
|
||||
matches!(self, Self::HappyHorse1p0)
|
||||
}
|
||||
|
||||
/// Whether reference URLs are sent in split `imageUrls` / `videoUrls`
|
||||
/// fields — with `uploadedUrls` mirroring just the images — rather than
|
||||
/// one combined `uploadedUrls` list. Seedance 2.5 Preview uses the split
|
||||
/// shape.
|
||||
fn uses_split_reference_url_fields(&self) -> bool {
|
||||
matches!(self, Self::Seedance2p5Preview)
|
||||
}
|
||||
|
||||
/// Whether `mode` is always "reference", even with no references attached.
|
||||
/// Seedance 2.5 Preview has no keyframe mode.
|
||||
fn always_uses_reference_mode(&self) -> bool {
|
||||
matches!(self, Self::Seedance2p5Preview)
|
||||
}
|
||||
|
||||
/// Whether the default field values (`outputResolution: "720p"`,
|
||||
/// `faceBlurMode: "off"`) are always sent explicitly rather than omitted.
|
||||
/// Seedance 2.5 Preview always sends both.
|
||||
fn always_sends_default_fields(&self) -> bool {
|
||||
matches!(self, Self::Seedance2p5Preview)
|
||||
}
|
||||
}
|
||||
|
||||
/// Output video bitrate. When omitted, defaults to "standard".
|
||||
@@ -408,9 +446,21 @@ fn build_batch_request(req: WorkflowRunTaskRequest) -> BatchRequest {
|
||||
|
||||
let is_reference_mode = has_reference_images || has_reference_videos || has_reference_audio || has_characters;
|
||||
|
||||
let video_input_mode = if is_reference_mode { "reference" } else { "keyframe" };
|
||||
let video_input_mode = if is_reference_mode || req.model_type.always_uses_reference_mode() {
|
||||
"reference"
|
||||
} else {
|
||||
"keyframe"
|
||||
};
|
||||
|
||||
let uploaded_urls: Option<Vec<String>> = if is_reference_mode {
|
||||
// Reference URLs. Seedance 2.5 Preview sends split `imageUrls` /
|
||||
// `videoUrls` fields with `uploadedUrls` mirroring just the images; other
|
||||
// models combine videos + images into `uploadedUrls` in reference mode, or
|
||||
// send the start/end frames there in keyframe mode.
|
||||
let (image_urls, video_urls, uploaded_urls): (Option<Vec<String>>, Option<Vec<String>>, Option<Vec<String>>) = if req.model_type.uses_split_reference_url_fields() {
|
||||
let image_urls = req.reference_image_urls.filter(|urls| !urls.is_empty());
|
||||
let video_urls = req.reference_video_urls.filter(|urls| !urls.is_empty());
|
||||
(image_urls.clone(), video_urls, image_urls)
|
||||
} else if is_reference_mode {
|
||||
let mut urls = Vec::new();
|
||||
if let Some(video_urls) = req.reference_video_urls {
|
||||
urls.extend(video_urls);
|
||||
@@ -418,7 +468,7 @@ fn build_batch_request(req: WorkflowRunTaskRequest) -> BatchRequest {
|
||||
if let Some(image_urls) = req.reference_image_urls {
|
||||
urls.extend(image_urls);
|
||||
}
|
||||
if urls.is_empty() { None } else { Some(urls) }
|
||||
(None, None, if urls.is_empty() { None } else { Some(urls) })
|
||||
} else {
|
||||
let mut urls = Vec::new();
|
||||
if let Some(url) = req.start_frame_url {
|
||||
@@ -427,7 +477,7 @@ fn build_batch_request(req: WorkflowRunTaskRequest) -> BatchRequest {
|
||||
if let Some(url) = req.end_frame_url {
|
||||
urls.push(url);
|
||||
}
|
||||
if urls.is_empty() { None } else { Some(urls) }
|
||||
(None, None, if urls.is_empty() { None } else { Some(urls) })
|
||||
};
|
||||
|
||||
let audio_urls: Option<Vec<String>> = if has_reference_audio {
|
||||
@@ -439,9 +489,17 @@ fn build_batch_request(req: WorkflowRunTaskRequest) -> BatchRequest {
|
||||
let face_blur_mode = match req.use_face_blur_hack {
|
||||
Some(true) => Some("on"),
|
||||
Some(false) => Some("off"),
|
||||
None if req.model_type.always_sends_default_fields() => Some("off"),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let output_resolution = if req.model_type.always_sends_default_fields() {
|
||||
let resolution = req.output_resolution.unwrap_or(KinoviOutputResolutionRaw::SevenTwentyP);
|
||||
Some(resolution.as_explicit_api_str())
|
||||
} else {
|
||||
req.output_resolution.and_then(|r| r.as_api_str())
|
||||
};
|
||||
|
||||
let batch_count_value = req.batch_count.as_u8();
|
||||
let batch_count = if batch_count_value > 1 { Some(batch_count_value) } else { None };
|
||||
|
||||
@@ -483,9 +541,11 @@ fn build_batch_request(req: WorkflowRunTaskRequest) -> BatchRequest {
|
||||
duration,
|
||||
mode,
|
||||
happyhorse_mode,
|
||||
output_resolution: req.output_resolution.and_then(|r| r.as_api_str()),
|
||||
output_resolution,
|
||||
face_blur_mode,
|
||||
character_ids: req.character_ids,
|
||||
image_urls,
|
||||
video_urls,
|
||||
uploaded_urls,
|
||||
audio_urls,
|
||||
batch_count,
|
||||
@@ -545,6 +605,8 @@ mod tests {
|
||||
output_resolution: None,
|
||||
face_blur_mode: None,
|
||||
character_ids: None,
|
||||
image_urls: None,
|
||||
video_urls: None,
|
||||
uploaded_urls: None,
|
||||
audio_urls: None,
|
||||
batch_count: None,
|
||||
@@ -594,6 +656,8 @@ mod tests {
|
||||
output_resolution,
|
||||
face_blur_mode: None,
|
||||
character_ids: None,
|
||||
image_urls: None,
|
||||
video_urls: None,
|
||||
uploaded_urls: None,
|
||||
audio_urls: None,
|
||||
batch_count: None,
|
||||
@@ -705,6 +769,130 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Seedance 2.5 Preview request shape ──
|
||||
//
|
||||
// 2.5 Preview differs from the other models on the wire: a
|
||||
// `seedance25-preview-video-generation` businessType, a
|
||||
// `seedance2-5-preview` model, an `aspectRatio` ratio string, `mode` always
|
||||
// "reference" (even with no references), `outputResolution` and
|
||||
// `faceBlurMode` always sent (including their "720p" / "off" defaults), and
|
||||
// references split into `imageUrls` / `videoUrls` with `uploadedUrls`
|
||||
// mirroring just the images.
|
||||
|
||||
mod seedance_2p5_preview_shape_tests {
|
||||
use super::*;
|
||||
|
||||
fn preview_request(
|
||||
output_resolution: Option<KinoviOutputResolutionRaw>,
|
||||
reference_image_urls: Option<Vec<String>>,
|
||||
reference_video_urls: Option<Vec<String>>,
|
||||
reference_audio_urls: Option<Vec<String>>,
|
||||
) -> WorkflowRunTaskRequest {
|
||||
WorkflowRunTaskRequest {
|
||||
model_type: KinoviModelTypeRaw::Seedance2p5Preview,
|
||||
prompt: "A man is running from a t-rex".to_string(),
|
||||
aspect_ratio: KinoviAspectRatioRaw::Landscape16x9,
|
||||
output_resolution,
|
||||
duration_seconds: 4,
|
||||
batch_count: KinoviBatchCountRaw::One,
|
||||
start_frame_url: None,
|
||||
end_frame_url: None,
|
||||
reference_image_urls,
|
||||
reference_video_urls,
|
||||
reference_audio_urls,
|
||||
character_ids: None,
|
||||
use_face_blur_hack: None,
|
||||
bitrate: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_to_video_matches_observed_request() {
|
||||
// Mirrors external/requests/sites/kinovi.ai/2026-07-31-seedance2p5/1_seedance2p5.txt.
|
||||
let body = build_batch_request(preview_request(
|
||||
Some(KinoviOutputResolutionRaw::FourEightyP), None, None, None));
|
||||
let json = serde_json::to_string(&body).unwrap();
|
||||
assert!(json.contains(r#""businessType":"seedance25-preview-video-generation""#), "{json}");
|
||||
assert!(json.contains(r#""model":"seedance2-5-preview""#), "{json}");
|
||||
assert!(json.contains(r#""aspectRatio":"16:9""#), "{json}");
|
||||
assert!(json.contains(r#""duration":"4s""#), "{json}");
|
||||
assert!(json.contains(r#""outputResolution":"480p""#), "{json}");
|
||||
assert!(json.contains(r#""contentMode":"normal""#), "{json}");
|
||||
// 2.5 Preview does NOT send the ratio-string `resolution` field.
|
||||
assert!(!json.contains(r#""resolution":"#), "{json}");
|
||||
// No references attached: no URL fields at all.
|
||||
assert!(!json.contains("imageUrls"), "{json}");
|
||||
assert!(!json.contains("videoUrls"), "{json}");
|
||||
assert!(!json.contains("uploadedUrls"), "{json}");
|
||||
assert!(!json.contains("audioUrls"), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mode_is_reference_even_without_references() {
|
||||
let body = build_batch_request(preview_request(None, None, None, None));
|
||||
let json = serde_json::to_string(&body).unwrap();
|
||||
assert!(json.contains(r#""mode":"reference""#), "{json}");
|
||||
assert!(!json.contains("keyframe"), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_720p_and_face_blur_off_are_sent_explicitly() {
|
||||
let body = build_batch_request(preview_request(None, None, None, None));
|
||||
let json = serde_json::to_string(&body).unwrap();
|
||||
assert!(json.contains(r#""outputResolution":"720p""#), "{json}");
|
||||
assert!(json.contains(r#""faceBlurMode":"off""#), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_references_fill_image_urls_and_uploaded_urls() {
|
||||
let images = vec![
|
||||
"https://static.seedance2-pro.com/materials/a.jpg".to_string(),
|
||||
"https://static.seedance2-pro.com/materials/b.png".to_string(),
|
||||
];
|
||||
let body = build_batch_request(preview_request(
|
||||
Some(KinoviOutputResolutionRaw::SevenTwentyP), Some(images), None, None));
|
||||
let json = serde_json::to_string(&body).unwrap();
|
||||
let expected_urls = r#"["https://static.seedance2-pro.com/materials/a.jpg","https://static.seedance2-pro.com/materials/b.png"]"#;
|
||||
assert!(json.contains(&format!(r#""imageUrls":{expected_urls}"#)), "{json}");
|
||||
// `uploadedUrls` mirrors the images.
|
||||
assert!(json.contains(&format!(r#""uploadedUrls":{expected_urls}"#)), "{json}");
|
||||
assert!(!json.contains("videoUrls"), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn video_and_audio_references_use_their_own_fields() {
|
||||
// Mirrors 3_seedance2p5_third.txt: images + video + audio. The video
|
||||
// and audio URLs are NOT mirrored into `uploadedUrls`.
|
||||
let body = build_batch_request(preview_request(
|
||||
Some(KinoviOutputResolutionRaw::FourEightyP),
|
||||
Some(vec!["https://static.seedance2-pro.com/materials/img.jpg".to_string()]),
|
||||
Some(vec!["https://static.seedance2-pro.com/materials/dog.mp4".to_string()]),
|
||||
Some(vec!["https://static.seedance2-pro.com/materials/bark.wav".to_string()]),
|
||||
));
|
||||
let json = serde_json::to_string(&body).unwrap();
|
||||
assert!(json.contains(r#""imageUrls":["https://static.seedance2-pro.com/materials/img.jpg"]"#), "{json}");
|
||||
assert!(json.contains(r#""videoUrls":["https://static.seedance2-pro.com/materials/dog.mp4"]"#), "{json}");
|
||||
assert!(json.contains(r#""audioUrls":["https://static.seedance2-pro.com/materials/bark.wav"]"#), "{json}");
|
||||
assert!(json.contains(r#""uploadedUrls":["https://static.seedance2-pro.com/materials/img.jpg"]"#), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_reference_lists_send_no_url_fields() {
|
||||
let body = build_batch_request(preview_request(
|
||||
None, Some(vec![]), Some(vec![]), None));
|
||||
let json = serde_json::to_string(&body).unwrap();
|
||||
assert!(!json.contains("imageUrls"), "{json}");
|
||||
assert!(!json.contains("videoUrls"), "{json}");
|
||||
assert!(!json.contains("uploadedUrls"), "{json}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_string_and_business_type() {
|
||||
assert_eq!(KinoviModelTypeRaw::Seedance2p5Preview.as_api_str(), "seedance2-5-preview");
|
||||
assert_eq!(KinoviModelTypeRaw::Seedance2p5Preview.business_type(), "seedance25-preview-video-generation");
|
||||
}
|
||||
}
|
||||
|
||||
// ── 2026-06-24 request-shape change ──
|
||||
//
|
||||
// The aspect ratio is now a ratio string ("16:9"). Seedance Pro/Fast keep it
|
||||
|
||||
Reference in new issue
Block a user