Repository navigation
fix(cost): bill speech at a deployment's custom per-character price - #53265
Conversation
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ef452e2. Configure here.
| "input_cost_per_query", | ||
| "input_cost_per_text_message", | ||
| "input_cost_per_character", | ||
| "output_cost_per_character", |
There was a problem hiding this comment.
Zero per-character speech price marked as unknown
Medium Severity
Cost selection now picks up a deployment's per-character rate, but _response_price_is_known and cost_headers don't. For a deployment priced at 0, the cost is 0 while price_known stays false, so the proxy drops x-litellm-response-cost. The request then looks unpriced instead of free. The PR's own live run shows this, and the new test only checks completion_cost.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit ef452e2. Configure here.
There was a problem hiding this comment.
The cost here is 0 and known. The speech route reads it with or "", so any zero cost drops the header. That line predates this PR, so I am leaving it for a follow-up.
There was a problem hiding this comment.
Fixed in d8119f1. The cost was already 0 and known, the speech route dropped it with or "". It now sends 0.0, with a test.
[Medium impact] This PR appears safe to merge with no outstanding findings.
|
|
bugbot run |
Bugbot is paused — your team has an unpaid invoiceBugbot is paused because your team has an unpaid invoice. Pay it from the billing page in the Cursor dashboard and Bugbot resumes automatically. (requestId: 580d6d73-0076-485a-93fb-c008cad807f1) |
|
bugbot run |
Bugbot is paused — your team has an unpaid invoiceBugbot is paused because your team has an unpaid invoice. Pay it from the billing page in the Cursor dashboard and Bugbot resumes automatically. (requestId: f26e45c2-8a70-4eae-909c-762b85e43497) |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |


Handwritten 1-3 sentence description
Setting your own per-character price on a text-to-speech model now changes the tracked cost. Before, the proxy ignored it and billed the public list price.
Details
Link to Devin session: https://app.devin.ai/sessions/1d80c4eaf5034fd2882d1a7921ff4763
Open in Devin Desktop: https://app.devin.ai/desktop/session/1d80c4eaf5034fd2882d1a7921ff4763?variant=devin
Requested by: @kenneth-berri
TLDR
Problem this solves:
input_cost_per_characteron a speech deployment was ignoredHow it solves it:
/v1/audio/speechroute sends a zero cost as0.0instead of dropping the headerUser Flow
Before: a proxy admin with their own text-to-speech rate sees spend tracked at the public list price
input_cost_per_character: 0.0002undermodel_info(orlitellm_params) on an ElevenLabs or OpenAI speech model and restart the proxyx-litellm-response-cost: 0.00256for ElevenLabs, which is the public rate of 0.00008 per characterAfter: the same request is tracked at the admin's own rate
input_cost_per_character: 0.0002undermodel_info(orlitellm_params) on the same model and restart the proxyx-litellm-response-cost: 0.0064, which is 32 billed characters at 0.0002Relevant issues
Found while reproducing #18058. That issue is closed and was about a missing price row, this is the custom price override on the same route.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<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 moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live proxy against real ElevenLabs and OpenAI. One worker, no Redis and no database, because the cost of one request does not depend on shared state. Before is the merge base f74d0dc and After is b37e26d.
Env vars:
ELEVENLABS_API_KEY,OPENAI_API_KEYProxy command:
python litellm/proxy/proxy_cli.py --config config.yaml --port 4060config.yaml
run.sh, the client
Before (f74d0dc)
./run.shEvery override row is billed at the list price, including the row priced at 0.
After (b37e26d)
./run.shThe override rows are billed at 32 characters times 0.0002, and the list price rows are unchanged. The free row reports 0.0.
Regression test:
tests/unit/test_cost_calculator.py::test_speech_cost_bills_the_deployment_per_character_rate, 8 cases, all fail at the merge base and pass at b37e26d.tests/unit/proxy/proxy_server/test_routes_audio.py::test_audio_speech_reports_a_free_clip_as_zero_costcovers the header, and its zero cost case fails without the route change.Type
🐛 Bug Fix
Caveats (if any)
Medium
Low
x-litellm-response-cost: 0.0Final Attestation