MCPcopy Create free account
hub / github.com/vercel/examples / list_models

Function list_models

python/vibe-coding-ide/backend/src/api/models.py:26–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24
25@router.get("/models")
26async def list_models() -> dict[str, Any]:
27 oidc_token = await get_vercel_oidc_token()
28 result = list(ALLOWED_MODELS)
29
30 api_key = os.getenv("VERCEL_AI_GATEWAY_API_KEY", oidc_token)
31 gateway_base = (
32 os.getenv("AI_GATEWAY_BASE_URL")
33 or os.getenv("OPENAI_BASE_URL")
34 or "https://ai-gateway.vercel.sh/v1"
35 )
36
37 if not api_key:
38 return {"models": result}
39
40 url = f"{gateway_base.rstrip('/')}/models"
41 headers = {"Authorization": f"Bearer {api_key}"}
42 try:
43 async with httpx.AsyncClient(timeout=15.0) as client:
44 resp = await client.get(url, headers=headers)
45 resp.raise_for_status()
46 data = resp.json()
47 available_ids = {
48 str(m.get("id")) for m in (data.get("data") or []) if m.get("id")
49 }
50 intersected = [m for m in ALLOWED_MODELS if m in available_ids]
51 return {"models": intersected or result}
52 except httpx.HTTPError:
53 return {"models": result}

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected