feat: auto-promote free Moonshot models to top of ai-gateway picker

When the live Vercel AI Gateway catalog exposes a Moonshot model with
zero input AND output pricing, it's promoted to position #1 as the
recommended default — even if the exact ID isn't in the curated
AI_GATEWAY_MODELS list. This enables dynamic discovery of new free
Moonshot variants without requiring a PR to update curation.

Paid Moonshot models are unaffected; falls back to the normal curated
recommended tag when no free Moonshot is live.
This commit is contained in:
jerilynzheng
2026-04-20 00:18:51 -07:00
committed by Teknium
parent ac26a460f9
commit 5bb2d11b07
2 changed files with 50 additions and 2 deletions

View File

@@ -812,8 +812,24 @@ def fetch_ai_gateway_models(
if not curated:
return list(_ai_gateway_catalog_cache or fallback)
first_id, _ = curated[0]
curated[0] = (first_id, "recommended")
# If the live catalog offers a free Moonshot model, auto-promote it to
# position #1 as "recommended" — dynamic discovery without a PR.
free_moonshot = next(
(
mid
for mid, item in live_by_id.items()
if mid.startswith("moonshotai/")
and _ai_gateway_model_is_free(item.get("pricing"))
),
None,
)
if free_moonshot:
curated = [(mid, desc) for mid, desc in curated if mid != free_moonshot]
curated.insert(0, (free_moonshot, "recommended"))
else:
first_id, _ = curated[0]
curated[0] = (first_id, "recommended")
_ai_gateway_catalog_cache = curated
return list(curated)