Skip to content

Commit f935d49

Browse files
committed
postprocess: Route namespaced model ids through OpenRouter
OpenRouter is OpenAI-compatible, so reuse GPTModel with its base URL. Its model ids always contain a slash (vendor/model), which bare gemini-*/gpt-* ids never do, so dispatch on that instead of maintaining a vendor list.
1 parent 3aaacbf commit f935d49

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

c2rust-postprocess/postprocess/models/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
from postprocess.models.gemini import GoogleGenerativeModel
55
from postprocess.models.gpt import GPTModel
66

7+
OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1"
8+
79

810
def api_key_from_env(model_id: str) -> str | None:
911
"""Retrieve API key from environment variable based on model ID."""
1012
if model_id.startswith("gemini"):
1113
return os.getenv("GEMINI_API_KEY")
1214
elif model_id.startswith("gpt"):
1315
return os.getenv("OPENAI_API_KEY")
16+
# OpenRouter ids are namespaced, e.g. "anthropic/claude-sonnet-4.5"
17+
elif "/" in model_id:
18+
return os.getenv("OPENROUTER_API_KEY")
1419
return None
1520

1621

@@ -20,5 +25,11 @@ def get_model_by_id(id: str) -> AbstractGenerativeModel:
2025
return GoogleGenerativeModel(id=id)
2126
elif id.startswith("gpt"):
2227
return GPTModel(id=id)
28+
elif "/" in id:
29+
return GPTModel(
30+
id=id,
31+
api_key=os.getenv("OPENROUTER_API_KEY"),
32+
base_url=OPENROUTER_BASE_URL,
33+
)
2334

2435
raise ValueError(f"Unsupported model identifier: {id}")

0 commit comments

Comments
 (0)