This repository was archived by the owner on Sep 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_models_docs.py
More file actions
88 lines (71 loc) · 3.23 KB
/
Copy pathfetch_models_docs.py
File metadata and controls
88 lines (71 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import requests
import json
from pathlib import Path
def fetch_and_parse_models():
url = "https://openrouter.ai/api/v1/models"
headers = {
"HTTP-Referer": "https://github.com/OpenAgent/OpenAgent",
"X-Title": "OpenAgent v0.2",
}
print(f"Fetching models from {url}...")
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
except Exception as e:
print(f"Error fetching models: {e}")
return
models = data.get("data", [])
if not models:
print("No models found in the API response.")
return
print(f"Found {len(models)} models. Generating markdown...")
# Sort models by ID for easier navigation
models.sort(key=lambda x: x.get("id", ""))
full_lines = [
"# OpenRouter Comprehensive Model List",
f"\n*Auto-generated on {Path('.').absolute()}*",
"\nThis document contains a full list of models available via OpenRouter, including pricing and context limits.",
"\n| Model Name | Model ID | Input ($/1M) | Output ($/1M) | Context |",
"| :--- | :--- | :--- | :--- | :--- |"
]
free_lines = [
"# OpenRouter High-Quality Free Models",
f"\n*Auto-generated on {Path('.').absolute()}*",
"\nThis document highlights free models on OpenRouter. Note that these often have stricter rate limits.",
"\n| Model Name | Model ID | Context | Quality Note |",
"| :--- | :--- | :--- | :--- |"
]
# High quality indicators for free models
high_quality_keywords = ["llama-3.1", "llama-3.3", "gemini", "gemma-3", "hermes", "phi-4", "qwen", "mistral-small"]
for model in models:
name = model.get("name", "Unknown")
id = model.get("id", "Unknown")
pricing = model.get("pricing", {})
prompt_val = float(pricing.get("prompt", 0))
completion_val = float(pricing.get("completion", 0))
prompt = prompt_val * 1000000
completion = completion_val * 1000000
context = model.get("context_length", "Unknown")
# Format pricing
prompt_str = f"{prompt:.4f}" if prompt < 0.01 else f"{prompt:.2f}"
comp_str = f"{completion:.4f}" if completion < 0.01 else f"{completion:.2f}"
full_lines.append(f"| {name} | `{id}` | ${prompt_str} | ${comp_str} | {context} |")
# Check for free
if prompt_val == 0 and completion_val == 0:
quality_note = "Standard"
lower_id = id.lower()
if any(kw in lower_id for kw in high_quality_keywords):
quality_note = "**High Quality**"
free_lines.append(f"| {name} | `{id}` | {context} | {quality_note} |")
# Save Full List
full_path = Path("docs/openrouter_models_full.md")
full_path.parent.mkdir(parents=True, exist_ok=True)
full_path.write_text("\n".join(full_lines), encoding="utf-8")
# Save Free List
free_path = Path("docs/openrouter_free_models.md")
free_path.write_text("\n".join(free_lines), encoding="utf-8")
print(f"Successfully saved {len(models)} models to {full_path}")
print(f"Successfully saved free models to {free_path}")
if __name__ == "__main__":
fetch_and_parse_models()