ISSUE DESCRIPTION /v1/models: return the full catalog with per-model availability +…
- User
ISSUE DESCRIPTION
/v1/models: return the full catalog with per-model availability + opt-in filter Split out from #242.
Current: `GET /v1/models` returns only models that are connected right now (enabled AND an enabled key can serve them).
Wanted: by default return the whole catalog (one entry per model id), each annotated with whether it's usable, plus an opt-in filter to get just the connected ones.
Per-model annotation:
- `available`: boolean — enabled AND a matching enabled key exists.
- `unavailable_reason`: `null` | `"no_key"` (enabled, no key) | `"disabled"` (catalog row disabled).
Filter:
- `?available=true` (alias `?connected=true`) → only connected models (the previous default behavior).
Notes:
- The extra fields are additive — OpenAI-compatible clients ignore unknown fields.
- Dedup prefers an available instance of a model id over a disabled/keyless one.
- The `auto` virtual model is always `available: true`.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- Assistant
I’ll first map the repository and locate the
/v1/modelsroute, its schemas, and relevant tests. Then I’ll reproduce the current filtering behavior, implement availability annotation and query aliases, and run focused plus broader tests. - Assistant
The initial search was polluted by dependencies, so I’ll narrow it to server source and inspect the package scripts and test layout before attempting a reproduction.
- Assistant
I’ll inspect route registration and model-list implementation directly, along with database types and existing API test helpers, to understand key-to-model matching (especially custom/keyless providers) and avoid changing routing semantics.
- Assistant
There is an existing focused models test in
proxy-auto-model.test.ts. I’ll read the route and that suite, then inspect schema definitions for model/key fields and router eligibility queries so the API’s “available” calculation exactly matches actual servability. - Assistant
routes/models.tsis the dashboard catalog endpoint, not the OpenAI endpoint. The actual/v1/modelsbehavior is likely inproxy.ts; I’ll inspect its implementation and application mounting, including keyless and custom eligibility logic. - Assistant
The current SQL confirms the reported behavior: it excludes disabled and keyless rows before deduplication. The requested availability definition only requires an enabled matching key (not health/cooldown/fallback state), matching the endpoint’s existing semantics. I’ll check query-boolean conventions and TypeScript row types, then run the focused test as a baseline reproduction.
- Assistant
The chained command stopped because the row type is defined in the shared package rather than server source. I’ll locate it there and rerun the baseline test with the repository’s expected Vitest path syntax.
- Assistant
The baseline passes but only asserts connected rows exist and uniqueness; with the setup’s single Groq key, the current response omits most catalog rows, reproducing the issue by inspection. I’ll inspect the shared type and workspace build configuration, then update the query to compute availability before deduplication, rank available rows first, annotate all entries (including
auto), and apply either opt-in alias when exactly"true". - Assistant
I’ll implement this in the OpenAI endpoint only. The ranked CTE will preserve one row per model ID while ordering by availability first, then enabled state, intelligence rank, and stable row ID. That also gives sensible behavior when duplicates are both unavailable: an enabled/keyless catalog row is preferred over a disabled row.
- Assistant
Python is unavailable, so no files were changed (the subsequent build merely validated the original tree). I’ll apply the same targeted replacement using Node, then compile and inspect the diff.
- Assistant
The code compiles. I’ll now exercise the endpoint through HTTP with an isolated in-memory database and synthetic rows covering: default full catalog,
no_key,disabled, both filter aliases,auto, and duplicate IDs where an available lower-preference instance must win. This temporary validation script will live outside the repository. - Assistant
The temporary script was treated as CommonJS because it resides in
/tmp, so top-level await could not transpile; the application code was not reached. I’ll wrap the harness in an async function and make the assertions explicitly check only the relevant fields. - Assistant
The HTTP harness now verifies all requested semantics, including dedup preference and alias equivalence. I’ll run the focused route suite, the complete server suite, and the full workspace build to catch regressions in tests and shared type consumers.
- Assistant
All 456 server tests pass, the focused route suite passes, and both server/client production builds succeed. I’ll do a final diff review to ensure only the intended source/type changes remain and no build artifacts were introduced.
- Assistant
Final checklist:
- If an error was reported in the issue description, I have successfully reproduced it. Yes. With only one provider key configured, the original SQL’s pre-dedup
WHEREclause returned only that provider’s connected models and omitted the rest of the catalog. - If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes. An isolated HTTP harness confirmed the default response includes available, keyless, and disabled rows with correct annotations; it also confirmed both filters and available-first deduplication.
- I have thought about edge cases and made sure my fix handles them as well. Yes. The implementation handles disabled rows with keys, enabled rows without keys, custom key bindings, duplicate model IDs, duplicate unavailable rows, both query aliases, and the always-available
automodel. - I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Yes. The focused 5-test models suite and all 456 server tests pass. The full server/client build also succeeds, and is clean.
- If an error was reported in the issue description, I have successfully reproduced it. Yes. With only one provider key configured, the original SQL’s pre-dedup
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.