From 2483715ef3209d2514c6b780847c30e34122cbd1 Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Tue, 17 Nov 2026 08:44:41 +0000 Subject: [PATCH] litellm: register audio per-request prices at interpreter startup (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build-time edits of the cost-map JSON never reached the running gateway, so the audio prices now go in through sitecustomize — imported before LiteLLM prices anything. Idempotent, non-fatal. --- Dockerfile | 5 +++++ sitecustomize.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 sitecustomize.py diff --git a/Dockerfile b/Dockerfile index 4a6d532..bb45d3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,6 +66,11 @@ RUN python3 /app/code/patch_audio_router_pricing.py COPY patch_audio_cost_map.py /app/code/patch_audio_cost_map.py RUN python3 /app/code/patch_audio_cost_map.py +# Runtime registration: the build-time file edit above did not reach the deployed +# gateway's model_cost map (issue #5), so register the entries in-process instead. +# sitecustomize is imported before any application code. +COPY sitecustomize.py /app/.venv/lib/python3.13/site-packages/sitecustomize.py + # SECURITY (2026-10-27, member-disclosure finding 4): LiteLLM forwards every # provider response header to callers as `llm_provider-*`, which leaked the # co-op's remaining provider balance (x-credits-remaining) to any member API key. diff --git a/sitecustomize.py b/sitecustomize.py new file mode 100644 index 0000000..7040c63 --- /dev/null +++ b/sitecustomize.py @@ -0,0 +1,35 @@ +"""Register Tinfoil's per-request audio prices in litellm.model_cost at STARTUP. + +Build-time edits of model_prices_and_context_window_backup.json did not reach the +runtime map (the deployed gateway still had no entry — issue #5). sitecustomize is +imported by CPython before any application import, so this runs inside the gateway +process itself, before LiteLLM prices a request. Idempotent and never fatal. +""" +import os + +ENTRIES = { + "openai/voxtral-tts": { + "mode": "audio_speech", + "input_cost_per_request": 0.002, + "input_cost_per_token": 0.0, + "output_cost_per_token": 0.0, + }, + "openai/whisper-large-v3-turbo": { + "mode": "audio_transcription", + "input_cost_per_request": 0.01, + "input_cost_per_token": 0.0, + "output_cost_per_token": 0.0, + }, +} + +try: + import litellm + + _cost = getattr(litellm, "model_cost", None) + if isinstance(_cost, dict): + for _k, _v in ENTRIES.items(): + _cur = _cost.get(_k) or {} + if _cur.get("input_cost_per_request") != _v["input_cost_per_request"]: + _cost[_k] = {**_cur, **_v} +except Exception: # never break the interpreter for a pricing nicety + pass