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 start by exploring the repository structure to understand the codebase and locate the relevant files for the
/v1/modelsendpoint. Let me first check the directory structure. - Assistant
Let me check the general structure of the repository.
- Assistant
Let me explore the server directory more and understand the structure better.
- Assistant
Let me search for the models endpoint and the models route file.
- Assistant
Let me look at the models route file and related files.
- Assistant
Let me understand the current behavior. It seems the current implementation returns all models from the database but does not filter by availability. The issue says:
- Current:
GET /v1/modelsreturns only models that are connected right now (enabled AND an enabled key can serve them). - Wanted: return the whole catalog, each annotated with whether it's usable, plus an opt-in filter.
But looking at the code, it returns all models without filtering. Let me check if there's something else filtering later, or maybe the DB query already filters somehow. Let me check the database schema and understand the models table.
Let me also look at how the route is mounted and if there's another models endpoint that does the filtering. Let me also check if there are tests for this endpoint.
- Current:
- Assistant
Let me look at the proxy route for models and the app routing to understand the full picture.
- Assistant
Let me see the
/modelsendpoint in the proxy router to understand the current behavior. - Assistant
Let me see the
/modelsendpoint in the proxy router: - Assistant
Now I understand the structure. Let me look at how the proxy router is mounted and the app structure:
- Assistant
Now I have a clear picture of the codebase. Let me also look at the DB schema to understand the tables better:
- Assistant
Let me also look at the shared types to understand
ModelListRowand look at existing tests for the models endpoint: - Assistant
Let me look at the shared types and also find the relevant tests for the models endpoint.
- Assistant
Let me look at the tests for the proxy models endpoint:
- Assistant
Let me look at the test helpers and a relevant test file to understand the test setup:
- Assistant
Now let me look at the existing test for the
/v1/modelsendpoint to understand what's currently being tested. - Assistant
Let me look at the proxy-auto-model test file:
- Assistant
Now let me look at the
hasProviderfunction and thekey_idcolumn in the models table: - Assistant
Now let me check the DB schema for models table to understand the
key_idcolumn: - Assistant
Now let me check the existing tests to understand what's tested:
- Assistant
Let me also check how the router determines which models are available:
- Assistant
Now let me check what the
supports_toolscolumn looks like in the migration: - Assistant
Now I have a good understanding of the codebase. Let me run the existing tests to make sure they pass before making changes:
- Assistant
All 46 test files pass with 456 tests. Now let me look at the full flow test for /api/models to understand it:
- Assistant
Now I have a clear understanding. Let me plan my implementation:
Current behavior: The
/v1/modelsendpoint only returns models that are connected (enabled AND have enabled keys).Desired behavior:
- By default, return the full catalog (all models)
- Add
availableandunavailable_reasonannotations per model - Support
?available=true(or?connected=true) filter to get only connected models - Dedup prefers available instance of a model id over disabled/keyless
- The
autovirtual model is alwaysavailable: true
Let me implement this:
- Assistant
Now let me implement the changes to the
/v1/modelsendpoint inserver/src/routes/proxy.ts: - Assistant
Let me see the models endpoint section:
- Assistant
Now I'll implement the changes. Let me replace the
/v1/modelsendpoint inserver/src/routes/proxy.ts: - Assistant
I need to use the edit command properly. Let me try:
- Assistant
Wait, I need to fix the template literal injection in the SQL. Using
${filterConnected ? 'AND available = 1' : ''}directly in a template literal is fine for static SQL fragments, but let me make sure the approach is correct. Let me verify the file looks right: - Assistant
Good, the implementation looks correct. The
${filterConnected ? 'AND available = 1' : ''}is a safe static SQL fragment sincefilterConnectedis a boolean that maps to either a literal SQL string or empty string. Let me run the existing tests to make sure they still pass: - Assistant
All 46 tests pass. Now let me create a quick test script to verify the new behavior:
- Assistant
Let me run this quick test to verify the behavior. But first, let me check if vitest can run a standalone file:
- Assistant
It needs to be within the test directory and follow the naming pattern. Let me copy it there.
- Assistant
Let me fix the import paths and run it properly:
- Assistant
All 5 new tests pass. Let me clean up the test file (we shouldn't add tests) and run the full test suite to make sure everything is still working:
- Assistant
Let me run the full test suite to make sure everything is still working.
- Assistant
All 46 test files pass with 456 tests. Let me verify the final diff:
- Assistant
The diff looks clean and correct. Let me verify the implementation handles all the requirements from the issue:
- ✅ Returns whole catalog by default — removed the
WHERE m.enabled = 1 AND EXISTS(...)filter - ✅ Per-model annotation —
availableboolean andunavailable_reasonfield - ✅ Filter —
?available=trueor?connected=truefilters to connected models only - ✅ Dedup prefers available — ROW_NUMBER() ORDER BY prefers available=0 (available) before available=1 (unavailable)
- ✅ Auto always available — hardcoded
available: truefor theautovirtual model
Let me also check there's no issue with the
${filterConnected ...}in the template literal (this is a safe static SQL fragment sincefilterConnectedis a boolean): - ✅ Returns whole catalog by default — removed the
- Assistant
Good. The
filterConnectedis a boolean derived from=== 'true'comparison, so the SQL fragment is always either the literal'AND available = 1'or''— no injection risk.Let me do one final comprehensive test run to make sure everything is solid:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.