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
@@ -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