Skip to content

fix(cost): backport usage.seconds billing and the unsized FLAC guard to lts/1.108.x - #50860

Merged
yuneng-berri merged 5 commits into
lts/1.108.xfrom
litellm_backport_transcription_usage_seconds_lts_1_108_x
Nov 10, 2026
Merged

yuneng-berri merged 5 commits into
lts/1.108.xfrom
litellm_backport_transcription_usage_seconds_lts_1_108_x

Conversation

@kerry-berri

@kerry-berri kerry-berri commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Backport of the transcription billing fix to lts/1.108.x. The main side is #35600, #50727 (the usage.seconds slice, hand-ported as one commit) and #50842 (the unsized FLAC guard, picked as its four commits). #50842 has merged on main.

Problem this solves:

  • A FLAC encoded to a pipe has no sample count in its header
  • libsndfile reports 2**63 - 1 frames for it, so one request bills $43,234,556,422.76
  • The key is then over budget and every later request fails with 422
  • On this line that hits both json and text responses

How it solves it:

  • Transcriptions bill the provider's usage.seconds first when it is a valid positive number
  • Otherwise the measured length, otherwise 0
  • An unknown frame count is treated as no duration, not as 576 trillion seconds
  • The Amazon Transcribe passthrough duration helper gets the same guard

User Flow

Before: a developer who transcribes a FLAC that was encoded to a pipe is billed about $43 billion for one request, and the key stops working

  1. They run ffmpeg -i normal.flac -f flac - > piped.flac, which writes a FLAC with no sample count in its header
  2. They send POST https://litellm-domain/v1/audio/transcriptions with model=gpt-transcribe, response_format=json and piped.flac, and get 200 with the transcript
  3. The response carries x-litellm-response-cost: 43234556422.75676 and the key's spend jumps to the same amount against its $500 budget
  4. Their next POST on that key, with any file, returns 422 Budget has been exceeded! ... Current cost: 43234556422.76061, Max budget: 500.0

After: the same request bills the 11 seconds OpenAI reports, and the key keeps working

  1. They run ffmpeg -i normal.flac -f flac - > piped.flac, which writes a FLAC with no sample count in its header
  2. They send POST https://litellm-domain/v1/audio/transcriptions with model=gpt-transcribe, response_format=json and piped.flac, and get 200 with the transcript
  3. The response carries x-litellm-response-cost: 0.0008249999999999999 (11 s x $0.000075) and the key's spend rises by that amount. With response_format=text there is no usage, so that request bills $0 and carries no cost header
  4. Their next POST on that key with normal.flac returns 200 and bills $0.000825

Linear ticket

Resolves LIT-10595

Backport checklist

  • Line lts/1.108.x, base 2a56160037 (v1.108.4 + 11). No LiteLLM version bump on the LTS line, enterprise/ and litellm-proxy-extras/ untouched so no subpackage bump
  • 76539f9156 fix(cost): bill transcriptions by the seconds the provider reports, hand-ported slice of feat(realtime)!: support latest OpenAI audio models #35600 and fix(cost)!: bill transcriptions by the seconds the provider reports #50727, clean
  • 70f388a8ab fix(transcription): treat libsndfile's unknown frame count as no duration, cherry-pick of e6a0534, adapted to the line: the line's tests/unit/litellm_core_utils/test_audio_utils.py lacks main's from typing import Final, so make check (ruff on the test tree) reported F821 on the new streaminfo: Final. The import was added inside this pick
  • 3f50c8734e refactor(transcription): inline the unknown frame count check, cherry-pick of b6d25f2, clean
  • 0e5241c504 fix(transcription): read the frame count once to keep the type gate flat, cherry-pick of 54dcd92, clean
  • 0633730678 test(transcription): annotate the new passthrough test's locals as Final, cherry-pick of eb0f251, clean
  • Picked tests green on the line: 825 passed across the 10 unit test files that reach the changed code, with LITELLM_LOCAL_MODEL_COST_MAP=True PYTHONPATH="$PWD:$PWD/enterprise". No pass-to-fail transition against the line tip
  • BASE_REF=origin/lts/1.108.x make check: PASS at the tip (the first run at the pre-fix tip failed only on the F821 above)
  • ruff check --select F821,F811 on the changed litellm/ files clean, scoped ruff format --check clean, AST importer scan found no dropped module-level name
  • grype v0.100.0 on the line's uv.lock vs main's: nothing to bump. Every finding (pillow 12.3.0, dnspython 2.8.0, filelock 3.20.3, tornado 6.5.10) is at the same version on main, and the one line-only finding, diskcache 5.6.3 GHSA-w8v5-vhqr-4h9v, has no fixed release
  • gauntlet-mini (degraded mode, 5 lenses run by hand, no Agent tool): CONFIRMED, 5/5 lenses clear, 1 finding (the missing Final import) reproduced by running ruff on the test tree and fixed inside its pick, 0 dissent. Identifiers resolve on the line, picked tests pass, no line-only caller of _transcription_duration_for_cost, calculate_request_duration or media_file_seconds breaks (main.py guards None, the Azure speech handler does or 0.0, the Transcribe handler already routes None to its max-job-cost path)
  • Integration harness on the line, python tests/integration/run.py cost --workers 2 with the three whisper cases whisper-next-transcriptions-per-second, whisper-next-transcriptions-unsized-flac-no-usage, whisper-verbose-next-transcriptions-duration: 3 passed

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays 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

Both legs ran against a live proxy with real OpenAI gpt-transcribe and whisper-1 calls, Postgres, one dedicated Redis on port 6390 and two workers. Each leg had its own empty database. The line prints "workers" flag is ignored when reloading is enabled and starts one worker with --reload, so both proxies ran without --reload and each logged two Started server process lines.

Proxy command, run from a checkout of each commit, port 4111 for Before and 4112 for After. Env vars set were OPENAI_API_KEY, LITELLM_MASTER_KEY, DATABASE_URL and STORE_MODEL_IN_DB=True.

python litellm/proxy/proxy_cli.py --config qa_config.yaml --port 4111 --num_workers 2 --detailed_debug --use_v2_migration_resolver

qa_config.yaml

model_list:
  - model_name: gpt-transcribe
    litellm_params:
      model: openai/gpt-transcribe
      api_key: os.environ/OPENAI_API_KEY
  - model_name: whisper-1
    litellm_params:
      model: openai/whisper-1
      api_key: os.environ/OPENAI_API_KEY

router_settings:
  redis_host: 127.0.0.1
  redis_port: 6390

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  coordination_redis:
    host: 127.0.0.1
    port: 6390

normal.flac is 11.000 s of real speech (OpenAI gpt-4o-mini-tts wav, ffmpeg -ar 16000 -ac 1), piped.flac is ffmpeg -i normal.flac -f flac - > piped.flac. soundfile reads normal.flac as 176000 frames at 16 kHz and piped.flac as 9223372036854775807 frames. Rates from this line's cost map: gpt-transcribe $0.000075/s, whisper-1 $0.0001/s, so 11 s is $0.000825 and $0.0011.

Key A (max_budget: 500) runs cases 1, 2, 6a, 6b, 7, 3, 5a in that order. Key B (fresh, max_budget: 500) runs 4 then 5b, so the text case is not masked by key A already being over budget on Before. Each row reads status, x-litellm-response-cost, the LiteLLM_SpendLogs row's spend, and the key's spend from /key/info.

Case Before (2a56160) After (0633730)
1. normal.flac, gpt-transcribe, json 200, 0.000825, 0.000825, 0.000825 200, 0.000825, 0.000825, 0.000825
2. normal.flac, gpt-transcribe, text 200, 0.000825, 0.000825, 0.00165 200, 0.000825, 0.000825, 0.00165
6a. normal.flac, whisper-1, json 200, 0.0011, 0.0011, 0.00275 200, 0.0011, 0.0011, 0.00275
6b. normal.flac, whisper-1, verbose_json 200, 0.0011, 0.0011, 0.00385 200, 0.0011, 0.0011, 0.00385
7. normal.flac, gpt-transcribe, verbose_json 400 from OpenAI, verbose_json is not compatible with gpt-transcribe, no header, failure row 0, 0.00385 same 400, no header, failure row 0, 0.00385
3. piped.flac, gpt-transcribe, json 200, 43234556422.75676, 43234556422.75676, 43234556422.76061 200, 0.000825, 0.000825, 0.004675
5a. normal.flac, gpt-transcribe, json, key A after 3 422 budget exceeded, no header, failure row 0, 43234556422.76061 200, 0.000825, 0.000825, 0.0055
4. piped.flac, gpt-transcribe, text, key B 200, 43234556422.75676, 43234556422.75676, 43234556422.75676 200, header absent, success row 0, 0.0
5b. normal.flac, gpt-transcribe, json, key B after 4 422 budget exceeded, no header, failure row 0, 43234556422.75676 200, 0.000825, 0.000825, 0.000825
cases.sh, run as LITELLM_MASTER_KEY=... ./cases.sh <port> <database_url> <label>
#!/usr/bin/env bash
# usage: LITELLM_MASTER_KEY=... ./cases.sh <port> <database_url> <label>
PORT=$1; DB=$2; LABEL=$3; B=http://localhost:$PORT; ALIAS=flac-$LABEL-$PORT-$(date +%s)
cd /tmp/qa_lts
q() { psql "$DB" -Atc "$1"; }
spend_rows() { q "select count(*) from \"LiteLLM_SpendLogs\" s join \"LiteLLM_VerificationToken\" k on k.token = s.api_key where k.key_alias = '$ALIAS'"; }
key_spend() { curl -s "$B/key/info?key=$KEY" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | python3 -c 'import sys,json;print(json.load(sys.stdin)["info"]["spend"])'; }
transcribe() {
  local label=$1 file=$2 model=$3 fmt=$4
  local before_rows; before_rows=$(spend_rows)
  local http; http=$(curl -s -D /tmp/qa_lts/h_$LABEL.txt -o /tmp/qa_lts/b_$LABEL.txt -w "%{http_code}" $B/v1/audio/transcriptions -H "Authorization: Bearer $KEY" \
    -F model=$model -F response_format=$fmt -F file=@$file)
  local cost; cost=$(grep -i '^x-litellm-response-cost:' /tmp/qa_lts/h_$LABEL.txt | tr -d '\r' | awk '{print $2}')
  local row_spend="(no row)"
  for i in $(seq 1 40); do [ "$(spend_rows)" -gt "$before_rows" ] && break; sleep 2; done
  row_spend=$(q "select s.status || '|' || s.spend || '|' || coalesce(s.model,'') from \"LiteLLM_SpendLogs\" s join \"LiteLLM_VerificationToken\" k on k.token = s.api_key where k.key_alias = '$ALIAS' order by s.\"startTime\" desc limit 1")
  sleep 6
  echo "$label | model=$model fmt=$fmt file=$file | http=$http | x-litellm-response-cost=${cost:-<absent>} | spend_log(status|spend|model)=$row_spend | key_spend=$(key_spend)"
  echo "   body: $(head -c 160 /tmp/qa_lts/b_$LABEL.txt | tr '\n' ' ')"
}
KEY=$(curl -s $B/key/generate -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
  -d "{\"max_budget\": 500, \"models\": [\"gpt-transcribe\", \"whisper-1\"], \"key_alias\": \"$ALIAS\"}" | python3 -c 'import sys,json;print(json.load(sys.stdin)["key"])')
echo "== $LABEL port=$PORT litellm version=$(curl -s -D - -o /dev/null $B/health/liveliness | grep -i '^x-litellm-version' | tr -d '\r' | awk '{print $2}') key alias=$ALIAS max_budget=500"
echo "normal.flac $(ffprobe -v error -show_entries format=duration -of csv=p=0 normal.flac)s, piped.flac $(ffprobe -v error -show_entries format=duration -of csv=p=0 piped.flac)"
transcribe "1. normal json gpt-transcribe" normal.flac gpt-transcribe json
transcribe "2. normal text gpt-transcribe" normal.flac gpt-transcribe text
transcribe "6a. whisper-1 normal json" normal.flac whisper-1 json
transcribe "6b. whisper-1 normal verbose_json" normal.flac whisper-1 verbose_json
transcribe "7. gpt-transcribe normal verbose_json" normal.flac gpt-transcribe verbose_json
transcribe "3. piped json gpt-transcribe" piped.flac gpt-transcribe json
transcribe "5a. normal json gpt-transcribe, same key after piped json" normal.flac gpt-transcribe json
echo "-- fresh key B for the text case (key A may already be over budget)"
KEY_A=$KEY; ALIAS_A=$ALIAS; ALIAS=$ALIAS-b
KEY=$(curl -s $B/key/generate -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' \
  -d "{\"max_budget\": 500, \"models\": [\"gpt-transcribe\", \"whisper-1\"], \"key_alias\": \"$ALIAS\"}" | python3 -c 'import sys,json;print(json.load(sys.stdin)["key"])')
transcribe "4. piped text gpt-transcribe (key B)" piped.flac gpt-transcribe text
transcribe "5b. normal json gpt-transcribe, key B after piped text" normal.flac gpt-transcribe json
for a in $ALIAS_A $ALIAS; do
echo "LiteLLM_SpendLogs for $a (status|spend|model|startTime):"
q "select s.status, s.spend, s.model, s.\"startTime\" from \"LiteLLM_SpendLogs\" s join \"LiteLLM_VerificationToken\" k on k.token = s.api_key where k.key_alias = '$a' order by s.\"startTime\""
echo "LiteLLM_VerificationToken spend|max_budget for $a: $(q "select spend, max_budget from \"LiteLLM_VerificationToken\" where key_alias = '$a'")"
done
echo "/key/info spend key A: $(KEY=$KEY_A key_spend)  key B: $(key_spend)"

Before (2a56160)

  1. ./cases.sh 4111 postgresql://postgres:postgres@localhost:5432/lts_qa_before before
output
== before port=4111 litellm version= key alias=flac-before-4111-1794293030 max_budget=500
normal.flac 11.000000s, piped.flac N/A
1. normal json gpt-transcribe | model=gpt-transcribe fmt=json file=normal.flac | http=200 | x-litellm-response-cost=0.0008249999999999999 | spend_log(status|spend|model)=success|0.0008249999999999999|openai/gpt-transcribe | key_spend=0.0008249999999999999
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
2. normal text gpt-transcribe | model=gpt-transcribe fmt=text file=normal.flac | http=200 | x-litellm-response-cost=0.0008249999999999999 | spend_log(status|spend|model)=success|0.0008249999999999999|openai/gpt-transcribe | key_spend=0.00165
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
6a. whisper-1 normal json | model=whisper-1 fmt=json file=normal.flac | http=200 | x-litellm-response-cost=0.0011 | spend_log(status|spend|model)=success|0.0011|openai/whisper-1 | key_spend=0.00275
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that a
6b. whisper-1 normal verbose_json | model=whisper-1 fmt=verbose_json file=normal.flac | http=200 | x-litellm-response-cost=0.0011 | spend_log(status|spend|model)=success|0.0011|openai/whisper-1 | key_spend=0.00385
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that a
7. gpt-transcribe normal verbose_json | model=gpt-transcribe fmt=verbose_json file=normal.flac | http=400 | x-litellm-response-cost=<absent> | spend_log(status|spend|model)=failure|0|openai/gpt-transcribe | key_spend=0.00385
   body: {"error":{"message":"litellm.BadRequestError: OpenAIException - response_format 'verbose_json' is not compatible with model 'gpt-transcribe-api-ev3'. Use 'json'
3. piped json gpt-transcribe | model=gpt-transcribe fmt=json file=piped.flac | http=200 | x-litellm-response-cost=43234556422.75676 | spend_log(status|spend|model)=success|43234556422.75676|openai/gpt-transcribe | key_spend=43234556422.76061
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
5a. normal json gpt-transcribe, same key after piped json | model=gpt-transcribe fmt=json file=normal.flac | http=422 | x-litellm-response-cost=<absent> | spend_log(status|spend|model)=failure|0|openai/gpt-transcribe | key_spend=43234556422.76061
   body: {"error":{"message":"Budget has been exceeded! Key=flac-before-4111-1794293030 (sk-...redacted) Current cost: 43234556422.76061, Max budget: 500.0","type":"budget_e
-- fresh key B for the text case (key A may already be over budget)
4. piped text gpt-transcribe (key B) | model=gpt-transcribe fmt=text file=piped.flac | http=200 | x-litellm-response-cost=43234556422.75676 | spend_log(status|spend|model)=success|43234556422.75676|openai/gpt-transcribe | key_spend=43234556422.75676
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
5b. normal json gpt-transcribe, key B after piped text | model=gpt-transcribe fmt=json file=normal.flac | http=422 | x-litellm-response-cost=<absent> | spend_log(status|spend|model)=failure|0|openai/gpt-transcribe | key_spend=43234556422.75676
   body: {"error":{"message":"Budget has been exceeded! Key=flac-before-4111-1794293030-b (sk-...redacted) Current cost: 43234556422.75676, Max budget: 500.0","type":"budget
LiteLLM_SpendLogs for flac-before-4111-1794293030 (status|spend|model|startTime):
success|0.0008249999999999999|openai/gpt-transcribe|2026-11-10 06:43:52.524
success|0.0008249999999999999|openai/gpt-transcribe|2026-11-10 06:44:06.901
success|0.0011|openai/whisper-1|2026-11-10 06:44:20.455
success|0.0011|openai/whisper-1|2026-11-10 06:44:32.619
failure|0|openai/gpt-transcribe|2026-11-10 06:44:44.035
success|43234556422.75676|openai/gpt-transcribe|2026-11-10 06:44:58.736
failure|0|openai/gpt-transcribe|2026-11-10 06:45:08.068
LiteLLM_VerificationToken spend|max_budget for flac-before-4111-1794293030: 43234556422.76061|500
LiteLLM_SpendLogs for flac-before-4111-1794293030-b (status|spend|model|startTime):
success|43234556422.75676|openai/gpt-transcribe|2026-11-10 06:45:20.776
failure|0|openai/gpt-transcribe|2026-11-10 06:45:38.121
LiteLLM_VerificationToken spend|max_budget for flac-before-4111-1794293030-b: 43234556422.75676|500
/key/info spend key A: 43234556422.76061  key B: 43234556422.75676

After (0633730)

  1. ./cases.sh 4112 postgresql://postgres:postgres@localhost:5432/lts_qa_after after
output
== after port=4112 litellm version= key alias=flac-after-4112-1794293042 max_budget=500
normal.flac 11.000000s, piped.flac N/A
1. normal json gpt-transcribe | model=gpt-transcribe fmt=json file=normal.flac | http=200 | x-litellm-response-cost=0.0008249999999999999 | spend_log(status|spend|model)=success|0.0008249999999999999|openai/gpt-transcribe | key_spend=0.0008249999999999999
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
2. normal text gpt-transcribe | model=gpt-transcribe fmt=text file=normal.flac | http=200 | x-litellm-response-cost=0.0008249999999999999 | spend_log(status|spend|model)=success|0.0008249999999999999|openai/gpt-transcribe | key_spend=0.00165
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
6a. whisper-1 normal json | model=whisper-1 fmt=json file=normal.flac | http=200 | x-litellm-response-cost=0.0011 | spend_log(status|spend|model)=success|0.0011|openai/whisper-1 | key_spend=0.00275
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that a
6b. whisper-1 normal verbose_json | model=whisper-1 fmt=verbose_json file=normal.flac | http=200 | x-litellm-response-cost=0.0011 | spend_log(status|spend|model)=success|0.0011|openai/whisper-1 | key_spend=0.00385
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that a
7. gpt-transcribe normal verbose_json | model=gpt-transcribe fmt=verbose_json file=normal.flac | http=400 | x-litellm-response-cost=<absent> | spend_log(status|spend|model)=failure|0|openai/gpt-transcribe | key_spend=0.00385
   body: {"error":{"message":"litellm.BadRequestError: OpenAIException - response_format 'verbose_json' is not compatible with model 'gpt-transcribe-api-ev3'. Use 'json'
3. piped json gpt-transcribe | model=gpt-transcribe fmt=json file=piped.flac | http=200 | x-litellm-response-cost=0.0008249999999999999 | spend_log(status|spend|model)=success|0.0008249999999999999|openai/gpt-transcribe | key_spend=0.004675
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
5a. normal json gpt-transcribe, same key after piped json | model=gpt-transcribe fmt=json file=normal.flac | http=200 | x-litellm-response-cost=0.0008249999999999999 | spend_log(status|spend|model)=success|0.0008249999999999999|openai/gpt-transcribe | key_spend=0.005500000000000001
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
-- fresh key B for the text case (key A may already be over budget)
4. piped text gpt-transcribe (key B) | model=gpt-transcribe fmt=text file=piped.flac | http=200 | x-litellm-response-cost=<absent> | spend_log(status|spend|model)=success|0|openai/gpt-transcribe | key_spend=0.0
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
5b. normal json gpt-transcribe, key B after piped text | model=gpt-transcribe fmt=json file=normal.flac | http=200 | x-litellm-response-cost=0.0008249999999999999 | spend_log(status|spend|model)=success|0.0008249999999999999|openai/gpt-transcribe | key_spend=0.0008249999999999999
   body: {"text":"Four score and seven years ago, our fathers brought forth on this continent a new nation, conceived in liberty and dedicated to the proposition that al
LiteLLM_SpendLogs for flac-after-4112-1794293042 (status|spend|model|startTime):
success|0.0008249999999999999|openai/gpt-transcribe|2026-11-10 06:44:03.223
success|0.0008249999999999999|openai/gpt-transcribe|2026-11-10 06:44:13.298
success|0.0011|openai/whisper-1|2026-11-10 06:44:27.556
success|0.0011|openai/whisper-1|2026-11-10 06:44:36.895
failure|0|openai/gpt-transcribe|2026-11-10 06:44:48.439
success|0.0008249999999999999|openai/gpt-transcribe|2026-11-10 06:44:58.948
success|0.0008249999999999999|openai/gpt-transcribe|2026-11-10 06:45:08.207
LiteLLM_VerificationToken spend|max_budget for flac-after-4112-1794293042: 0.0055000000000000005|500
LiteLLM_SpendLogs for flac-after-4112-1794293042-b (status|spend|model|startTime):
success|0|openai/gpt-transcribe|2026-11-10 06:45:17.536
success|0.0008249999999999999|openai/gpt-transcribe|2026-11-10 06:45:32.96
LiteLLM_VerificationToken spend|max_budget for flac-after-4112-1794293042-b: 0.0008249999999999999|500
/key/info spend key A: 0.005500000000000001  key B: 0.0008249999999999999

The After proxy ran the litellm/ tree of 63d2f813a7, which is byte-identical to the tip's (git diff --stat 63d2f813a7 0633730678 is one import line in tests/unit/litellm_core_utils/test_audio_utils.py).

Type

Bug Fix

Caveats (if any)

Medium

Low

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/46b12279387447c08b2cc007358bb400
Open in Devin Desktop: https://app.devin.ai/desktop/session/46b12279387447c08b2cc007358bb400?variant=devin
Requested by: @kerry-berri


Note

Medium Risk
Changes spend-tracking and budget enforcement for transcription and Transcribe passthrough; incorrect duration logic could under- or over-charge, though the fix tightens validation and adds regression tests.

Overview
Fixes transcription spend that could treat pipe-encoded FLAC (no sample count in the header) as billions of seconds when libsndfile reports 2**63 - 1 frames, blowing API key budgets.

Transcription billing now resolves billable seconds via _transcription_duration_for_cost: prefer validated provider usage.type=duration / usage.seconds, then measured duration from _hidden_params or response duration, else 0. Malformed seconds (negative, NaN, inf, overflow) are dropped through normalized_audio_duration_seconds.

Duration probing in calculate_request_duration and Amazon Transcribe passthrough media_file_seconds returns no duration when frame count is at or above LIBSNDFILE_UNKNOWN_FRAME_COUNT, so cost/logging does not infer length from unknown headers.

Integration and unit tests cover unsized FLAC ($0 spend), provider-reported seconds over measured length, and the passthrough path.

Reviewed by Cursor Bugbot for commit 0633730. Bugbot is set up for automated code reviews on this repo. Configure here.

Line port of the usage.seconds billing slice onto lts/1.108.x: normalized_audio_duration_seconds and _get_transcription_usage_duration from #35600 (ecb8ef5), and the provider-seconds-first _transcription_duration_for_cost from #50727 (dfb1aac), with their unit tests. The rest of #35600 stays on main.
…tion

Backport of #50842 to lts/1.108.x.
Cherry-picked from e6a0534 (litellm_transcription_unknown_frame_count).
Backport of #50842 to lts/1.108.x.
Cherry-picked from b6d25f2 (litellm_transcription_unknown_frame_count).
Backport of #50842 to lts/1.108.x.
Cherry-picked from 54dcd92 (litellm_transcription_unknown_frame_count).
Backport of #50842 to lts/1.108.x.
Cherry-picked from eb0f251 (litellm_transcription_unknown_frame_count).
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@veria-ai

veria-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect transcription cost and duration measurement workflows.

The billing changes appear sound, but the new test must meet the repository's explicit testing requirements before merging

Findings

  1. P2 Test skips real pricing ▶

Summary

This backport prefers valid provider-reported transcription seconds and rejects libsndfile's unknown frame count before calculating duration. It adds unit and integration coverage for the billing changes

The new mocked pricing test needs to follow the repository's test and typing requirements

kerry-berri explicitly acknowledges that unsized audio without provider usage bills zero, existing incorrect spend is not repaired, zero-cost responses omit the cost header, AWS unknown-duration jobs use the maximum charge with unit-only coverage, and gpt-transcribe rejects verbose_json upstream

  • Transcription bills use provider seconds when they are available.
  • Amazon Transcribe leaves unknown media lengths without a duration.

Reviews (1) · Last reviewed commit: "test(transcription): annotate the new pa..." · Reviewed by Greptile

Comment on lines +129 to +132
@patch( # test-quality-ok: isolates duration selection from the model pricing table
"litellm.cost_calculator.openai_cost_per_second"
)
def test_completion_cost_prefers_provider_usage_duration_over_measured_duration(self, mock_cost_fn):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test skips real pricing

This test replaces openai_cost_per_second and checks its arguments instead of the bill. The test guide forbids replacing LiteLLM's own code. The new parameters and locals also lack required types and Final annotations. Assert the real bill and satisfy these repository requirements before merging

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is the one #50727 merged on main (dfb1aac), only the response construction differs because this line's TranscriptionResponse takes text alone.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, #50727 already carries this test, and the constructor difference is immaterial. I retract the real-price objection. Missing annotations remain a separate concern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The locals match main's merged test line for line, and the type gates pass at this tip, so this pick stays as main has it.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0633730. Configure here.

@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yuneng-berri
yuneng-berri merged commit 5ef9d2a into lts/1.108.x Nov 10, 2026
62 of 64 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_transcription_usage_seconds_lts_1_108_x branch November 10, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants