fix(pricing): resolve gemini-default routing label for submission

Merged
YU
4mo ago
+283-8

Summary

antigravity-cli records sessions with gemini-default (Google AI Studio's generic routing label) when no specific model is selected. Local reports priced this label through fuzzy matching, but tokscale submit validation requires every token bucket to have a rate, so any session with cached-prefix tokens failed with pricing is unavailable for submitted token usage: google/gemini-default (issue #1019).

This PR makes the label resolve deterministically and prices it with full bucket coverage:

  • Add a pricing alias gemini-default -> gemini-2.0-flash-lite (same target the local display already fuzzy-matched to, matching the issue's suggested mapping).
  • Block the bare brand token gemini in fuzzy matching, so generic ids that erode to gemini can no longer land on an unrelated gemini key (e.g. a native-audio preview with no cache rates).
  • Add a usage-aware fallback in submission validation and cost calculation: when the provider-hinted resolution (e.g. vercel_ai_gateway/google/gemini-2.0-flash-lite, which has no cache-read rates) cannot cover the usage, retry the canonical unhinted resolution (the bare official key, which has cache rates). This also protects other models whose hinted reseller row lacks rates.

Root cause

google/gemini-default has no exact pricing key. The lookup strips the -default suffix, and fuzzy matching then selected the longest unrelated gemini key (dataset-dependent; e.g. gemini/gemini-2.5-flash-native-audio-preview-12-2025). Those rows have input/output rates but no cache-read rates, while Antigravity CLI sessions routinely include cacheRead tokens. covers_usage requires every populated bucket to have a rate, so validation failed for the whole submission. Local display still worked because cost display only needs input/output rates.

Reproduced against the real LiteLLM dataset in both the current shape and an older-cache shape (without the later-added live-audio key): pure input/output usage passed validation while input/output + cacheRead + reasoning failed. After the fix both pass.

Validation

  • cargo test -p tokscale-core: 1357 lib tests + all integration suites pass (new regression tests cover the alias, the fuzzy blocklist, the Antigravity CLI parser, and submission validation with cache-read usage).
  • cargo test -p tokscale-cli: 993 unit + 132 integration pass.
  • Real-dataset probe: covers_usage_with_provider("gemini-default", Some("google"), cache-read usage) is now true on the current LiteLLM dataset and on the older-cache simulation, with cost computed at full flash-lite rates.
  • cargo fmt --check and git diff --check clean.

Boundary

The gemini-default -> gemini-2.0-flash-lite mapping is taken from the issue reporter's local display behavior and the issue's suggested mapping; it is not confirmed against official Google/Antigravity documentation. If the maintainers know the actual default-routing billable model, only the single alias line needs updating - the fallback fix is independent of that choice.

Known CI note

test_pricing_command_with_provider in the CLI integration suite depends on live LiteLLM data and fails on main too because upstream removed the bare claude-sonnet-4-20250514 key. Verified by running that test with this change stashed: it fails identically on the base commit. This PR does not change that behavior.

Fixes #1019


Summary by cubic

Fix submission pricing for Google’s gemini-default by resolving it to gemini-2.0-flash-lite when it fully covers the used buckets and excluding unpriceable generic routing usage from submission. Submissions now price covered tokens (including cache-read) and no longer fail validation; the CLI warns about excluded generic usage without promising a submission when none remains. Fixes #1019.

  • Bug Fixes
    • Added alias: gemini-default -> gemini-2.0-flash-lite only when it covers all used buckets; otherwise keep provider pricing.
    • Blocked bare brand token gemini in fuzzy matching to avoid wrong hits.
    • Preserved the generic routing label in session parsing and excluded unpriced google/gemini-default messages from submission.
    • CLI: print per-model exclusion warnings with counts/tokens; show “Remaining priced usage will be submitted.” only if priced usage exists, otherwise “No usage data found to submit.”