litellm: register audio per-request prices at interpreter startup (#5)
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.
This commit is contained in:
1 parent
f66bedfb55
commit
2483715ef3
2 files changed
+40
No files matched your search
@@ -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
|
COPY patch_audio_cost_map.py /app/code/patch_audio_cost_map.py
|
||||||
RUN python3 /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
|
# SECURITY (2026-10-27, member-disclosure finding 4): LiteLLM forwards every
|
||||||
# provider response header to callers as `llm_provider-*`, which leaked the
|
# 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.
|
# co-op's remaining provider balance (x-credits-remaining) to any member API key.
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in new issue
Block a user