Spaces:
Sleeping
Sleeping
| """Fetch an OpenRouter model metadata snapshot for the Space. | |
| Run when you want to refresh model_info_snapshot.json: | |
| python fetch_openrouter_model_info.py | |
| No API key is required for the public /models endpoint at the time of writing. | |
| """ | |
| import json | |
| from pathlib import Path | |
| import requests | |
| MODEL_FAMILIES_PATH = Path("model_families.json") | |
| OUTPUT = Path("model_info_snapshot.json") | |
| OPENROUTER_MODELS_URL = "https://openrouter.ai/api/v1/models" | |
| def load_model_families() -> dict: | |
| return json.loads(MODEL_FAMILIES_PATH.read_text(encoding="utf-8")) | |
| def main() -> None: | |
| model_families = load_model_families() | |
| wanted = {model for models in model_families.values() for model in models} | |
| response = requests.get(OPENROUTER_MODELS_URL, timeout=30) | |
| response.raise_for_status() | |
| data = response.json().get("data", []) | |
| by_id = {item.get("id"): item for item in data} | |
| snapshot = {} | |
| for family, models in model_families.items(): | |
| for model in models: | |
| item = by_id.get(model, {"id": model, "name": model}) | |
| item = dict(item) | |
| item["model_family"] = family | |
| snapshot[model] = item | |
| missing = sorted(wanted - set(by_id)) | |
| OUTPUT.write_text(json.dumps(snapshot, ensure_ascii=False, indent=2), encoding="utf-8") | |
| print(f"Wrote {len(snapshot)} models to {OUTPUT}") | |
| if missing: | |
| print("Missing from OpenRouter response:") | |
| for model in missing: | |
| print(f"- {model}") | |
| if __name__ == "__main__": | |
| main() | |