From c9b613659c5b03c1cd54f19ef79fb6abce907ab1 Mon Sep 17 00:00:00 2001 From: zyycn Date: Fri, 31 Jul 2026 22:43:18 +0800 Subject: [PATCH] fix(openai): refresh GPT pricing from upstream Align GPT-5.6 Terra/Luna standard, Fast, cache and long-context rates with the current upstream pricing page, and add GPT-4o/4o-mini cached-input rates. Co-authored-by: Codex --- .../providers/openai/src/transport/usage.rs | 20 ++++++++------ .../providers/openai/tests/transport/usage.rs | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/backend/crates/providers/openai/src/transport/usage.rs b/backend/crates/providers/openai/src/transport/usage.rs index ae04a892f..ec2d68078 100644 --- a/backend/crates/providers/openai/src/transport/usage.rs +++ b/backend/crates/providers/openai/src/transport/usage.rs @@ -96,25 +96,29 @@ const PRICING_RULES: &[PricingRule] = &[ model: "gpt-5.6-sol", pricing: ModelPricing::new(50_000, 300_000, 5_000) .with_cache_write(125) - .with_priority(100_000, 600_000, 10_000), + .with_priority(100_000, 600_000, 10_000) + .with_long_context(100_000, 450_000, 10_000, 0, 0, 0), }, PricingRule { model: "gpt-5.6-terra", - pricing: ModelPricing::new(25_000, 150_000, 2_500) + pricing: ModelPricing::new(20_000, 120_000, 2_000) .with_cache_write(125) - .with_priority(50_000, 300_000, 5_000), + .with_priority(40_000, 240_000, 4_000) + .with_long_context(40_000, 180_000, 4_000, 0, 0, 0), }, PricingRule { model: "gpt-5.6-luna", - pricing: ModelPricing::new(10_000, 60_000, 1_000) + pricing: ModelPricing::new(2_000, 12_000, 200) .with_cache_write(125) - .with_priority(20_000, 120_000, 2_000), + .with_priority(4_000, 24_000, 400) + .with_long_context(4_000, 18_000, 400, 0, 0, 0), }, PricingRule { model: "gpt-5.6", pricing: ModelPricing::new(50_000, 300_000, 5_000) .with_cache_write(125) - .with_priority(100_000, 600_000, 10_000), + .with_priority(100_000, 600_000, 10_000) + .with_long_context(100_000, 450_000, 10_000, 0, 0, 0), }, PricingRule { model: "gpt-5.5-pro", @@ -162,11 +166,11 @@ const PRICING_RULES: &[PricingRule] = &[ }, PricingRule { model: "gpt-4o-mini", - pricing: ModelPricing::new(1_500, 6_000, 0), + pricing: ModelPricing::new(1_500, 6_000, 750), }, PricingRule { model: "gpt-4o", - pricing: ModelPricing::new(25_000, 100_000, 0), + pricing: ModelPricing::new(25_000, 100_000, 12_500), }, PricingRule { model: "gpt-4-turbo", diff --git a/backend/crates/providers/openai/tests/transport/usage.rs b/backend/crates/providers/openai/tests/transport/usage.rs index 66f2b1947..139b4be99 100644 --- a/backend/crates/providers/openai/tests/transport/usage.rs +++ b/backend/crates/providers/openai/tests/transport/usage.rs @@ -30,6 +30,33 @@ fn billing_breakdown_should_preserve_input_output_and_cache_components() { assert_eq!(breakdown.multiplier_percent(), 100); } +#[test] +fn billing_breakdown_should_use_latest_gpt_5_6_and_cached_input_prices() { + let terra = openai_billing_breakdown("gpt-5.6-terra", 1, 1, 0, 0, None) + .expect("gpt-5.6-terra standard pricing"); + assert_eq!(terra.total_amount().amount().scaled(), 140_000); + + let terra_fast = openai_billing_breakdown("gpt-5.6-terra", 1, 1, 0, 0, Some("fast")) + .expect("gpt-5.6-terra fast pricing"); + assert_eq!(terra_fast.total_amount().amount().scaled(), 280_000); + + let terra_long = openai_billing_breakdown("gpt-5.6-terra", 272_001, 0, 0, 0, None) + .expect("gpt-5.6-terra long-context pricing"); + assert_eq!(terra_long.total_amount().amount().scaled(), 10_880_040_000); + + let luna = openai_billing_breakdown("gpt-5.6-luna", 1, 1, 0, 0, None) + .expect("gpt-5.6-luna standard pricing"); + assert_eq!(luna.total_amount().amount().scaled(), 14_000); + + let gpt_4o = + openai_billing_breakdown("gpt-4o", 1, 1, 1, 0, None).expect("gpt-4o cached-input pricing"); + assert_eq!(gpt_4o.total_amount().amount().scaled(), 112_500); + + let gpt_4o_mini = openai_billing_breakdown("gpt-4o-mini", 1, 1, 1, 0, None) + .expect("gpt-4o-mini cached-input pricing"); + assert_eq!(gpt_4o_mini.total_amount().amount().scaled(), 6_750); +} + #[test] fn billing_breakdown_should_apply_fast_and_flex_tiers_without_guessing_unknown_models() { let fast = openai_billing_breakdown("gpt-5.4", 1, 1, 0, 0, Some("fast")).expect("fast pricing");