Enhance model handling by normalizing modalities and updating fetch logic; add tests for new functionality

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-29 14:16:42 +02:00
parent acc6991341
commit 78b76dc331
3 changed files with 99 additions and 19 deletions
+16 -3
View File
@@ -24,12 +24,25 @@ def _headers() -> dict[str, str]:
}
async def list_models() -> list[dict[str, Any]]:
"""Return available models from OpenRouter."""
async def list_models(
output_modalities: str = "all",
category: str | None = None,
supported_parameters: str | None = None,
) -> list[dict[str, Any]]:
"""Return available models from OpenRouter.
Docs: GET /models supports query filters like output_modalities.
"""
base_url = os.getenv("OPENROUTER_BASE_URL", OPENROUTER_BASE_URL)
params: dict[str, str] = {"output_modalities": output_modalities}
if category:
params["category"] = category
if supported_parameters:
params["supported_parameters"] = supported_parameters
async with httpx.AsyncClient(timeout=15) as client:
resp = client.build_request(
"GET", f"{base_url}/models", headers=_headers())
"GET", f"{base_url}/models", headers=_headers(), params=params)
response = await client.send(resp)
response.raise_for_status()
return response.json().get("data", [])