Skip to content

fix(pricing): add Gemini 3.x pricing snapshots and normalize provider - #31382

Closed
Gautam-J wants to merge 1 commit into
NousResearch:mainfrom
Gautam-J:feat/gemini-pricing-snapshots
Closed

fix(pricing): add Gemini 3.x pricing snapshots and normalize provider#31382
Gautam-J wants to merge 1 commit into
NousResearch:mainfrom
Gautam-J:feat/gemini-pricing-snapshots

Conversation

@Gautam-J

Copy link
Copy Markdown

What does this PR do?

This PR fixes a bug where sessions using Google Gemini models (via the gemini provider) would display estimated costs as $0.00 (or n/a) in the Web Dashboard, /insights, and CLI status bar.

It solves two problems:

  1. Provider Mapping Gap: The static pricing table _OFFICIAL_DOCS_PRICING maps Google models under the "google" key. However, the canonical provider identifier used for API calls is "gemini". Since resolve_billing_route did not normalize "gemini" (or "google-gemini"/"google-ai-studio") to "google", billing checks resulted in "unknown" routes and $0.00 costs.
  2. Missing 3.x Models: Static pricing snapshots were missing for the latest Gemini 3.x generation, leaving models like gemini-3.5-flash and gemini-3.1-flash-lite with no base cost definition.

This PR normalizes Gemini provider aliases during billing route resolution and seeds standard pricing snapshots for the 3.x family, enabling accurate local cost metrics.

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✅ Tests (adding or improving test coverage)

Changes Made

  • agent/usage_pricing.py:
    • Normalized "gemini", "google-gemini", and "google-ai-studio" to the canonical "google" billing provider inside resolve_billing_route().
    • Added pricing snapshots for standard and cached tokens under the "google" key for the following models:
      • gemini-3.5-flash ($1.50/M input, $9.00/M output, $0.15/M cache-read)
      • gemini-3.1-flash-lite ($0.25/M input, $1.50/M output, $0.025/M cache-read)
      • gemini-3.1-flash-lite-preview ($0.25/M input, $1.50/M output, $0.025/M cache-read)
      • gemini-3-flash-preview ($0.50/M input, $3.00/M output, $0.05/M cache-read)
  • tests/agent/test_usage_pricing.py:
    • Added unit tests checking the existence of these new pricing entries.
    • Added integrated test asserting that estimate_usage_cost successfully calculates the expected cost breakdown when invoked under the "gemini" provider namespace.

How to Test

  1. Run the targeted pricing test suite to ensure mapping and math calculations work flawlessly:
    bash
    pytest tests/agent/test_usage_pricing.py

  2. Verify in a live session that costs are now actively logged and displayed on subsequent turns when using provider: gemini and any of the supported 3.x models.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (feat(pricing): add Gemini 3.x pricing snapshots and normalize provider)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass (pricing tests verified passing locally)
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • My platform is: Raspberry Pi OS (Linux debian-based, ARM64)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

bash
tests/agent/test_usage_pricing.py ............... [100%]
============================== 15 passed in 0.86s ==============================

@Gautam-J

Copy link
Copy Markdown
Author

@maintainers FYI this change was completely made by my hermes-agent - Samantha (from "Her").

I did review the code myself, and i have verified that costs for these models are showing up fine on my dashboard instance.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/gemini Google Gemini (AI Studio, Cloud Code) labels May 24, 2026
hbentel added a commit to hbentel/hermes-agent that referenced this pull request May 27, 2026
…h-lite-preview entry

Extends resolve_billing_route to include the full set of gemini profile
aliases (google, google-gemini, google-ai-studio) alongside the already-
covered gemini and google-gemini-cli names, so all entry points map to
the google pricing table.  Adds the gemini-3.1-flash-lite-preview pricing
entry that was present in the competing fix (NousResearch#31382).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@hbentel

hbentel commented May 27, 2026

Copy link
Copy Markdown
Contributor

This overlaps with #32404. Both fix the same root issue but cover different gaps:

#32404 has since been updated to cover all aliases including google-gemini-cli and also includes gemini-3.1-flash-lite-preview, making it a strict superset. Recommend consolidating into #32404 and closing this one.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for identifying the direct-Gemini accounting gap. The premise remains valid on current main: plugins/model-providers/gemini/__init__.py:51-58 registers the canonical provider as gemini, while agent/usage_pricing.py:654-677 has no Gemini route and falls through to billing_mode="unknown"; the session loop forwards that provider into costing at agent/conversation_loop.py:2183-2189.

Problems

  • The added per-model table-entry/value assertions are change-detector tests. AGENTS.md:1311-1355 explicitly excludes model-catalog and hardcoded-list snapshots because routine pricing/model updates should not break CI.

Suggested changes

  • Keep a behavioral end-to-end regression for a direct provider="gemini" cost estimate, but replace the individual snapshot assertions with a stable routing/estimation invariant.

Automated hermes-sweeper review.

@alt-glitch alt-glitch added P2 Medium — degraded but workaround exists area/billing Account usage, credit usage, billing (cross-cutting) and removed P3 Low — cosmetic, nice to have labels Jul 13, 2026
@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing — the route fix + Gemini 3.x pricing this PR proposed landed on main via #73516 (salvage of #60063 plus follow-ups). You were the earliest submitter to identify the missing resolve_billing_route() branch and the missing Gemini 3.x snapshot entries (May 24, ahead of both #32404 and #60063) — credited here and in the salvage PR. The merged version covers your route branch (google/gemini + aliases), your 3.5-flash / 3.1-flash-lite(+preview) / 3-flash-preview entries, and adds 3.6-flash. Thanks @Gautam-J!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing Account usage, credit usage, billing (cross-cutting) comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/gemini Google Gemini (AI Studio, Cloud Code) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants