Skip to content

Commit e9eda9a

Browse files
committed
fix(pricing): preserve fast multipliers in fallback
1 parent c773e31 commit e9eda9a

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

‎rust/crates/ccusage-core/src/pricing.rs‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ impl PricingMap {
10591059

10601060
fn load_models_dev_json_missing(&mut self, json: &str) -> Option<usize> {
10611061
let raw = parse_models_dev_json(json)?;
1062+
let fast_multiplier_overrides = FastMultiplierOverrides::load();
10621063
Some(match raw {
10631064
ModelsDevJson::Providers(providers) => {
10641065
let rules = models_dev_catalog_rules();
@@ -1097,6 +1098,7 @@ impl PricingMap {
10971098
&provider_id,
10981099
trust,
10991100
true,
1101+
&fast_multiplier_overrides,
11001102
&mut claims,
11011103
)
11021104
})
@@ -1108,7 +1110,14 @@ impl PricingMap {
11081110
// verdicts as fields rather than leaving them to be rederived.
11091111
// The flat snapshot has one implicit source, so any constant id
11101112
// works: ties inside it are settled by the source keys.
1111-
self.load_models_dev_models(models, "", MODELS_DEV_TRUST_OWNER, false, &mut claims)
1113+
self.load_models_dev_models(
1114+
models,
1115+
"",
1116+
MODELS_DEV_TRUST_OWNER,
1117+
false,
1118+
&fast_multiplier_overrides,
1119+
&mut claims,
1120+
)
11121121
}
11131122
})
11141123
}
@@ -1134,6 +1143,7 @@ impl PricingMap {
11341143
provider_id: &str,
11351144
trust: u8,
11361145
derive_exact_only: bool,
1146+
fast_multiplier_overrides: &FastMultiplierOverrides,
11371147
claims: &mut FxHashMap<String, ModelsDevClaimSlot>,
11381148
) -> usize {
11391149
let rules = models_dev_catalog_rules();
@@ -1242,7 +1252,9 @@ impl PricingMap {
12421252
cache_create_above_200k: long_context.and_then(|rates| rates.cache_create),
12431253
cache_read_above_200k: long_context.and_then(|rates| rates.cache_read),
12441254
long_context_threshold: long_context.map(|rates| rates.threshold),
1245-
fast_multiplier: 1.0,
1255+
fast_multiplier: fast_multiplier_overrides
1256+
.multiplier_for(&model_id)
1257+
.unwrap_or(1.0),
12461258
},
12471259
);
12481260
if exact_only {
@@ -3564,6 +3576,34 @@ mod tests {
35643576
assert_eq!(pricing.context_limits.get("gpt-alias"), Some(&654));
35653577
}
35663578

3579+
#[test]
3580+
fn applies_fast_multiplier_override_to_models_dev_fallback() {
3581+
let mut pricing = PricingMap::default();
3582+
let models_dev_json = r#"{
3583+
"openai": {
3584+
"id": "openai",
3585+
"models": {
3586+
"gpt-6-astra": {
3587+
"id": "gpt-6-astra",
3588+
"cost": {
3589+
"input": 10.0,
3590+
"output": 50.0
3591+
}
3592+
}
3593+
}
3594+
}
3595+
}"#;
3596+
3597+
assert_eq!(
3598+
pricing.load_models_dev_json_missing(models_dev_json),
3599+
Some(1)
3600+
);
3601+
assert_eq!(
3602+
pricing.find_exact("gpt-6-astra").unwrap().fast_multiplier,
3603+
2.0
3604+
);
3605+
}
3606+
35673607
#[test]
35683608
fn live_models_dev_pricing_prefers_the_authoring_catalog_over_resellers() {
35693609
// The same model id appears in every catalog that serves it, and the

0 commit comments

Comments
 (0)