Skip to content

Commit 1acb60b

Browse files
committed
fix(pricing): match qualified fast overrides
1 parent e9eda9a commit 1acb60b

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,12 +933,18 @@ impl FastMultiplierOverrides {
933933
if let Some(multiplier) = pricing_alias(model).and_then(|alias| self.exact.get(alias)) {
934934
return Some(*multiplier);
935935
}
936-
let normalized = model.replace(['.', '@'], "-");
937-
normalized.split(['/', ':']).find_map(|part| {
938-
self.normalized_prefix
939-
.iter()
940-
.find_map(|(base, multiplier)| {
941-
matches_model_suffix(part, base).then_some(*multiplier)
936+
model.split(['/', ':']).find_map(|part| {
937+
self.exact
938+
.get(part)
939+
.copied()
940+
.or_else(|| pricing_alias(part).and_then(|alias| self.exact.get(alias).copied()))
941+
.or_else(|| {
942+
let normalized = part.replace(['.', '@'], "-");
943+
self.normalized_prefix
944+
.iter()
945+
.find_map(|(base, multiplier)| {
946+
matches_model_suffix(&normalized, base).then_some(*multiplier)
947+
})
942948
})
943949
})
944950
}
@@ -4273,6 +4279,27 @@ mod tests {
42734279
assert_eq!(pricing.context_limit("claude-fallback"), Some(200000));
42744280
}
42754281

4282+
#[test]
4283+
fn applies_fast_multiplier_to_qualified_flat_models_dev_model() {
4284+
let mut pricing = PricingMap::default();
4285+
let models_dev_json = r#"{
4286+
"openai/gpt-6-astra": {
4287+
"cost": {
4288+
"input": 10.0,
4289+
"output": 50.0
4290+
}
4291+
}
4292+
}"#;
4293+
4294+
assert_eq!(
4295+
pricing.load_models_dev_json_missing(models_dev_json),
4296+
Some(1)
4297+
);
4298+
4299+
let model = pricing.find_exact("openai/gpt-6-astra").unwrap();
4300+
assert_eq!(model.fast_multiplier, 2.0);
4301+
}
4302+
42764303
#[test]
42774304
fn embedded_models_dev_snapshot_is_parseable() {
42784305
let mut map = PricingMap::default();

0 commit comments

Comments
 (0)