ParthKulshreshtha's picture
Upload folder using huggingface_hub
59db361 verified
Raw
History Blame Contribute Delete
1.34 kB
"""OpenRouter model catalog: tool-capable models only (design doc: 'any
OpenRouter model' is only true of tool-capable ones)."""
from __future__ import annotations
import httpx
# Verified live against https://openrouter.ai/api/v1/models on 2026-08-05:
# both ids exist, pricing shapes match (string USD-per-token), tool-capable.
PINNED_MODELS = [
{"id": "anthropic/claude-sonnet-4.5", "name": "Claude Sonnet 4.5 (pinned)",
"prompt_price": 0.0, "completion_price": 0.0},
{"id": "openai/gpt-4.1-mini", "name": "GPT-4.1 mini (pinned)",
"prompt_price": 0.0, "completion_price": 0.0},
]
def fetch_models(base_url: str,
transport: httpx.BaseTransport | None = None) -> list[dict]:
with httpx.Client(base_url=base_url, timeout=30.0,
transport=transport) as client:
resp = client.get("/models")
resp.raise_for_status()
out = []
for m in resp.json().get("data", []):
if "tools" not in (m.get("supported_parameters") or []):
continue
pricing = m.get("pricing") or {}
out.append({"id": m["id"], "name": m.get("name", m["id"]),
"prompt_price": float(pricing.get("prompt", 0) or 0),
"completion_price": float(pricing.get("completion", 0) or 0)})
return sorted(out, key=lambda m: m["id"])