feat(models): pull OpenRouter catalog from its live models API - #847
Merged
Conversation
pi-ai ships a build-time OpenRouter snapshot (346 models) overlaid with pi.dev's catalog; both lag OpenRouter itself (352 tool-capable models live, incl. z-ai/glm-5.3). Register a native provider that spreads pi-ai's openrouter provider (auth + streaming untouched) and serves the live /api/v1/models list, cached in ~/.pizzapi/openrouter-models-cache.json for 24h. Sessions warm the cache stale-while-revalidate; the daemon's model listing reads it so the web picker shows live models.
react-icons' Simple Icons pack has no OpenRouter glyph, so openrouter fell through to the generic robot. Inline the simple-icons path (CC0 1.0).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenRouter models came from a static list:
@earendil-works/pi-aiships a build-time snapshot (providers/data/openrouter.json, 346 models), and pi overlays it with pi.dev's catalog (withRemoteCatalog). Both lag OpenRouter itself — new models never show up until an upstream release.Change
Register a native
openrouterprovider that spreads pi-ai's own provider (auth — env key + OAuth — and streaming untouched) and replaces onlygetModels()with OpenRouter's livehttps://openrouter.ai/api/v1/models.~/.pizzapi/openrouter-models-cache.json, 24h TTL,0600extensions/openrouter-provider.ts): cached list is used immediately, a refreshed fetch re-registers the provider so the runtime snapshot updates mid-sessionlistConfiguredModels()reads the cache too, so the web model picker shows live modelstools(same rule pi-ai's generated catalog uses); pricing converted per-token → per-millionVerification
packages/cli/src/openrouter-models.test.ts— 10 new tests (mapping, cost conversion, tools filter, TTL, stale refetch, failure paths, corrupt cache, both registration shapes)bun run typecheckcleanbun test packages/cli/src: 2823 pass / 254 fail — identical 254 failures onorigin/mainbaseline (pre-existing full-suite cross-file pollution), so no regressionsSkipped
runner-ollama-models-cache.ts) — sessions warm the cache; add if idle runners serve >24h-stale listsprovider-auth.ts/commit-message-generator.ts— auth behaviour is identical since the provider spreads pi-ai's; add if either needs live-only model ids