Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5a2b36525 | ||
|
|
e3c553ff2c | ||
|
|
094d33e405 |
No files matched your search
@@ -0,0 +1,96 @@
|
||||
# Wan 3.0 pricing and September 23 promotion
|
||||
|
||||
Last verified: **2026-09-18**. Recheck after **2026-09-23** (starting September 24).
|
||||
|
||||
The code and tests intentionally use the promotional Wan 3.0 rates below.
|
||||
Prices stay at these values until a reviewed code change; there is no automatic
|
||||
date-based switch. Kinovi advertises 30% off until September 23 without specifying
|
||||
the cutoff time or timezone. Confirm the live prices when updating.
|
||||
[Kinovi promotion and pricing](https://kinovi.ai/models/wan3-text-to-video)
|
||||
|
||||
## Rates currently used
|
||||
|
||||
All values are **Kinovi credits per output second**. Each family's rates apply
|
||||
to text-to-video, image-to-video, and reference-to-video. Reference media does
|
||||
not add billed input seconds. Sources for regular Wan:
|
||||
[text](https://kinovi.ai/models/wan3-text-to-video),
|
||||
[image](https://kinovi.ai/models/wan3-image-to-video),
|
||||
[reference](https://kinovi.ai/models/wan3-ref-to-video).
|
||||
|
||||
| Family | Resolution | Credits/second | Current status |
|
||||
|---------------|------------|----------------|--------------------------------|
|
||||
| Wan 3.0 | 480p | 9.98 | Promotional until Sep 23 |
|
||||
| Wan 3.0 | 720p | 19.96 | Promotional until Sep 23 |
|
||||
| Wan 3.0 | 1080p | 39.91 | Promotional until Sep 23 |
|
||||
| Wan 3.0 Prime | 480p | 18.86 | No advertised Sep 23 promotion |
|
||||
| Wan 3.0 Prime | 720p | 38.83 | No advertised Sep 23 promotion |
|
||||
| Wan 3.0 Prime | 1080p | 77.66 | No advertised Sep 23 promotion |
|
||||
|
||||
Prime sources:
|
||||
[text](https://kinovi.ai/models/wan3-prime-text-to-video),
|
||||
[image](https://kinovi.ai/models/wan3-prime-image-to-video),
|
||||
[reference](https://kinovi.ai/models/wan3-prime-ref-to-video).
|
||||
Prime 480p for 30 seconds is **565.8 credits**; the original supplied reference
|
||||
example's 568.8 was a typo. Recheck Prime independently; the regular Wan
|
||||
promotion ending does not establish a Prime price change.
|
||||
|
||||
The promotional rates already include the discount. Total credits are the
|
||||
selected rate multiplied by output seconds. Both pricing tiers currently use
|
||||
the same credit rates; only their credit purchase rates differ. The client uses
|
||||
192.98 credits/USD for Consumer and 243.16 for Enterprise, defined in
|
||||
[pricing constants](src/pricing/constants.rs).
|
||||
[KinoviPricingTier::cost_from_credits](src/pricing/kinovi_pricing_tier.rs) rounds
|
||||
the total to hundredths of a credit and calculates fractional, floor, and ceiling
|
||||
USD cents. Use those purchase rates for client costs; Kinovi's displayed USD
|
||||
prices use a different conversion.
|
||||
|
||||
## Advertised non-promotional rates to recheck
|
||||
|
||||
These are the crossed-out prices shown alongside the promotion on September 18.
|
||||
They are **reference values for the later update**, not active calculator rates
|
||||
or a guarantee of what Kinovi will charge after the promotion.
|
||||
The same values appear on the regular Wan
|
||||
[text](https://kinovi.ai/models/wan3-text-to-video),
|
||||
[image](https://kinovi.ai/models/wan3-image-to-video), and
|
||||
[reference](https://kinovi.ai/models/wan3-ref-to-video) pricing pages.
|
||||
|
||||
| Resolution | Current promotional credits/second | Advertised non-promotional credits/second |
|
||||
|------------|------------------------------------|-------------------------------------------|
|
||||
| 480p | 9.98 | 14.2571 |
|
||||
| 720p | 19.96 | 28.5143 |
|
||||
| 1080p | 39.91 | 57.0143 |
|
||||
|
||||
## How to update after September 23
|
||||
|
||||
1. Reopen the six model pages above and confirm the promotion ended, the exact
|
||||
credit rates, and total-credit rounding. Check consumer quotes for multiple
|
||||
durations and every resolution; the web client uses the consumer workflow.
|
||||
Record the verification date and evidence in this document.
|
||||
2. Update `WAN_CREDIT_HUNDREDTHS_PER_SECOND` and `Wan3p0Model::calculate_costs`
|
||||
in [wan_3p0.rs](src/generate/video/wan_3p0.rs). The current table is
|
||||
`[998, 1996, 3991]` in 480p/720p/1080p order. **The advertised replacement
|
||||
rates have four decimal places:** the existing hundredths representation
|
||||
cannot preserve them. If confirmed, use a sufficient fixed-point scale
|
||||
(for example 10,000), rename the constants to match their units, and adjust
|
||||
the final divisor. Preserve rate precision until after multiplying by
|
||||
duration; verify provider rounding before changing the shared credit
|
||||
conversion. If both families change scale, rescale the Prime integers while
|
||||
preserving Prime's monetary rates unless a separate price change is confirmed.
|
||||
3. Update the literal expectations in
|
||||
[wan_3p0_tests.rs](src/generate/video/wan_3p0_tests.rs): `WAN_CREDITS`,
|
||||
`WAN_CENTS`, the `199.6` regular `reference_media_tests!` argument (720p/10s),
|
||||
and the `99.8` regular image `check!` argument (720p/5s). The default-price
|
||||
and seed/audio tests already read the literal tables. Keep expected prices
|
||||
independent of production rate constants and assert both pricing tiers.
|
||||
Update Prime expectations only if its verified monetary rates change.
|
||||
4. Update this document and the dated comments beside the production constants
|
||||
and test tables. Keep the promotional snapshot as historical context.
|
||||
5. Run from the repository root:
|
||||
|
||||
```sh
|
||||
cargo test --offline -p kinovi_web_client --lib wan_3p0_tests
|
||||
cargo test --offline -p kinovi_web_client --lib
|
||||
```
|
||||
|
||||
The Wan HTTP tests use a local server and need permission to bind localhost.
|
||||
These commands leave the existing ignored live-generation tests ignored.
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
//! Wan 3.0 image-to-video through the Kinovi consumer workflow endpoint.
|
||||
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::generate::video::wan_3p0::{BUSINESS_TYPE, Wan3p0ApiParams, Wan3p0Model, invalid_field};
|
||||
use crate::pricing::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::pricing::kinovi_cost_calculator_trait::KinoviCostCalculatorTrait;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
use crate::requests::workflow_run_task::workflow_run_task::{workflow_run_task_custom, WorkflowRunTaskCustomArgs};
|
||||
|
||||
pub use crate::generate::video::wan_3p0::{KinoviWan3p0AspectRatio, KinoviWan3p0OutputResolution};
|
||||
pub use crate::requests::workflow_run_task::workflow_run_task::WorkflowRunTaskResponse as GenerateWan3p0ImageToVideoResponse;
|
||||
|
||||
pub struct GenerateWan3p0ImageToVideoArgs<'a> {
|
||||
pub request: GenerateWan3p0ImageToVideoRequest,
|
||||
pub session: &'a KinoviWebSession,
|
||||
pub maybe_host_override: Option<KinoviHost>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerateWan3p0ImageToVideoRequest {
|
||||
/// Up to 20,000 characters; may be empty when media is supplied.
|
||||
pub prompt: String,
|
||||
/// None resolves to 16:9.
|
||||
pub maybe_aspect_ratio: Option<KinoviWan3p0AspectRatio>,
|
||||
/// None resolves to 720p for both pricing and generation.
|
||||
pub maybe_output_resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
/// Any whole-second duration from 2 through 30 (not just the UI presets).
|
||||
pub duration_seconds: u8,
|
||||
/// Optional noise seed, inclusive range 0..=2147483647.
|
||||
pub maybe_seed: Option<u32>,
|
||||
/// None keeps Kinovi's default generated soundtrack; false disables it.
|
||||
pub maybe_generate_audio: Option<bool>,
|
||||
/// Required for generation; optional so costs can be estimated without media.
|
||||
pub maybe_start_frame_url: Option<String>,
|
||||
/// Optional final keyframe. Requires a start frame.
|
||||
pub maybe_end_frame_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for GenerateWan3p0ImageToVideoRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prompt: String::new(),
|
||||
maybe_aspect_ratio: None,
|
||||
maybe_output_resolution: None,
|
||||
duration_seconds: 5,
|
||||
maybe_seed: None,
|
||||
maybe_generate_audio: None,
|
||||
maybe_start_frame_url: None,
|
||||
maybe_end_frame_url: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KinoviCostCalculatorTrait for GenerateWan3p0ImageToVideoRequest {
|
||||
type Cost = KinoviFractionalGenerationCost;
|
||||
|
||||
/// Prices output seconds only. Images, video/audio references, seed, and
|
||||
/// aspect ratio do not change the credit charge. Both tiers use the same
|
||||
/// credit rate and their respective credit-to-USD conversion.
|
||||
fn calculate_costs(&self, tier: KinoviPricingTier) -> Self::Cost {
|
||||
Wan3p0Model::ImageToVideo.calculate_costs(self.maybe_output_resolution, self.duration_seconds, tier)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerateWan3p0ImageToVideoRequest {
|
||||
pub(super) fn build_api_params(self) -> Result<Wan3p0ApiParams, KinoviWebError> {
|
||||
if self.maybe_end_frame_url.is_some() && self.maybe_start_frame_url.is_none() {
|
||||
return Err(invalid_field("maybe_end_frame_url", "", "an end frame requires a start frame"));
|
||||
}
|
||||
let mut params = Wan3p0ApiParams::new(
|
||||
Wan3p0Model::ImageToVideo,
|
||||
self.prompt,
|
||||
self.maybe_aspect_ratio,
|
||||
self.maybe_output_resolution,
|
||||
self.duration_seconds,
|
||||
self.maybe_seed,
|
||||
self.maybe_generate_audio,
|
||||
)?;
|
||||
params.uploaded_urls = Some(self.maybe_start_frame_url.into_iter().chain(self.maybe_end_frame_url).collect());
|
||||
params.validate_media(self.duration_seconds, None)?;
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_wan_3p0_image_to_video(
|
||||
args: GenerateWan3p0ImageToVideoArgs<'_>,
|
||||
) -> Result<GenerateWan3p0ImageToVideoResponse, KinoviWebError> {
|
||||
workflow_run_task_custom(WorkflowRunTaskCustomArgs {
|
||||
business_type: BUSINESS_TYPE,
|
||||
api_params: args.request.build_api_params()?,
|
||||
session: args.session,
|
||||
host_override: args.maybe_host_override,
|
||||
})
|
||||
.await
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
//! Wan 3.0 Prime image-to-video through the Kinovi consumer workflow endpoint.
|
||||
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::generate::video::wan_3p0::{BUSINESS_TYPE, Wan3p0ApiParams, Wan3p0Model, invalid_field};
|
||||
use crate::pricing::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::pricing::kinovi_cost_calculator_trait::KinoviCostCalculatorTrait;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
use crate::requests::workflow_run_task::workflow_run_task::{workflow_run_task_custom, WorkflowRunTaskCustomArgs};
|
||||
|
||||
pub use crate::generate::video::wan_3p0::{KinoviWan3p0AspectRatio, KinoviWan3p0OutputResolution};
|
||||
pub use crate::requests::workflow_run_task::workflow_run_task::WorkflowRunTaskResponse as GenerateWan3p0PrimeImageToVideoResponse;
|
||||
|
||||
pub struct GenerateWan3p0PrimeImageToVideoArgs<'a> {
|
||||
pub request: GenerateWan3p0PrimeImageToVideoRequest,
|
||||
pub session: &'a KinoviWebSession,
|
||||
pub maybe_host_override: Option<KinoviHost>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerateWan3p0PrimeImageToVideoRequest {
|
||||
/// Up to 20,000 characters; may be empty when media is supplied.
|
||||
pub prompt: String,
|
||||
/// None resolves to 16:9.
|
||||
pub maybe_aspect_ratio: Option<KinoviWan3p0AspectRatio>,
|
||||
/// None resolves to 720p for both pricing and generation.
|
||||
pub maybe_output_resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
/// Any whole-second duration from 2 through 30 (not just the UI presets).
|
||||
pub duration_seconds: u8,
|
||||
/// Optional noise seed, inclusive range 0..=2147483647.
|
||||
pub maybe_seed: Option<u32>,
|
||||
/// None keeps Kinovi's default generated soundtrack; false disables it.
|
||||
pub maybe_generate_audio: Option<bool>,
|
||||
/// Required for generation; optional so costs can be estimated without media.
|
||||
pub maybe_start_frame_url: Option<String>,
|
||||
/// Optional final keyframe. Requires a start frame.
|
||||
pub maybe_end_frame_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for GenerateWan3p0PrimeImageToVideoRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prompt: String::new(),
|
||||
maybe_aspect_ratio: None,
|
||||
maybe_output_resolution: None,
|
||||
duration_seconds: 5,
|
||||
maybe_seed: None,
|
||||
maybe_generate_audio: None,
|
||||
maybe_start_frame_url: None,
|
||||
maybe_end_frame_url: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KinoviCostCalculatorTrait for GenerateWan3p0PrimeImageToVideoRequest {
|
||||
type Cost = KinoviFractionalGenerationCost;
|
||||
|
||||
/// Prices output seconds only. Images, video/audio references, seed, and
|
||||
/// aspect ratio do not change the credit charge. Both tiers use the same
|
||||
/// credit rate and their respective credit-to-USD conversion.
|
||||
fn calculate_costs(&self, tier: KinoviPricingTier) -> Self::Cost {
|
||||
Wan3p0Model::PrimeImageToVideo.calculate_costs(self.maybe_output_resolution, self.duration_seconds, tier)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerateWan3p0PrimeImageToVideoRequest {
|
||||
pub(super) fn build_api_params(self) -> Result<Wan3p0ApiParams, KinoviWebError> {
|
||||
if self.maybe_end_frame_url.is_some() && self.maybe_start_frame_url.is_none() {
|
||||
return Err(invalid_field("maybe_end_frame_url", "", "an end frame requires a start frame"));
|
||||
}
|
||||
let mut params = Wan3p0ApiParams::new(
|
||||
Wan3p0Model::PrimeImageToVideo,
|
||||
self.prompt,
|
||||
self.maybe_aspect_ratio,
|
||||
self.maybe_output_resolution,
|
||||
self.duration_seconds,
|
||||
self.maybe_seed,
|
||||
self.maybe_generate_audio,
|
||||
)?;
|
||||
params.uploaded_urls = Some(self.maybe_start_frame_url.into_iter().chain(self.maybe_end_frame_url).collect());
|
||||
params.validate_media(self.duration_seconds, None)?;
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_wan_3p0_prime_image_to_video(
|
||||
args: GenerateWan3p0PrimeImageToVideoArgs<'_>,
|
||||
) -> Result<GenerateWan3p0PrimeImageToVideoResponse, KinoviWebError> {
|
||||
workflow_run_task_custom(WorkflowRunTaskCustomArgs {
|
||||
business_type: BUSINESS_TYPE,
|
||||
api_params: args.request.build_api_params()?,
|
||||
session: args.session,
|
||||
host_override: args.maybe_host_override,
|
||||
})
|
||||
.await
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
//! Wan 3.0 Prime ref-to-video through the Kinovi consumer workflow endpoint.
|
||||
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::generate::video::wan_3p0::{BUSINESS_TYPE, Wan3p0ApiParams, Wan3p0Model};
|
||||
use crate::pricing::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::pricing::kinovi_cost_calculator_trait::KinoviCostCalculatorTrait;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
use crate::requests::workflow_run_task::workflow_run_task::{workflow_run_task_custom, WorkflowRunTaskCustomArgs};
|
||||
|
||||
pub use crate::generate::video::wan_3p0::{KinoviWan3p0AspectRatio, KinoviWan3p0OutputResolution};
|
||||
pub use crate::requests::workflow_run_task::workflow_run_task::WorkflowRunTaskResponse as GenerateWan3p0PrimeRefToVideoResponse;
|
||||
|
||||
pub struct GenerateWan3p0PrimeRefToVideoArgs<'a> {
|
||||
pub request: GenerateWan3p0PrimeRefToVideoRequest,
|
||||
pub session: &'a KinoviWebSession,
|
||||
pub maybe_host_override: Option<KinoviHost>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerateWan3p0PrimeRefToVideoRequest {
|
||||
/// Up to 20,000 characters; may be empty when media is supplied.
|
||||
pub prompt: String,
|
||||
/// None resolves to 16:9.
|
||||
pub maybe_aspect_ratio: Option<KinoviWan3p0AspectRatio>,
|
||||
/// None resolves to 720p for both pricing and generation.
|
||||
pub maybe_output_resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
/// Any whole-second duration from 2 through 30 (not just the UI presets).
|
||||
pub duration_seconds: u8,
|
||||
/// Optional noise seed, inclusive range 0..=2147483647.
|
||||
pub maybe_seed: Option<u32>,
|
||||
/// None keeps Kinovi's default generated soundtrack; false disables it.
|
||||
pub maybe_generate_audio: Option<bool>,
|
||||
/// Up to 10 reference images, addressed as Image 1, Image 2, etc.
|
||||
pub maybe_reference_image_urls: Option<Vec<String>>,
|
||||
/// Up to 5 videos, each 1-15s, totaling at most 15s.
|
||||
pub maybe_reference_video_urls: Option<Vec<String>>,
|
||||
/// Up to 5 audio files, each 1-15s, totaling at most 15s.
|
||||
/// Actual file durations are validated by Kinovi.
|
||||
pub maybe_reference_audio_urls: Option<Vec<String>>,
|
||||
/// Optional measured TOTAL reference-video duration, used only for validation.
|
||||
/// Reference duration + output duration must not exceed 30s. This metadata
|
||||
/// is not sent or billed. Without it, Kinovi validates the actual durations.
|
||||
pub maybe_total_reference_video_duration_millis: Option<u32>,
|
||||
}
|
||||
|
||||
impl Default for GenerateWan3p0PrimeRefToVideoRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prompt: String::new(),
|
||||
maybe_aspect_ratio: None,
|
||||
maybe_output_resolution: None,
|
||||
duration_seconds: 5,
|
||||
maybe_seed: None,
|
||||
maybe_generate_audio: None,
|
||||
maybe_reference_image_urls: None,
|
||||
maybe_reference_video_urls: None,
|
||||
maybe_reference_audio_urls: None,
|
||||
maybe_total_reference_video_duration_millis: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KinoviCostCalculatorTrait for GenerateWan3p0PrimeRefToVideoRequest {
|
||||
type Cost = KinoviFractionalGenerationCost;
|
||||
|
||||
/// Prices output seconds only. Images, video/audio references, seed, and
|
||||
/// aspect ratio do not change the credit charge. Both tiers use the same
|
||||
/// credit rate and their respective credit-to-USD conversion.
|
||||
fn calculate_costs(&self, tier: KinoviPricingTier) -> Self::Cost {
|
||||
Wan3p0Model::PrimeRefToVideo.calculate_costs(self.maybe_output_resolution, self.duration_seconds, tier)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerateWan3p0PrimeRefToVideoRequest {
|
||||
pub(super) fn build_api_params(self) -> Result<Wan3p0ApiParams, KinoviWebError> {
|
||||
let mut params = Wan3p0ApiParams::new(
|
||||
Wan3p0Model::PrimeRefToVideo,
|
||||
self.prompt,
|
||||
self.maybe_aspect_ratio,
|
||||
self.maybe_output_resolution,
|
||||
self.duration_seconds,
|
||||
self.maybe_seed,
|
||||
self.maybe_generate_audio,
|
||||
)?;
|
||||
params.uploaded_urls = self.maybe_reference_image_urls;
|
||||
params.video_urls = self.maybe_reference_video_urls;
|
||||
params.audio_urls = self.maybe_reference_audio_urls;
|
||||
params.validate_media(self.duration_seconds, self.maybe_total_reference_video_duration_millis)?;
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_wan_3p0_prime_ref_to_video(
|
||||
args: GenerateWan3p0PrimeRefToVideoArgs<'_>,
|
||||
) -> Result<GenerateWan3p0PrimeRefToVideoResponse, KinoviWebError> {
|
||||
workflow_run_task_custom(WorkflowRunTaskCustomArgs {
|
||||
business_type: BUSINESS_TYPE,
|
||||
api_params: args.request.build_api_params()?,
|
||||
session: args.session,
|
||||
host_override: args.maybe_host_override,
|
||||
})
|
||||
.await
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
//! Wan 3.0 Prime text-to-video through the Kinovi consumer workflow endpoint.
|
||||
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::generate::video::wan_3p0::{BUSINESS_TYPE, Wan3p0ApiParams, Wan3p0Model};
|
||||
use crate::pricing::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::pricing::kinovi_cost_calculator_trait::KinoviCostCalculatorTrait;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
use crate::requests::workflow_run_task::workflow_run_task::{workflow_run_task_custom, WorkflowRunTaskCustomArgs};
|
||||
|
||||
pub use crate::generate::video::wan_3p0::{KinoviWan3p0AspectRatio, KinoviWan3p0OutputResolution};
|
||||
pub use crate::requests::workflow_run_task::workflow_run_task::WorkflowRunTaskResponse as GenerateWan3p0PrimeTextToVideoResponse;
|
||||
|
||||
pub struct GenerateWan3p0PrimeTextToVideoArgs<'a> {
|
||||
pub request: GenerateWan3p0PrimeTextToVideoRequest,
|
||||
pub session: &'a KinoviWebSession,
|
||||
pub maybe_host_override: Option<KinoviHost>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerateWan3p0PrimeTextToVideoRequest {
|
||||
/// Required prompt, up to 20,000 characters.
|
||||
pub prompt: String,
|
||||
/// None resolves to 16:9.
|
||||
pub maybe_aspect_ratio: Option<KinoviWan3p0AspectRatio>,
|
||||
/// None resolves to 720p for both pricing and generation.
|
||||
pub maybe_output_resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
/// Any whole-second duration from 2 through 30 (not just the UI presets).
|
||||
pub duration_seconds: u8,
|
||||
/// Optional noise seed, inclusive range 0..=2147483647.
|
||||
pub maybe_seed: Option<u32>,
|
||||
/// None keeps Kinovi's default generated soundtrack; false disables it.
|
||||
pub maybe_generate_audio: Option<bool>,
|
||||
}
|
||||
|
||||
impl Default for GenerateWan3p0PrimeTextToVideoRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prompt: String::new(),
|
||||
maybe_aspect_ratio: None,
|
||||
maybe_output_resolution: None,
|
||||
duration_seconds: 5,
|
||||
maybe_seed: None,
|
||||
maybe_generate_audio: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KinoviCostCalculatorTrait for GenerateWan3p0PrimeTextToVideoRequest {
|
||||
type Cost = KinoviFractionalGenerationCost;
|
||||
|
||||
/// Prices output seconds only. Images, video/audio references, seed, and
|
||||
/// aspect ratio do not change the credit charge. Both tiers use the same
|
||||
/// credit rate and their respective credit-to-USD conversion.
|
||||
fn calculate_costs(&self, tier: KinoviPricingTier) -> Self::Cost {
|
||||
Wan3p0Model::PrimeTextToVideo.calculate_costs(self.maybe_output_resolution, self.duration_seconds, tier)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerateWan3p0PrimeTextToVideoRequest {
|
||||
pub(super) fn build_api_params(self) -> Result<Wan3p0ApiParams, KinoviWebError> {
|
||||
let mut params = Wan3p0ApiParams::new(
|
||||
Wan3p0Model::PrimeTextToVideo,
|
||||
self.prompt,
|
||||
self.maybe_aspect_ratio,
|
||||
self.maybe_output_resolution,
|
||||
self.duration_seconds,
|
||||
self.maybe_seed,
|
||||
self.maybe_generate_audio,
|
||||
)?;
|
||||
params.validate_media(self.duration_seconds, None)?;
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_wan_3p0_prime_text_to_video(
|
||||
args: GenerateWan3p0PrimeTextToVideoArgs<'_>,
|
||||
) -> Result<GenerateWan3p0PrimeTextToVideoResponse, KinoviWebError> {
|
||||
workflow_run_task_custom(WorkflowRunTaskCustomArgs {
|
||||
business_type: BUSINESS_TYPE,
|
||||
api_params: args.request.build_api_params()?,
|
||||
session: args.session,
|
||||
host_override: args.maybe_host_override,
|
||||
})
|
||||
.await
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
//! Wan 3.0 ref-to-video through the Kinovi consumer workflow endpoint.
|
||||
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::generate::video::wan_3p0::{BUSINESS_TYPE, Wan3p0ApiParams, Wan3p0Model};
|
||||
use crate::pricing::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::pricing::kinovi_cost_calculator_trait::KinoviCostCalculatorTrait;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
use crate::requests::workflow_run_task::workflow_run_task::{workflow_run_task_custom, WorkflowRunTaskCustomArgs};
|
||||
|
||||
pub use crate::generate::video::wan_3p0::{KinoviWan3p0AspectRatio, KinoviWan3p0OutputResolution};
|
||||
pub use crate::requests::workflow_run_task::workflow_run_task::WorkflowRunTaskResponse as GenerateWan3p0RefToVideoResponse;
|
||||
|
||||
pub struct GenerateWan3p0RefToVideoArgs<'a> {
|
||||
pub request: GenerateWan3p0RefToVideoRequest,
|
||||
pub session: &'a KinoviWebSession,
|
||||
pub maybe_host_override: Option<KinoviHost>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerateWan3p0RefToVideoRequest {
|
||||
/// Up to 20,000 characters; may be empty when media is supplied.
|
||||
pub prompt: String,
|
||||
/// None resolves to 16:9.
|
||||
pub maybe_aspect_ratio: Option<KinoviWan3p0AspectRatio>,
|
||||
/// None resolves to 720p for both pricing and generation.
|
||||
pub maybe_output_resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
/// Any whole-second duration from 2 through 30 (not just the UI presets).
|
||||
pub duration_seconds: u8,
|
||||
/// Optional noise seed, inclusive range 0..=2147483647.
|
||||
pub maybe_seed: Option<u32>,
|
||||
/// None keeps Kinovi's default generated soundtrack; false disables it.
|
||||
pub maybe_generate_audio: Option<bool>,
|
||||
/// Up to 10 reference images, addressed as Image 1, Image 2, etc.
|
||||
pub maybe_reference_image_urls: Option<Vec<String>>,
|
||||
/// Up to 5 videos, each 1-15s, totaling at most 15s.
|
||||
pub maybe_reference_video_urls: Option<Vec<String>>,
|
||||
/// Up to 5 audio files, each 1-15s, totaling at most 15s.
|
||||
/// Actual file durations are validated by Kinovi.
|
||||
pub maybe_reference_audio_urls: Option<Vec<String>>,
|
||||
/// Optional measured TOTAL reference-video duration, used only for validation.
|
||||
/// Reference duration + output duration must not exceed 30s. This metadata
|
||||
/// is not sent or billed. Without it, Kinovi validates the actual durations.
|
||||
pub maybe_total_reference_video_duration_millis: Option<u32>,
|
||||
}
|
||||
|
||||
impl Default for GenerateWan3p0RefToVideoRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prompt: String::new(),
|
||||
maybe_aspect_ratio: None,
|
||||
maybe_output_resolution: None,
|
||||
duration_seconds: 5,
|
||||
maybe_seed: None,
|
||||
maybe_generate_audio: None,
|
||||
maybe_reference_image_urls: None,
|
||||
maybe_reference_video_urls: None,
|
||||
maybe_reference_audio_urls: None,
|
||||
maybe_total_reference_video_duration_millis: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KinoviCostCalculatorTrait for GenerateWan3p0RefToVideoRequest {
|
||||
type Cost = KinoviFractionalGenerationCost;
|
||||
|
||||
/// Prices output seconds only. Images, video/audio references, seed, and
|
||||
/// aspect ratio do not change the credit charge. Both tiers use the same
|
||||
/// credit rate and their respective credit-to-USD conversion.
|
||||
fn calculate_costs(&self, tier: KinoviPricingTier) -> Self::Cost {
|
||||
Wan3p0Model::RefToVideo.calculate_costs(self.maybe_output_resolution, self.duration_seconds, tier)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerateWan3p0RefToVideoRequest {
|
||||
pub(super) fn build_api_params(self) -> Result<Wan3p0ApiParams, KinoviWebError> {
|
||||
let mut params = Wan3p0ApiParams::new(
|
||||
Wan3p0Model::RefToVideo,
|
||||
self.prompt,
|
||||
self.maybe_aspect_ratio,
|
||||
self.maybe_output_resolution,
|
||||
self.duration_seconds,
|
||||
self.maybe_seed,
|
||||
self.maybe_generate_audio,
|
||||
)?;
|
||||
params.uploaded_urls = self.maybe_reference_image_urls;
|
||||
params.video_urls = self.maybe_reference_video_urls;
|
||||
params.audio_urls = self.maybe_reference_audio_urls;
|
||||
params.validate_media(self.duration_seconds, self.maybe_total_reference_video_duration_millis)?;
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_wan_3p0_ref_to_video(
|
||||
args: GenerateWan3p0RefToVideoArgs<'_>,
|
||||
) -> Result<GenerateWan3p0RefToVideoResponse, KinoviWebError> {
|
||||
workflow_run_task_custom(WorkflowRunTaskCustomArgs {
|
||||
business_type: BUSINESS_TYPE,
|
||||
api_params: args.request.build_api_params()?,
|
||||
session: args.session,
|
||||
host_override: args.maybe_host_override,
|
||||
})
|
||||
.await
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
//! Wan 3.0 text-to-video through the Kinovi consumer workflow endpoint.
|
||||
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::generate::video::wan_3p0::{BUSINESS_TYPE, Wan3p0ApiParams, Wan3p0Model};
|
||||
use crate::pricing::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::pricing::kinovi_cost_calculator_trait::KinoviCostCalculatorTrait;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
use crate::requests::workflow_run_task::workflow_run_task::{workflow_run_task_custom, WorkflowRunTaskCustomArgs};
|
||||
|
||||
pub use crate::generate::video::wan_3p0::{KinoviWan3p0AspectRatio, KinoviWan3p0OutputResolution};
|
||||
pub use crate::requests::workflow_run_task::workflow_run_task::WorkflowRunTaskResponse as GenerateWan3p0TextToVideoResponse;
|
||||
|
||||
pub struct GenerateWan3p0TextToVideoArgs<'a> {
|
||||
pub request: GenerateWan3p0TextToVideoRequest,
|
||||
pub session: &'a KinoviWebSession,
|
||||
pub maybe_host_override: Option<KinoviHost>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GenerateWan3p0TextToVideoRequest {
|
||||
/// Required prompt, up to 20,000 characters.
|
||||
pub prompt: String,
|
||||
/// None resolves to 16:9.
|
||||
pub maybe_aspect_ratio: Option<KinoviWan3p0AspectRatio>,
|
||||
/// None resolves to 720p for both pricing and generation.
|
||||
pub maybe_output_resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
/// Any whole-second duration from 2 through 30 (not just the UI presets).
|
||||
pub duration_seconds: u8,
|
||||
/// Optional noise seed, inclusive range 0..=2147483647.
|
||||
pub maybe_seed: Option<u32>,
|
||||
/// None keeps Kinovi's default generated soundtrack; false disables it.
|
||||
pub maybe_generate_audio: Option<bool>,
|
||||
}
|
||||
|
||||
impl Default for GenerateWan3p0TextToVideoRequest {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prompt: String::new(),
|
||||
maybe_aspect_ratio: None,
|
||||
maybe_output_resolution: None,
|
||||
duration_seconds: 5,
|
||||
maybe_seed: None,
|
||||
maybe_generate_audio: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl KinoviCostCalculatorTrait for GenerateWan3p0TextToVideoRequest {
|
||||
type Cost = KinoviFractionalGenerationCost;
|
||||
|
||||
/// Prices output seconds only. Images, video/audio references, seed, and
|
||||
/// aspect ratio do not change the credit charge. Both tiers use the same
|
||||
/// credit rate and their respective credit-to-USD conversion.
|
||||
fn calculate_costs(&self, tier: KinoviPricingTier) -> Self::Cost {
|
||||
Wan3p0Model::TextToVideo.calculate_costs(self.maybe_output_resolution, self.duration_seconds, tier)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerateWan3p0TextToVideoRequest {
|
||||
pub(super) fn build_api_params(self) -> Result<Wan3p0ApiParams, KinoviWebError> {
|
||||
let mut params = Wan3p0ApiParams::new(
|
||||
Wan3p0Model::TextToVideo,
|
||||
self.prompt,
|
||||
self.maybe_aspect_ratio,
|
||||
self.maybe_output_resolution,
|
||||
self.duration_seconds,
|
||||
self.maybe_seed,
|
||||
self.maybe_generate_audio,
|
||||
)?;
|
||||
params.validate_media(self.duration_seconds, None)?;
|
||||
Ok(params)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_wan_3p0_text_to_video(
|
||||
args: GenerateWan3p0TextToVideoArgs<'_>,
|
||||
) -> Result<GenerateWan3p0TextToVideoResponse, KinoviWebError> {
|
||||
workflow_run_task_custom(WorkflowRunTaskCustomArgs {
|
||||
business_type: BUSINESS_TYPE,
|
||||
api_params: args.request.build_api_params()?,
|
||||
session: args.session,
|
||||
host_override: args.maybe_host_override,
|
||||
})
|
||||
.await
|
||||
}
|
||||
@@ -4,3 +4,13 @@ pub mod generate_seedance_2p0_fast;
|
||||
pub mod generate_seedance_2p0_mini;
|
||||
pub mod generate_seedance_2p5;
|
||||
pub mod generate_seedance_2p5_preview;
|
||||
pub mod generate_wan_3p0_text_to_video;
|
||||
pub mod generate_wan_3p0_image_to_video;
|
||||
pub mod generate_wan_3p0_ref_to_video;
|
||||
pub mod generate_wan_3p0_prime_text_to_video;
|
||||
pub mod generate_wan_3p0_prime_image_to_video;
|
||||
pub mod generate_wan_3p0_prime_ref_to_video;
|
||||
pub mod wan_3p0;
|
||||
|
||||
#[cfg(test)]
|
||||
mod wan_3p0_tests;
|
||||
@@ -0,0 +1,245 @@
|
||||
//! Shared options and wire format for Wan 3.0 and Wan 3.0 Prime.
|
||||
//!
|
||||
//! Schema: https://kinovi.ai/models/wan3-ref-to-video (checked 2026-09-18).
|
||||
//! All modes bill only OUTPUT seconds; reference media does not add a surcharge.
|
||||
//!
|
||||
//! Output accepts any whole-second duration from 2 through 30. Reference
|
||||
//! videos must each be 1-15s and total at most 15s; their total plus output
|
||||
//! duration must not exceed 30s. Thus 10s of video references allows at most
|
||||
//! 20s of output. Audio and image references do not consume this video budget.
|
||||
//! The optional measured reference duration enables local validation; otherwise
|
||||
//! Kinovi checks actual file durations. This client does not probe media URLs.
|
||||
//!
|
||||
//! Pricing sources (all three modalities share each family's rates):
|
||||
//! - https://kinovi.ai/models/wan3-text-to-video
|
||||
//! - https://kinovi.ai/models/wan3-prime-ref-to-video
|
||||
//! Pricing maintenance and the September 23 promotion: `costs_wan_3p0.md`
|
||||
//! at the crate root.
|
||||
|
||||
use serde_derive::Serialize;
|
||||
|
||||
use crate::error::kinovi_web_client_error::KinoviWebClientError;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::pricing::cost::kinovi_fractional_generation_cost::KinoviFractionalGenerationCost;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
|
||||
pub(super) const BUSINESS_TYPE: &str = "wan3-video-generation";
|
||||
pub const MAX_SEED: u32 = 2_147_483_647;
|
||||
pub const MIN_DURATION_SECONDS: u8 = 2;
|
||||
pub const MAX_DURATION_SECONDS: u8 = 30;
|
||||
pub const MAX_REFERENCE_VIDEO_DURATION_MILLIS: u32 = 15_000;
|
||||
|
||||
// Hundredths of a credit per OUTPUT second, as observed 2026-09-18.
|
||||
// Regular Wan intentionally uses the promotional rates (30% off until 2026-09-23).
|
||||
// TODO(2026-09-24): Recheck live pricing using costs_wan_3p0.md at the crate root.
|
||||
// That note records advertised replacement rates, precision needs, and test updates.
|
||||
// Keep these promotional rates until a reviewed update; no automatic date switch.
|
||||
// Prime 480p is 18.86/s, so 30s costs 565.8, not 568.8 credits.
|
||||
// No separate enterprise credit discount has been supplied for these models.
|
||||
const WAN_CREDIT_HUNDREDTHS_PER_SECOND: [u64; 3] = [998, 1996, 3991];
|
||||
const PRIME_CREDIT_HUNDREDTHS_PER_SECOND: [u64; 3] = [1886, 3883, 7766];
|
||||
|
||||
/// Shared by all six Wan operations. Defaults to 16:9.
|
||||
/// `adaptive` is REST-only for reference-to-video and is not a Studio option.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum KinoviWan3p0AspectRatio {
|
||||
#[default]
|
||||
Landscape16x9,
|
||||
Portrait9x16,
|
||||
Landscape4x3,
|
||||
Portrait3x4,
|
||||
Square1x1,
|
||||
}
|
||||
|
||||
/// Shared by regular and Prime Wan. Defaults to 720p, pinned on the wire.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum KinoviWan3p0OutputResolution {
|
||||
FourEightyP,
|
||||
#[default]
|
||||
SevenTwentyP,
|
||||
TenEightyP,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(super) enum Wan3p0Model {
|
||||
TextToVideo,
|
||||
ImageToVideo,
|
||||
RefToVideo,
|
||||
PrimeTextToVideo,
|
||||
PrimeImageToVideo,
|
||||
PrimeRefToVideo,
|
||||
}
|
||||
|
||||
/// Consumer tRPC shape, verified against the 2026-09-18 captures. Images
|
||||
/// use `uploadedUrls`; videos use BOTH `videoUrl` and `videoUrls`.
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(super) struct Wan3p0ApiParams {
|
||||
model: &'static str,
|
||||
content_mode: &'static str,
|
||||
face_blur_mode: &'static str,
|
||||
prompt: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
mode: Option<&'static str>,
|
||||
aspect_ratio: &'static str,
|
||||
duration: String,
|
||||
output_resolution: &'static str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
seed: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
audio: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub(super) uploaded_urls: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
video_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub(super) video_urls: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub(super) audio_urls: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl Wan3p0Model {
|
||||
pub(super) fn calculate_costs(
|
||||
self,
|
||||
resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
duration_seconds: u8,
|
||||
tier: KinoviPricingTier,
|
||||
) -> KinoviFractionalGenerationCost {
|
||||
let rates = match self {
|
||||
Self::TextToVideo | Self::ImageToVideo | Self::RefToVideo => WAN_CREDIT_HUNDREDTHS_PER_SECOND,
|
||||
Self::PrimeTextToVideo | Self::PrimeImageToVideo | Self::PrimeRefToVideo => PRIME_CREDIT_HUNDREDTHS_PER_SECOND,
|
||||
};
|
||||
let index = match resolution.unwrap_or_default() {
|
||||
KinoviWan3p0OutputResolution::FourEightyP => 0,
|
||||
KinoviWan3p0OutputResolution::SevenTwentyP => 1,
|
||||
KinoviWan3p0OutputResolution::TenEightyP => 2,
|
||||
};
|
||||
let credit_hundredths = rates[index] * u64::from(duration_seconds);
|
||||
tier.cost_from_credits(credit_hundredths as f64 / 100.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Wan3p0ApiParams {
|
||||
pub(super) fn new(
|
||||
model: Wan3p0Model,
|
||||
prompt: String,
|
||||
aspect_ratio: Option<KinoviWan3p0AspectRatio>,
|
||||
resolution: Option<KinoviWan3p0OutputResolution>,
|
||||
duration_seconds: u8,
|
||||
seed: Option<u32>,
|
||||
audio: Option<bool>,
|
||||
) -> Result<Self, KinoviWebError> {
|
||||
if !(MIN_DURATION_SECONDS..=MAX_DURATION_SECONDS).contains(&duration_seconds) {
|
||||
return Err(invalid_field("duration_seconds", duration_seconds, "must be between 2 and 30"));
|
||||
}
|
||||
if let Some(seed) = seed {
|
||||
if seed > MAX_SEED {
|
||||
return Err(invalid_field("maybe_seed", seed, "must be between 0 and 2147483647"));
|
||||
}
|
||||
}
|
||||
if prompt.chars().count() > 20_000 {
|
||||
return Err(invalid_field("prompt", prompt.chars().count(), "must not exceed 20000 characters"));
|
||||
}
|
||||
|
||||
let (model, mode) = match model {
|
||||
Wan3p0Model::TextToVideo => ("wan3.0-text-to-video", None),
|
||||
Wan3p0Model::ImageToVideo => ("wan3.0-image-to-video", Some("keyframe")),
|
||||
Wan3p0Model::RefToVideo => ("wan3.0-ref-to-video", Some("reference")),
|
||||
Wan3p0Model::PrimeTextToVideo => ("wan3.0-prime-text-to-video", None),
|
||||
Wan3p0Model::PrimeImageToVideo => ("wan3.0-prime-image-to-video", Some("keyframe")),
|
||||
Wan3p0Model::PrimeRefToVideo => ("wan3.0-prime-ref-to-video", Some("reference")),
|
||||
};
|
||||
Ok(Self {
|
||||
model,
|
||||
content_mode: "normal",
|
||||
face_blur_mode: "off",
|
||||
prompt,
|
||||
mode,
|
||||
aspect_ratio: match aspect_ratio.unwrap_or_default() {
|
||||
KinoviWan3p0AspectRatio::Landscape16x9 => "16:9",
|
||||
KinoviWan3p0AspectRatio::Portrait9x16 => "9:16",
|
||||
KinoviWan3p0AspectRatio::Landscape4x3 => "4:3",
|
||||
KinoviWan3p0AspectRatio::Portrait3x4 => "3:4",
|
||||
KinoviWan3p0AspectRatio::Square1x1 => "1:1",
|
||||
},
|
||||
duration: format!("{duration_seconds}s"),
|
||||
output_resolution: match resolution.unwrap_or_default() {
|
||||
KinoviWan3p0OutputResolution::FourEightyP => "480p",
|
||||
KinoviWan3p0OutputResolution::SevenTwentyP => "720p",
|
||||
KinoviWan3p0OutputResolution::TenEightyP => "1080p",
|
||||
},
|
||||
seed,
|
||||
audio,
|
||||
uploaded_urls: None,
|
||||
video_url: None,
|
||||
video_urls: None,
|
||||
audio_urls: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn validate_media(
|
||||
&mut self,
|
||||
duration_seconds: u8,
|
||||
maybe_total_reference_video_duration_millis: Option<u32>,
|
||||
) -> Result<(), KinoviWebError> {
|
||||
self.uploaded_urls = self.uploaded_urls.take().filter(|urls| !urls.is_empty());
|
||||
self.video_urls = self.video_urls.take().filter(|urls| !urls.is_empty());
|
||||
self.audio_urls = self.audio_urls.take().filter(|urls| !urls.is_empty());
|
||||
let image_count = self.uploaded_urls.as_ref().map_or(0, Vec::len);
|
||||
let video_count = self.video_urls.as_ref().map_or(0, Vec::len);
|
||||
let audio_count = self.audio_urls.as_ref().map_or(0, Vec::len);
|
||||
let max_images = if self.mode == Some("keyframe") { 2 } else { 10 };
|
||||
for (field, count, maximum) in [
|
||||
("maybe_reference_image_urls", image_count, max_images),
|
||||
("maybe_reference_video_urls", video_count, 5),
|
||||
("maybe_reference_audio_urls", audio_count, 5),
|
||||
] {
|
||||
if count > maximum {
|
||||
return Err(invalid_field(field, count, format!("at most {maximum} items are supported")));
|
||||
}
|
||||
}
|
||||
if self.mode == Some("keyframe") && image_count == 0 {
|
||||
return Err(invalid_field("maybe_start_frame_url", "", "image-to-video requires a start frame"));
|
||||
}
|
||||
if self.prompt.trim().is_empty() && image_count + video_count + audio_count == 0 {
|
||||
return Err(invalid_field("prompt", "", "a prompt is required when no media is supplied"));
|
||||
}
|
||||
for urls in [&self.uploaded_urls, &self.video_urls, &self.audio_urls].into_iter().flatten() {
|
||||
if urls.iter().any(|url| url.trim().is_empty()) {
|
||||
return Err(invalid_field("media_url", "", "media URLs must not be empty"));
|
||||
}
|
||||
}
|
||||
if video_count > 0 {
|
||||
// Without measured metadata, only enforce the known lower bound:
|
||||
// each reference video must be at least 1s. Kinovi validates actual
|
||||
// media durations; the client does not download/probe URLs here.
|
||||
let minimum_millis = video_count as u32 * 1_000;
|
||||
let input_millis = maybe_total_reference_video_duration_millis.unwrap_or(minimum_millis);
|
||||
if !(minimum_millis..=MAX_REFERENCE_VIDEO_DURATION_MILLIS).contains(&input_millis) {
|
||||
return Err(invalid_field(
|
||||
"maybe_total_reference_video_duration_millis",
|
||||
input_millis,
|
||||
"reference videos must each be 1-15s and total at most 15s",
|
||||
));
|
||||
}
|
||||
if input_millis + u32::from(duration_seconds) * 1_000 > 30_000 {
|
||||
return Err(invalid_field(
|
||||
"duration_seconds",
|
||||
duration_seconds,
|
||||
"reference-video duration plus output duration must not exceed 30s",
|
||||
));
|
||||
}
|
||||
self.video_url = self.video_urls.as_ref().and_then(|urls| urls.first()).cloned();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn invalid_field(field: &'static str, value: impl ToString, reason: impl Into<String>) -> KinoviWebError {
|
||||
KinoviWebClientError::InvalidRequestField {
|
||||
field,
|
||||
raw_value: value.to_string(),
|
||||
reason: reason.into(),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"model": "wan3.0-ref-to-video",
|
||||
"contentMode": "normal",
|
||||
"faceBlurMode": "off",
|
||||
"prompt": "A corgi eats a watermelon",
|
||||
"mode": "reference",
|
||||
"aspectRatio": "16:9",
|
||||
"duration": "5s",
|
||||
"outputResolution": "720p"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"model": "wan3.0-text-to-video",
|
||||
"contentMode": "normal",
|
||||
"faceBlurMode": "off",
|
||||
"prompt": "A shiba eats a pie",
|
||||
"aspectRatio": "16:9",
|
||||
"duration": "5s",
|
||||
"outputResolution": "720p"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"model": "wan3.0-prime-image-to-video",
|
||||
"contentMode": "normal",
|
||||
"faceBlurMode": "off",
|
||||
"prompt": "A lighthouse over the coast",
|
||||
"mode": "keyframe",
|
||||
"aspectRatio": "16:9",
|
||||
"duration": "5s",
|
||||
"outputResolution": "720p",
|
||||
"uploadedUrls": [
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789739927378-438b78db.png"
|
||||
]
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"model": "wan3.0-ref-to-video",
|
||||
"contentMode": "normal",
|
||||
"faceBlurMode": "off",
|
||||
"prompt": "The Image 2 is on the beach Video 1 . There's a lighthouse Image 1 . The shiba says Audio 1",
|
||||
"mode": "reference",
|
||||
"aspectRatio": "4:3",
|
||||
"duration": "5s",
|
||||
"outputResolution": "1080p",
|
||||
"videoUrl": "https://static.seedance2-pro.com/materials/20260918/1789740067508-9b952e67.mp4",
|
||||
"videoUrls": [
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789740067508-9b952e67.mp4"
|
||||
],
|
||||
"audioUrls": [
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789740228370-3f5d9623.wav"
|
||||
],
|
||||
"uploadedUrls": [
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789740059548-4149c254.png",
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789740077221-9702e67d.png"
|
||||
]
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"model": "wan3.0-prime-ref-to-video",
|
||||
"contentMode": "normal",
|
||||
"faceBlurMode": "off",
|
||||
"prompt": "There's a shop full of lanterns. the camera orbits.",
|
||||
"mode": "reference",
|
||||
"aspectRatio": "16:9",
|
||||
"duration": "10s",
|
||||
"outputResolution": "480p",
|
||||
"seed": 2028741236,
|
||||
"uploadedUrls": [
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789740399001-2bb62f21.jpg"
|
||||
]
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"model": "wan3.0-prime-text-to-video",
|
||||
"contentMode": "normal",
|
||||
"faceBlurMode": "off",
|
||||
"prompt": "A bowl of soup is knocked over by a knight",
|
||||
"aspectRatio": "16:9",
|
||||
"duration": "5s",
|
||||
"outputResolution": "720p"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"model": "wan3.0-prime-image-to-video",
|
||||
"contentMode": "normal",
|
||||
"faceBlurMode": "off",
|
||||
"prompt": "The lanterns blow in the breeze above the water",
|
||||
"mode": "keyframe",
|
||||
"aspectRatio": "16:9",
|
||||
"duration": "4s",
|
||||
"outputResolution": "1080p",
|
||||
"seed": 1878107760,
|
||||
"uploadedUrls": [
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789740716787-bf6a26f8.jpg",
|
||||
"https://static.seedance2-pro.com/materials/20260918/1789740722438-0101d158.jpg"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,523 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use serde_json::{json, Value};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio::time::timeout;
|
||||
|
||||
use super::generate_wan_3p0_image_to_video::*;
|
||||
use super::generate_wan_3p0_prime_image_to_video::*;
|
||||
use super::generate_wan_3p0_prime_ref_to_video::*;
|
||||
use super::generate_wan_3p0_prime_text_to_video::*;
|
||||
use super::generate_wan_3p0_ref_to_video::*;
|
||||
use super::generate_wan_3p0_text_to_video::*;
|
||||
use super::wan_3p0::{KinoviWan3p0AspectRatio, KinoviWan3p0OutputResolution, Wan3p0ApiParams};
|
||||
use crate::creds::kinovi_web_session::KinoviWebSession;
|
||||
use crate::error::kinovi_web_client_error::KinoviWebClientError;
|
||||
use crate::error::kinovi_web_error::KinoviWebError;
|
||||
use crate::pricing::kinovi_cost_calculator_trait::KinoviCostCalculatorTrait;
|
||||
use crate::pricing::kinovi_pricing_tier::KinoviPricingTier;
|
||||
use crate::requests::kinovi_host::KinoviHost;
|
||||
|
||||
const RESOLUTIONS: [KinoviWan3p0OutputResolution; 3] = [
|
||||
KinoviWan3p0OutputResolution::FourEightyP,
|
||||
KinoviWan3p0OutputResolution::SevenTwentyP,
|
||||
KinoviWan3p0OutputResolution::TenEightyP,
|
||||
];
|
||||
|
||||
// Literal price snapshots from the supplied observations and Kinovi's model
|
||||
// pages, checked 2026-09-18. Keep independent of the calculator's rate tables.
|
||||
// Columns are 480p, 720p, 1080p; all three modalities have the same rates.
|
||||
// WAN_CREDITS and WAN_CENTS intentionally assert promotional prices until a
|
||||
// reviewed update after 2026-09-23. See costs_wan_3p0.md at the crate root for
|
||||
// advertised replacement rates and all expectations that need to change.
|
||||
const WAN_CREDITS: [(u8, [f64; 3]); 9] = [
|
||||
(2, [19.96, 39.92, 79.82]),
|
||||
(5, [49.9, 99.8, 199.55]),
|
||||
(8, [79.84, 159.68, 319.28]),
|
||||
(10, [99.8, 199.6, 399.1]),
|
||||
(15, [149.7, 299.4, 598.65]),
|
||||
(20, [199.6, 399.2, 798.2]),
|
||||
(22, [219.56, 439.12, 878.02]),
|
||||
(25, [249.5, 499.0, 997.75]),
|
||||
(30, [299.4, 598.8, 1197.3]),
|
||||
];
|
||||
const PRIME_CREDITS: [(u8, [f64; 3]); 9] = [
|
||||
(2, [37.72, 77.66, 155.32]),
|
||||
(5, [94.3, 194.15, 388.3]),
|
||||
(8, [150.88, 310.64, 621.28]),
|
||||
(10, [188.6, 388.3, 776.6]),
|
||||
(15, [282.9, 582.45, 1164.9]),
|
||||
(20, [377.2, 776.6, 1553.2]),
|
||||
(22, [414.92, 854.26, 1708.52]),
|
||||
(25, [471.5, 970.75, 1941.5]),
|
||||
// The supplied Prime reference 480p/30s figure said 568.8; docs say 565.8.
|
||||
(30, [565.8, 1164.9, 2329.8]),
|
||||
];
|
||||
// Thirty-second USD cents, (rounded down, rounded up), consumer then enterprise.
|
||||
const WAN_CENTS: [[(u64, u64); 3]; 2] = [[(155, 156), (310, 311), (620, 621)], [(123, 124), (246, 247), (492, 493)]];
|
||||
const PRIME_CENTS: [[(u64, u64); 3]; 2] =
|
||||
[[(293, 294), (603, 604), (1207, 1208)], [(232, 233), (479, 480), (958, 959)]];
|
||||
// Only sanitized apiParams are included; the original captures contain cookies.
|
||||
const CAPTURES: [&str; 7] = [
|
||||
include_str!("wan_3p0_test_data/01_wan_ref_to_video_without_ref.json"),
|
||||
include_str!("wan_3p0_test_data/02_wan_text_to_video.json"),
|
||||
include_str!("wan_3p0_test_data/03_wan_image_to_video.json"),
|
||||
include_str!("wan_3p0_test_data/04_wan_ref_to_video_full.json"),
|
||||
include_str!("wan_3p0_test_data/05_wan_prime_ref_to_video.json"),
|
||||
include_str!("wan_3p0_test_data/06_wan_prime_text_to_video.json"),
|
||||
include_str!("wan_3p0_test_data/07_wan_prime_image_to_video.json"),
|
||||
];
|
||||
|
||||
macro_rules! operation_tests {
|
||||
($module:ident, $request:ident, $args:ident, $generate:ident, $model:literal,
|
||||
$credits:ident, $cents:ident, {$($field:ident: $value:expr),* $(,)?}) => {
|
||||
mod $module {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn literal_credit_prices_at_every_resolution_and_observed_duration() {
|
||||
for tier in [KinoviPricingTier::Consumer, KinoviPricingTier::Enterprise] {
|
||||
for (duration, expected) in $credits {
|
||||
for (resolution, credits) in RESOLUTIONS.into_iter().zip(expected) {
|
||||
// Cost estimates work before media has been uploaded.
|
||||
let request = $request {
|
||||
duration_seconds: duration,
|
||||
maybe_output_resolution: Some(resolution),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(request.calculate_costs(tier).kinovi_credits, credits,
|
||||
"{tier:?}, {resolution:?}, {duration}s");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_usd_cent_prices_for_both_tiers() {
|
||||
for (tier, expected) in [KinoviPricingTier::Consumer, KinoviPricingTier::Enterprise]
|
||||
.into_iter().zip($cents)
|
||||
{
|
||||
for (resolution, (down, up)) in RESOLUTIONS.into_iter().zip(expected) {
|
||||
let request = $request {
|
||||
duration_seconds: 30,
|
||||
maybe_output_resolution: Some(resolution),
|
||||
..Default::default()
|
||||
};
|
||||
let cost = request.calculate_costs(tier);
|
||||
assert_eq!((cost.usd_cents_rounded_down, cost.usd_cents_rounded_up), (down, up));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn defaults_match_the_priced_resolution() {
|
||||
let request = valid_request();
|
||||
assert_eq!(request.calculate_consumer_costs().kinovi_credits, $credits[1].1[1]);
|
||||
let params = serde_json::to_value(request.build_api_params().unwrap()).unwrap();
|
||||
assert_eq!(params["model"], $model);
|
||||
assert_eq!(params["duration"], "5s");
|
||||
assert_eq!(params["outputResolution"], "720p");
|
||||
assert_eq!(params["aspectRatio"], "16:9");
|
||||
assert!(params.get("seed").is_none());
|
||||
assert!(params.get("audio").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_whole_second_durations_and_aspect_ratios_serialize() {
|
||||
for duration in 2..=30 {
|
||||
let mut request = valid_request();
|
||||
request.duration_seconds = duration;
|
||||
let params = serde_json::to_value(request.build_api_params().unwrap()).unwrap();
|
||||
assert_eq!(params["duration"], format!("{duration}s"));
|
||||
}
|
||||
for (maybe_aspect_ratio, expected) in [
|
||||
(KinoviWan3p0AspectRatio::Landscape16x9, "16:9"),
|
||||
(KinoviWan3p0AspectRatio::Portrait9x16, "9:16"),
|
||||
(KinoviWan3p0AspectRatio::Landscape4x3, "4:3"),
|
||||
(KinoviWan3p0AspectRatio::Portrait3x4, "3:4"),
|
||||
(KinoviWan3p0AspectRatio::Square1x1, "1:1"),
|
||||
] {
|
||||
let mut request = valid_request();
|
||||
request.maybe_aspect_ratio = Some(maybe_aspect_ratio);
|
||||
let params = serde_json::to_value(request.build_api_params().unwrap()).unwrap();
|
||||
assert_eq!(params["aspectRatio"], expected);
|
||||
}
|
||||
for (resolution, expected) in RESOLUTIONS.into_iter().zip(["480p", "720p", "1080p"]) {
|
||||
let mut request = valid_request();
|
||||
request.maybe_output_resolution = Some(resolution);
|
||||
let params = serde_json::to_value(request.build_api_params().unwrap()).unwrap();
|
||||
assert_eq!(params["outputResolution"], expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seed_and_audio_flags_preserve_values_without_changing_price() {
|
||||
for (seed, audio) in [(0, false), (2_147_483_647, true)] {
|
||||
let mut request = valid_request();
|
||||
request.maybe_seed = Some(seed);
|
||||
request.maybe_generate_audio = Some(audio);
|
||||
assert_eq!(request.calculate_consumer_costs().kinovi_credits, $credits[1].1[1]);
|
||||
let params = serde_json::to_value(request.build_api_params().unwrap()).unwrap();
|
||||
assert_eq!(params["seed"], seed);
|
||||
assert_eq!(params["audio"], audio);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_duration_seed_and_prompt_are_rejected() {
|
||||
for duration in [0, 1, 31, 255] {
|
||||
let mut request = valid_request();
|
||||
request.duration_seconds = duration;
|
||||
assert_invalid(request.build_api_params(), "duration_seconds");
|
||||
}
|
||||
for seed in [2_147_483_648, u32::MAX] {
|
||||
let mut request = valid_request();
|
||||
request.maybe_seed = Some(seed);
|
||||
assert_invalid(request.build_api_params(), "maybe_seed");
|
||||
}
|
||||
let mut request = valid_request();
|
||||
request.prompt = "猫".repeat(20_000);
|
||||
assert!(request.clone().build_api_params().is_ok());
|
||||
request.prompt.push('猫');
|
||||
assert_invalid(request.build_api_params(), "prompt");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn public_generate_sends_workflow_request_and_returns_task_ids() {
|
||||
let (host, server) = stub_server().await;
|
||||
let session = KinoviWebSession::from_cookies_string("test-session=local".to_owned());
|
||||
let request = valid_request();
|
||||
let params = serde_json::to_value(request.clone().build_api_params().unwrap()).unwrap();
|
||||
let result = timeout(Duration::from_secs(10), $generate($args {
|
||||
request,
|
||||
session: &session,
|
||||
maybe_host_override: Some(host),
|
||||
})).await.unwrap().unwrap();
|
||||
assert_eq!(result.task_id, "wan-task");
|
||||
assert_eq!(result.order_id, "wan-order");
|
||||
assert_eq!(result.task_ids, Some(vec!["wan-task".to_owned()]));
|
||||
assert_eq!(result.order_ids, Some(vec!["wan-order".to_owned()]));
|
||||
let (headers, body) = timeout(Duration::from_secs(10), server).await.unwrap().unwrap();
|
||||
assert!(headers.starts_with("POST /api/trpc/workflow.runTask?batch=1 HTTP/1.1\r\n"));
|
||||
assert_eq!(body, json!({"0": {"json": {
|
||||
"businessType": "wan3-video-generation", "apiParams": params,
|
||||
}}}));
|
||||
}
|
||||
|
||||
fn valid_request() -> $request {
|
||||
$request {
|
||||
prompt: "A lighthouse on the coast".to_owned(),
|
||||
$($field: $value,)*
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
operation_tests!(
|
||||
text,
|
||||
GenerateWan3p0TextToVideoRequest,
|
||||
GenerateWan3p0TextToVideoArgs,
|
||||
generate_wan_3p0_text_to_video,
|
||||
"wan3.0-text-to-video",
|
||||
WAN_CREDITS,
|
||||
WAN_CENTS,
|
||||
{}
|
||||
);
|
||||
operation_tests!(image, GenerateWan3p0ImageToVideoRequest, GenerateWan3p0ImageToVideoArgs,
|
||||
generate_wan_3p0_image_to_video, "wan3.0-image-to-video", WAN_CREDITS, WAN_CENTS,
|
||||
{ maybe_start_frame_url: Some("https://example.com/start.png".to_owned()) });
|
||||
operation_tests!(
|
||||
reference,
|
||||
GenerateWan3p0RefToVideoRequest,
|
||||
GenerateWan3p0RefToVideoArgs,
|
||||
generate_wan_3p0_ref_to_video,
|
||||
"wan3.0-ref-to-video",
|
||||
WAN_CREDITS,
|
||||
WAN_CENTS,
|
||||
{}
|
||||
);
|
||||
operation_tests!(
|
||||
prime_text,
|
||||
GenerateWan3p0PrimeTextToVideoRequest,
|
||||
GenerateWan3p0PrimeTextToVideoArgs,
|
||||
generate_wan_3p0_prime_text_to_video,
|
||||
"wan3.0-prime-text-to-video",
|
||||
PRIME_CREDITS,
|
||||
PRIME_CENTS,
|
||||
{}
|
||||
);
|
||||
operation_tests!(prime_image, GenerateWan3p0PrimeImageToVideoRequest, GenerateWan3p0PrimeImageToVideoArgs,
|
||||
generate_wan_3p0_prime_image_to_video, "wan3.0-prime-image-to-video", PRIME_CREDITS, PRIME_CENTS,
|
||||
{ maybe_start_frame_url: Some("https://example.com/start.png".to_owned()) });
|
||||
operation_tests!(
|
||||
prime_reference,
|
||||
GenerateWan3p0PrimeRefToVideoRequest,
|
||||
GenerateWan3p0PrimeRefToVideoArgs,
|
||||
generate_wan_3p0_prime_ref_to_video,
|
||||
"wan3.0-prime-ref-to-video",
|
||||
PRIME_CREDITS,
|
||||
PRIME_CENTS,
|
||||
{}
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn payloads_match_all_seven_consumer_captures() {
|
||||
for fixture in CAPTURES {
|
||||
let expected: Value = serde_json::from_str(fixture).unwrap();
|
||||
assert_eq!(params_from_capture(&expected), expected);
|
||||
}
|
||||
// Capture 03's filename says Wan image, but its actual model is Prime.
|
||||
// Exercise regular image too, using the same documented keyframe shape.
|
||||
let mut regular_image: Value = serde_json::from_str(CAPTURES[2]).unwrap();
|
||||
regular_image["model"] = json!("wan3.0-image-to-video");
|
||||
assert_eq!(params_from_capture(®ular_image), regular_image);
|
||||
}
|
||||
|
||||
macro_rules! reference_media_tests {
|
||||
($module:ident, $request:ident, $credits:literal) => {
|
||||
mod $module {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn references_are_optional_and_empty_lists_are_omitted() {
|
||||
let request = $request {
|
||||
prompt: "A ship at sea".to_owned(),
|
||||
duration_seconds: 30,
|
||||
maybe_reference_image_urls: Some(vec![]),
|
||||
maybe_reference_video_urls: Some(vec![]),
|
||||
maybe_reference_audio_urls: Some(vec![]),
|
||||
..Default::default()
|
||||
};
|
||||
let params = serde_json::to_value(request.build_api_params().unwrap()).unwrap();
|
||||
for field in ["uploadedUrls", "videoUrl", "videoUrls", "audioUrls"] {
|
||||
assert!(params.get(field).is_none(), "{field}");
|
||||
}
|
||||
assert_invalid($request::default().build_api_params(), "prompt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_duration_and_output_share_thirty_seconds() {
|
||||
let request = $request {
|
||||
duration_seconds: 20,
|
||||
maybe_reference_video_urls: Some(urls(1)),
|
||||
maybe_total_reference_video_duration_millis: Some(10_000),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(request.clone().build_api_params().is_ok());
|
||||
for millis in [0, 999, 10_001, 15_001, u32::MAX] {
|
||||
let mut invalid = request.clone();
|
||||
invalid.maybe_total_reference_video_duration_millis = Some(millis);
|
||||
assert!(invalid.build_api_params().is_err(), "{millis}ms");
|
||||
}
|
||||
let mut request = request;
|
||||
request.duration_seconds = 15;
|
||||
request.maybe_total_reference_video_duration_millis = Some(15_000);
|
||||
assert!(request.clone().build_api_params().is_ok());
|
||||
request.duration_seconds = 16;
|
||||
assert_invalid(request.clone().build_api_params(), "duration_seconds");
|
||||
request.maybe_total_reference_video_duration_millis = None;
|
||||
request.duration_seconds = 29;
|
||||
assert!(request.clone().build_api_params().is_ok());
|
||||
request.duration_seconds = 30;
|
||||
assert_invalid(request.build_api_params(), "duration_seconds");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_reference_types_have_independent_limits_and_no_surcharge() {
|
||||
let request = $request {
|
||||
duration_seconds: 10,
|
||||
maybe_reference_image_urls: Some(urls(10)),
|
||||
maybe_reference_video_urls: Some(urls(5)),
|
||||
maybe_reference_audio_urls: Some(urls(5)),
|
||||
maybe_total_reference_video_duration_millis: Some(15_000),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(request.calculate_consumer_costs().kinovi_credits, $credits);
|
||||
let params = serde_json::to_value(request.clone().build_api_params().unwrap()).unwrap();
|
||||
assert_eq!(params["uploadedUrls"], json!(urls(10)));
|
||||
assert_eq!(params["videoUrls"], json!(urls(5)));
|
||||
assert_eq!(params["videoUrl"], urls(1)[0]);
|
||||
assert_eq!(params["audioUrls"], json!(urls(5)));
|
||||
assert!(params.get("maybeTotalReferenceVideoDurationMillis").is_none());
|
||||
assert!(params.get("imageUrls").is_none());
|
||||
let mut invalid = request.clone();
|
||||
invalid.maybe_reference_image_urls = Some(urls(11));
|
||||
assert_invalid(invalid.build_api_params(), "maybe_reference_image_urls");
|
||||
let mut invalid = request.clone();
|
||||
invalid.maybe_reference_video_urls = Some(urls(6));
|
||||
assert_invalid(invalid.build_api_params(), "maybe_reference_video_urls");
|
||||
let mut invalid = request.clone();
|
||||
invalid.maybe_reference_audio_urls = Some(urls(6));
|
||||
assert_invalid(invalid.build_api_params(), "maybe_reference_audio_urls");
|
||||
let mut invalid = request.clone();
|
||||
invalid.maybe_total_reference_video_duration_millis = Some(4_999);
|
||||
assert_invalid(invalid.build_api_params(), "maybe_total_reference_video_duration_millis");
|
||||
let mut invalid = request;
|
||||
invalid.maybe_reference_audio_urls = Some(vec![" ".to_owned()]);
|
||||
assert_invalid(invalid.build_api_params(), "media_url");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
reference_media_tests!(reference_media, GenerateWan3p0RefToVideoRequest, 199.6);
|
||||
reference_media_tests!(prime_reference_media, GenerateWan3p0PrimeRefToVideoRequest, 388.3);
|
||||
|
||||
#[test]
|
||||
fn keyframes_require_a_start_image_and_preserve_start_end_order() {
|
||||
macro_rules! check {
|
||||
($request:ident, $credits:literal) => {
|
||||
let mut request = $request {
|
||||
prompt: "Waves".to_owned(),
|
||||
..Default::default()
|
||||
};
|
||||
assert_invalid(request.clone().build_api_params(), "maybe_start_frame_url");
|
||||
request.maybe_end_frame_url = Some("https://example.com/end.png".to_owned());
|
||||
assert_invalid(request.clone().build_api_params(), "maybe_end_frame_url");
|
||||
request.maybe_start_frame_url = Some("https://example.com/start.png".to_owned());
|
||||
request.prompt.clear();
|
||||
assert_eq!(request.calculate_consumer_costs().kinovi_credits, $credits);
|
||||
let params = serde_json::to_value(request.build_api_params().unwrap()).unwrap();
|
||||
assert_eq!(params["uploadedUrls"], json!(["https://example.com/start.png", "https://example.com/end.png",]));
|
||||
assert!(params.get("imageUrls").is_none());
|
||||
};
|
||||
}
|
||||
check!(GenerateWan3p0ImageToVideoRequest, 99.8);
|
||||
check!(GenerateWan3p0PrimeImageToVideoRequest, 194.15);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_operations_require_a_prompt() {
|
||||
assert_invalid(GenerateWan3p0TextToVideoRequest::default().build_api_params(), "prompt");
|
||||
assert_invalid(GenerateWan3p0PrimeTextToVideoRequest::default().build_api_params(), "prompt");
|
||||
}
|
||||
|
||||
fn params_from_capture(value: &Value) -> Value {
|
||||
macro_rules! build {
|
||||
($request:ident, {$($field:ident: $extra:expr),* $(,)?}) => {
|
||||
$request {
|
||||
prompt: value["prompt"].as_str().unwrap().to_owned(),
|
||||
maybe_aspect_ratio: Some(match value["aspectRatio"].as_str().unwrap() {
|
||||
"16:9" => KinoviWan3p0AspectRatio::Landscape16x9,
|
||||
"4:3" => KinoviWan3p0AspectRatio::Landscape4x3,
|
||||
other => panic!("unexpected fixture aspect ratio: {other}"),
|
||||
}),
|
||||
maybe_output_resolution: Some(match value["outputResolution"].as_str().unwrap() {
|
||||
"480p" => KinoviWan3p0OutputResolution::FourEightyP,
|
||||
"720p" => KinoviWan3p0OutputResolution::SevenTwentyP,
|
||||
"1080p" => KinoviWan3p0OutputResolution::TenEightyP,
|
||||
other => panic!("unexpected fixture resolution: {other}"),
|
||||
}),
|
||||
duration_seconds: value["duration"].as_str().unwrap().trim_end_matches('s').parse().unwrap(),
|
||||
maybe_seed: value["seed"].as_u64().map(|seed| seed as u32),
|
||||
$($field: $extra,)*
|
||||
..Default::default()
|
||||
}.build_api_params().unwrap()
|
||||
};
|
||||
}
|
||||
macro_rules! image {
|
||||
($request:ident) => {
|
||||
build!($request, {
|
||||
maybe_start_frame_url: value["uploadedUrls"][0].as_str().map(str::to_owned),
|
||||
maybe_end_frame_url: value["uploadedUrls"][1].as_str().map(str::to_owned),
|
||||
})
|
||||
};
|
||||
}
|
||||
macro_rules! reference {
|
||||
($request:ident) => {
|
||||
build!($request, {
|
||||
maybe_reference_image_urls: capture_urls(value, "uploadedUrls"),
|
||||
maybe_reference_video_urls: capture_urls(value, "videoUrls"),
|
||||
maybe_reference_audio_urls: capture_urls(value, "audioUrls"),
|
||||
})
|
||||
};
|
||||
}
|
||||
let params = match value["model"].as_str().unwrap() {
|
||||
"wan3.0-text-to-video" => build!(GenerateWan3p0TextToVideoRequest, {}),
|
||||
"wan3.0-image-to-video" => image!(GenerateWan3p0ImageToVideoRequest),
|
||||
"wan3.0-ref-to-video" => reference!(GenerateWan3p0RefToVideoRequest),
|
||||
"wan3.0-prime-text-to-video" => build!(GenerateWan3p0PrimeTextToVideoRequest, {}),
|
||||
"wan3.0-prime-image-to-video" => image!(GenerateWan3p0PrimeImageToVideoRequest),
|
||||
"wan3.0-prime-ref-to-video" => reference!(GenerateWan3p0PrimeRefToVideoRequest),
|
||||
other => panic!("unexpected fixture model: {other}"),
|
||||
};
|
||||
serde_json::to_value(params).unwrap()
|
||||
}
|
||||
|
||||
async fn stub_server() -> (KinoviHost, JoinHandle<(String, Value)>) {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let address = format!("http://{}", listener.local_addr().unwrap());
|
||||
let server = tokio::spawn(async move {
|
||||
let (mut stream, _) = listener.accept().await.unwrap();
|
||||
let mut bytes = Vec::new();
|
||||
let (headers, body_start, body_len) = loop {
|
||||
let mut chunk = [0; 4096];
|
||||
let length = stream.read(&mut chunk).await.unwrap();
|
||||
assert_ne!(length, 0, "request ended before headers");
|
||||
bytes.extend_from_slice(&chunk[..length]);
|
||||
if let Some(end) = bytes.windows(4).position(|window| window == b"\r\n\r\n") {
|
||||
let headers = String::from_utf8(bytes[..end + 4].to_vec()).unwrap();
|
||||
let body_len: usize = headers
|
||||
.lines()
|
||||
.find_map(|line| {
|
||||
let (name, value) = line.split_once(':')?;
|
||||
name.eq_ignore_ascii_case("content-length").then(|| value.trim().parse().unwrap())
|
||||
})
|
||||
.unwrap();
|
||||
break (headers, end + 4, body_len);
|
||||
}
|
||||
};
|
||||
while bytes.len() < body_start + body_len {
|
||||
let mut chunk = [0; 4096];
|
||||
let length = stream.read(&mut chunk).await.unwrap();
|
||||
assert_ne!(length, 0, "request ended before body");
|
||||
bytes.extend_from_slice(&chunk[..length]);
|
||||
}
|
||||
let body = serde_json::from_slice(&bytes[body_start..body_start + body_len]).unwrap();
|
||||
let response = json!([{"result": {"data": {"json": {
|
||||
"taskId": "wan-task", "orderId": "wan-order",
|
||||
"taskIds": ["wan-task"], "orderIds": ["wan-order"], "violationWarning": false,
|
||||
}}}}])
|
||||
.to_string();
|
||||
let response = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
|
||||
response.len(),
|
||||
response,
|
||||
);
|
||||
stream.write_all(response.as_bytes()).await.unwrap();
|
||||
(headers, body)
|
||||
});
|
||||
(
|
||||
KinoviHost::CustomHost {
|
||||
api_host: address.clone(),
|
||||
cdn_host: address,
|
||||
},
|
||||
server,
|
||||
)
|
||||
}
|
||||
|
||||
fn capture_urls(value: &Value, field: &str) -> Option<Vec<String>> {
|
||||
value[field]
|
||||
.as_array()
|
||||
.map(|urls| urls.iter().map(|url| url.as_str().unwrap().to_owned()).collect())
|
||||
}
|
||||
|
||||
fn urls(count: usize) -> Vec<String> {
|
||||
(0..count).map(|index| format!("https://example.com/reference-{index}")).collect()
|
||||
}
|
||||
|
||||
fn assert_invalid(result: Result<Wan3p0ApiParams, KinoviWebError>, field: &str) {
|
||||
match result.unwrap_err() {
|
||||
KinoviWebError::Client(KinoviWebClientError::InvalidRequestField {
|
||||
field: actual,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(actual, field);
|
||||
},
|
||||
other => panic!("expected invalid {field}, got {other:?}"),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user