Repository navigation
fix(cost): bill audio input once when both per-token and per-second rates exist - #41158
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…ates exist Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR prevents audio input from being charged by both token count and duration when both rates are configured.
Confidence Score: 5/5The PR appears safe to merge; the billing precedence is consistent with the configured rates and is covered in both directions. No actionable failures remain: the rate probe and charge use identical fallback semantics, per-second billing remains available when token pricing is absent, and the modified Vertex tests accurately reflect catalog pricing.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/llm_cost_calc/utils.py | Adds consistent per-token precedence to prevent duplicate audio input charges while preserving per-second fallback. |
| tests/test_litellm/litellm_core_utils/llm_cost_calc/test_llm_cost_calc_utils.py | Covers both dual-rate token precedence and duration-only fallback behavior. |
| tests/test_litellm/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_transformation.py | Updates Vertex Gemini embedding cost assertions to the configured per-audio-token rate without weakening modality-accounting checks. |
Reviews (1): Last reviewed commit: "fix(cost): bill audio input once when bo..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
gemini-embedding-2audio input is billed twice after the pricing syncinput_cost_per_audio_token; catalog also keepsinput_cost_per_audio_per_secondHow it solves it:
User Flow
Before: a user embedding an audio clip on Vertex is overcharged for the audio
"model": "vertex_ai/gemini-embedding-2"and a 2 second audio fileAfter: the same request is billed once
"model": "vertex_ai/gemini-embedding-2"and the same clipRelevant issues
Fixes the
Vertex AI / Run testsfailure on #41154 (generated pricing sync PR). Do not edit that PR; this lands independentlyRaw provider evidence, fetched with
curl -sL "https://cloud.google.com/gemini-enterprise-agent-platform/generative-ai/pricing?x=$RANDOM"and parsed from the HTML table for "Gemini Embedding 2 (Unified Multimodal, Preview)":Google now prices audio per token ($6.50/1M = 6.5e-6 per token). The older per-second rate in the catalog (0.00016/s at 32 tokens/s = 5e-6 per token) is not what the page publishes, so the per-token rate wins whenever it exists
Affected release
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Cost math only, no provider call needed. Shared script
cost_check.py:Before (b67137b)
LITELLM_LOCAL_MODEL_COST_MAP=True uv run python cost_check.py0.000736(64 * 6.5e-6 + 2 * 0.00016, audio billed twice)After (e5391c8)
LITELLM_LOCAL_MODEL_COST_MAP=True uv run python cost_check.py0.000416(64 * 6.5e-6)Type
🐛 Bug Fix
Caveats (if any)
Low
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/10c57e7b5dec41e29684a8c42c5c6aab
Open in Devin Desktop: https://app.devin.ai/desktop/session/10c57e7b5dec41e29684a8c42c5c6aab?variant=devin