mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(ci): skip missing pricing keys in Vercel AI Gateway transform
The auto_update_price_and_context_window_file.py script crashed with KeyError: 'output' on the latest Vercel AI Gateway response, where 88 of 280 models (embeddings, image/video, etc.) don't expose 'output' pricing and 62 don't expose 'input'. Treat both pricing fields as optional so the daily price-update job stops failing Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
This commit is contained in:
parent
2655d1dd5e
commit
be70a3539e
1 changed files with 13 additions and 10 deletions
|
|
@ -85,24 +85,27 @@ def transform_openrouter_data(data):
|
|||
def transform_vercel_ai_gateway_data(data):
|
||||
transformed = {}
|
||||
for row in data:
|
||||
pricing = row.get("pricing") or {}
|
||||
obj = {
|
||||
"max_tokens": row["context_window"],
|
||||
"input_cost_per_token": float(row["pricing"]["input"]),
|
||||
"output_cost_per_token": float(row["pricing"]["output"]),
|
||||
'max_output_tokens': row['max_tokens'],
|
||||
'max_input_tokens': row["context_window"],
|
||||
}
|
||||
|
||||
# Handle cache pricing if available
|
||||
if "pricing" in row:
|
||||
if "input_cache_read" in row["pricing"] and row["pricing"]["input_cache_read"] is not None:
|
||||
obj['cache_read_input_token_cost'] = float(f"{float(row['pricing']['input_cache_read']):e}")
|
||||
|
||||
if "input_cache_write" in row["pricing"] and row["pricing"]["input_cache_write"] is not None:
|
||||
obj['cache_creation_input_token_cost'] = float(f"{float(row['pricing']['input_cache_write']):e}")
|
||||
if "input" in pricing:
|
||||
obj["input_cost_per_token"] = float(pricing["input"])
|
||||
|
||||
if "output" in pricing:
|
||||
obj["output_cost_per_token"] = float(pricing["output"])
|
||||
|
||||
if pricing.get("input_cache_read") is not None:
|
||||
obj['cache_read_input_token_cost'] = float(f"{float(pricing['input_cache_read']):e}")
|
||||
|
||||
if pricing.get("input_cache_write") is not None:
|
||||
obj['cache_creation_input_token_cost'] = float(f"{float(pricing['input_cache_write']):e}")
|
||||
|
||||
mode = "embedding" if "embedding" in row["id"].lower() else "chat"
|
||||
|
||||
|
||||
obj.update({"litellm_provider": "vercel_ai_gateway", "mode": mode})
|
||||
|
||||
transformed[f'vercel_ai_gateway/{row["id"]}'] = obj
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue