Port upstream 0.70.0: price Mistral usage by event type, API zone and service tier - #718
Conversation
Upstream steipete#4076 (b468e0d). The billing price table lists one metric once per API zone and service tier and again under other event types, so keying prices by metric and group let the last row win: a per-second audio price or a priority-tier price could price ordinary token rows. Usage rows and prices now carry event_type, api_zone and service_tier. A row takes the price with the same event type, metric, group, zone and tier. Only a legacy price row that omits both zone and tier is a fallback, for rows with the same event type, metric and group; a zone or tier is never guessed. The lookup lives in a new pricing submodule.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Ports upstream v0.70.0 steipete#4076: Mistral API spend now prices each billed usage row by its event type, API zone and service tier, not by billing metric and group alone.
metric::group, the last row won. In upstream's real September 2026 sample,mistral-medium-3-5input was priced at the per-second audio rate, which is 100x the token rate, and cached and output tokens took the EU priority rates.event_type,api_zoneandservice_tier. A row takes the price with the same event type, metric, group, zone and tier.providers/mistral/pricing.rssubmodule, which keepsmod.rsat 853 lines.Token totals are unchanged: they already count consumed units per category.
Stacked on #657 (
port/micro-0.68.0-mistral-plan-detail), like #717. This PR and #717 change different parts ofproviders/mistral/mod.rs.Upstream reference
b468e0dbf3(v0.70.0 release notes: "Mistral: price billing usage by event type, API zone, and service tier").v0.70.0sources:MistralModels.swift(apiZoneandserviceTieronMistralUsageEntryandMistralPrice),MistralUsageFetcher.swift(PriceKey, the exact key then the zoneless key, a later duplicate wins),Tests/CodexBarTests/MistralUsageParserTests.swiftanddocs/mistral.md.Ported / Deferred
event_type,api_zoneandservice_tieron usage rows and pricespricing.rstests)MistralUsageFetcher(library tokens count only in daily buckets)docs/mistral.mdparagraphpricing.rsmodule comment.Validation
Run in the worker worktree on Rust 1.98.0 at
12c366e7:cargo +1.98.0 fmt --all --checkcargo +1.98.0 clippy --workspace --all-targets -- -D warningscargo +1.98.0 test -p codexbar providers::mistralcargo +1.98.0 test -p codexbarcargo +1.98.0 test -p codexbar-desktop-tauri -- --skip bootstrap_payload_exposes_every_provider_variantThe skipped desktop test is the non-hermetic #684 test, which is not on this stacked base. #711 fixes it. The frontend is unchanged.
New tests in
providers/mistral/pricing.rs:prices_entries_by_event_type_zone_and_tier_instead_of_the_last_matching_metric: upstream's September 2026 sample, in both table orders. The oldmetric::groupkey fails the original order.legacy_prices_match_qualified_usage_without_guessing_a_zone_or_tier: the unqualified price costs 40 billed units x 0.25 = 10. The EU-standard and global-priority prices cost 0, where the old key charged 10.exact_dimensions_win_over_the_unqualified_legacy_row,a_partly_qualified_price_is_not_a_fallback,event_type_must_match_even_for_the_legacy_rowandrows_without_a_metric_or_group_have_no_price.Affected areas
rust/src/providers/mistral/pricing.rs(new):MistralPrice,PriceIndexand tests.rust/src/providers/mistral/mod.rs: usage-row fields and the price lookup.UI proof
Not applicable: backend only. The change alters the Mistral spend amount, not any UI surface, and the tests above cover it.