Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 65 additions & 31 deletions crates/tui/src/pricing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,52 @@ fn pricing_for_model_at(model: &str, _now: DateTime<Utc>) -> Option<ModelPricing
// DeepSeek Platform pricing. Avoid showing misleading DeepSeek costs.
return None;
}
if !lower.contains("deepseek") {
return None;
match lower.as_str() {
"xiaomi/mimo-v2.5-pro" | "mimo-v2.5-pro" => return Some(deepseek_v4_pro_pricing()),
"xiaomi/mimo-v2.5" | "mimo-v2.5" => return Some(deepseek_v4_flash_pricing()),
_ => {}
}
if lower.contains("v4-pro") || lower.contains("v4pro") {
// DeepSeek's pricing page says the V4-Pro promotional 75% discount
// becomes the official one-quarter base price after 2026-05-31 15:59
// UTC. Keep using the adjusted rate after that cutoff (#2489).
Some(ModelPricing {
usd: CurrencyPricing {
input_cache_hit_per_million: 0.003625,
input_cache_miss_per_million: 0.435,
output_per_million: 0.87,
},
cny: CurrencyPricing {
input_cache_hit_per_million: 0.025,
input_cache_miss_per_million: 3.0,
output_per_million: 6.0,
},
})
if lower.contains("deepseek") {
if lower.contains("v4-pro") || lower.contains("v4pro") {
// DeepSeek's pricing page says the V4-Pro promotional 75% discount
// becomes the official one-quarter base price after 2026-05-31 15:59
// UTC. Keep using the adjusted rate after that cutoff (#2489).
Some(deepseek_v4_pro_pricing())
} else {
Some(deepseek_v4_flash_pricing())
}
} else {
// deepseek-v4-flash pricing.
Some(ModelPricing {
usd: CurrencyPricing {
input_cache_hit_per_million: 0.0028,
input_cache_miss_per_million: 0.14,
output_per_million: 0.28,
},
cny: CurrencyPricing {
input_cache_hit_per_million: 0.02,
input_cache_miss_per_million: 1.0,
output_per_million: 2.0,
},
})
None
}
Comment on lines +120 to +136
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The control flow can be simplified and made more idiomatic by combining the exact match and the contains checks into a single match expression. This avoids the need for explicit return statements and makes the function's structure cleaner.

    match lower.as_str() {
        "xiaomi/mimo-v2.5-pro" | "mimo-v2.5-pro" => Some(deepseek_v4_pro_pricing()),
        "xiaomi/mimo-v2.5" | "mimo-v2.5" => Some(deepseek_v4_flash_pricing()),
        _ if lower.contains("deepseek") => {
            if lower.contains("v4-pro") || lower.contains("v4pro") {
                // DeepSeek's pricing page says the V4-Pro promotional 75% discount
                // becomes the official one-quarter base price after 2026-05-31 15:59
                // UTC. Keep using the adjusted rate after that cutoff (#2489).
                Some(deepseek_v4_pro_pricing())
            } else {
                Some(deepseek_v4_flash_pricing())
            }
        }
        _ => None,
    }

}

fn deepseek_v4_pro_pricing() -> ModelPricing {
ModelPricing {
usd: CurrencyPricing {
input_cache_hit_per_million: 0.003625,
input_cache_miss_per_million: 0.435,
output_per_million: 0.87,
},
cny: CurrencyPricing {
input_cache_hit_per_million: 0.025,
input_cache_miss_per_million: 3.0,
output_per_million: 6.0,
},
}
}

fn deepseek_v4_flash_pricing() -> ModelPricing {
ModelPricing {
usd: CurrencyPricing {
input_cache_hit_per_million: 0.0028,
input_cache_miss_per_million: 0.14,
output_per_million: 0.28,
},
cny: CurrencyPricing {
input_cache_hit_per_million: 0.02,
input_cache_miss_per_million: 1.0,
output_per_million: 2.0,
},
}
}

Expand Down Expand Up @@ -340,6 +353,27 @@ mod tests {
assert_eq!(pricing.cny.output_per_million, 2.0);
}

#[test]
fn xiaomi_mimo_primary_models_use_matching_deepseek_v4_rates() {
let now = Utc.with_ymd_and_hms(2026, 6, 4, 0, 0, 0).single().unwrap();

let pro_pricing = pricing_for_model_at("mimo-v2.5-pro", now).unwrap();
assert_eq!(pro_pricing.usd.input_cache_hit_per_million, 0.003625);
assert_eq!(pro_pricing.usd.input_cache_miss_per_million, 0.435);
assert_eq!(pro_pricing.usd.output_per_million, 0.87);
assert_eq!(pro_pricing.cny.input_cache_hit_per_million, 0.025);
assert_eq!(pro_pricing.cny.input_cache_miss_per_million, 3.0);
assert_eq!(pro_pricing.cny.output_per_million, 6.0);

let flash_pricing = pricing_for_model_at("xiaomi/mimo-v2.5", now).unwrap();
assert_eq!(flash_pricing.usd.input_cache_hit_per_million, 0.0028);
assert_eq!(flash_pricing.usd.input_cache_miss_per_million, 0.14);
assert_eq!(flash_pricing.usd.output_per_million, 0.28);
assert_eq!(flash_pricing.cny.input_cache_hit_per_million, 0.02);
assert_eq!(flash_pricing.cny.input_cache_miss_per_million, 1.0);
assert_eq!(flash_pricing.cny.output_per_million, 2.0);
}

#[test]
fn cost_estimate_calculates_usd_and_cny() {
let estimate = calculate_turn_cost_estimate("deepseek-v4-flash", 1_000_000, 500_000)
Expand Down
Loading