Skip to content

Commit 625dcc0

Browse files
ryoppippirzv-me
andcommitted
fix(pricing): resolve the Ultrafast multiplier with the Standard entry
The Ultrafast multiplier was looked up from the recorded model name separately from the Standard rates, so the two could disagree. Provider spellings such as `openai@gpt-6-1-sol` fell back to Standard, and a model aliased to Sol while an exact entry of its own existed (e.g. `gpt-6.1-terra`) was billed Terra rates at Sol's 6x. Store the published Ultrafast multiplier on each `Pricing` entry, as Fast and Flex already are, so one `PricingMap::find`/`find_at` resolution supplies both the Standard rates and the multiplier. Co-authored-by: Razvan Aurariu <[email protected]>
1 parent 0d0d014 commit 625dcc0

4 files changed

Lines changed: 106 additions & 25 deletions

File tree

‎rust/adapters/codex/src/lib.rs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,37 @@ mod tests {
836836
}
837837
}
838838

839+
#[test]
840+
fn prices_ultrafast_from_the_same_entry_as_standard_rates() {
841+
let _aliases = crate::model_aliases::set_model_aliases_for_tests([
842+
("private-sol", "gpt-6.1-sol"),
843+
("gpt-6.1-terra", "gpt-6.1-sol"),
844+
]);
845+
let pricing = PricingMap::load_embedded();
846+
let usage = CodexModelUsage {
847+
input_tokens: 1_200,
848+
cached_input_tokens: 200,
849+
output_tokens: 50,
850+
total_tokens: 1_250,
851+
recorded_ultrafast_usage: CodexUsageBucket {
852+
input_tokens: 1_200,
853+
cached_input_tokens: 200,
854+
output_tokens: 50,
855+
..CodexUsageBucket::default()
856+
},
857+
..CodexModelUsage::default()
858+
};
859+
860+
let private_sol =
861+
calculate_codex_model_cost("private-sol", &usage, &pricing, CodexSpeed::Auto);
862+
let terra = calculate_codex_model_cost("gpt-6.1-terra", &usage, &pricing, CodexSpeed::Auto);
863+
let standard_terra =
864+
calculate_codex_model_cost("gpt-6.1-terra", &usage, &pricing, CodexSpeed::Standard);
865+
866+
assert!((private_sol - 0.01512).abs() < 1e-12, "{private_sol}");
867+
assert!((terra - standard_terra).abs() < f64::EPSILON, "{terra}");
868+
}
869+
839870
#[test]
840871
fn prices_rollout_service_tiers_across_loading_and_report_modes() {
841872
for (model, expected_costs) in [

‎rust/adapters/codex/src/report.rs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ pub fn calculate_codex_model_cost(
187187
speed: impl Into<CodexSpeedPolicy>,
188188
) -> f64 {
189189
let speed = speed.into();
190-
let ultrafast_multiplier = crate::ultrafast_multiplier(model);
191190
if !usage.timestamped_usage.is_empty() {
192191
return usage
193192
.timestamped_usage
@@ -198,7 +197,6 @@ pub fn calculate_codex_model_cost(
198197
Some(calculate_codex_usage_cost(
199198
*timestamped_usage,
200199
&pricing,
201-
ultrafast_multiplier,
202200
speed,
203201
))
204202
})
@@ -217,15 +215,13 @@ pub fn calculate_codex_model_cost(
217215
recorded_ultrafast_usage: usage.recorded_ultrafast_usage,
218216
},
219217
&pricing,
220-
ultrafast_multiplier,
221218
speed,
222219
)
223220
}
224221

225222
fn calculate_codex_usage_cost(
226223
usage: CodexTimestampedUsage,
227224
pricing: &crate::Pricing,
228-
ultrafast_multiplier: f64,
229225
speed: CodexSpeedPolicy,
230226
) -> f64 {
231227
let CodexTimestampedUsage {
@@ -278,7 +274,8 @@ fn calculate_codex_usage_cost(
278274
standard_cost
279275
+ calculate_codex_bucket_cost(&flex_usage, pricing) * (pricing.flex_multiplier - 1.0)
280276
+ calculate_codex_bucket_cost(&fast_usage, pricing) * (pricing.fast_multiplier - 1.0)
281-
+ calculate_codex_bucket_cost(&ultrafast_usage, pricing) * (ultrafast_multiplier - 1.0)
277+
+ calculate_codex_bucket_cost(&ultrafast_usage, pricing)
278+
* (pricing.ultrafast_multiplier - 1.0)
282279
}
283280

284281
fn model_usage_bucket(usage: &CodexModelUsage) -> CodexUsageBucket {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use output::{
3737
print_missing_pricing_warnings_for_models, print_usage_table, print_usage_table_with_options,
3838
sanitize_terminal_text, should_use_compact_layout, totals_json, unpriced_models, wants_json,
3939
};
40-
pub use pricing::{Pricing, PricingMap, has_time_dependent_pricing, ultrafast_multiplier};
40+
pub use pricing::{Pricing, PricingMap, has_time_dependent_pricing};
4141
pub(crate) use project_names::parse_project_aliases;
4242
pub(crate) use project_names::short_model_name;
4343
pub use project_names::{format_breakdown_model_label, format_project_name};

0 commit comments

Comments
 (0)