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`.
Interface
No new interfaces are introduced.
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. Let's first look at the current directory.
- Assistant
Let me explore the repository structure more broadly.
- Assistant
This looks like a Node.js project with a server directory. Let me look deeper.
- Assistant
Let me look at the server structure more specifically, particularly the routing and models endpoint.
- Assistant
Let me look at the current
/v1/modelsroute implementation and the database/services related to it. - Assistant
Now I need to understand the issue better. Let me also look at the proxy.ts route to see how /v1/models is served for OpenAI compatibility.
- Assistant
Let me look at the current
/v1/modelsendpoint in the proxy.ts file to understand what it does now. - Assistant
Now let me look at the models table schema and other related code.
- Assistant
Let me look at the models table schema and related concepts.
- Assistant
Let me check if there's a
key_idcolumn in the models table and thesupports_toolscolumn. - Assistant
Let me look at the full schema more carefully and understand what
key_idin models table refers to. - Assistant
Let me also check for supports_tools column and look at the types.
- Assistant
Now let me check for test files related to models:
- Assistant
Let me look for tests specifically about the models route or
/v1/models: - Assistant
Let me look at the existing tests for the models endpoint more closely to understand what behavior is expected:
- Assistant
Now let me understand the full picture. The current
/v1/modelsendpoint returns only models that are "connected" (enabled AND have an enabled key). I need to change it to return all models from the catalog, annotated with availability info, and add a filter parameter.Let me look at the proxy.ts
/v1/modelsendpoint more carefully and the DB schema to understand what I need to do. - Assistant
Now let me look at the shared types to understand the ModelListRow type.
- Assistant
Let me check the ModelListRow type definition.
- Assistant
Let me check the full ModelListRow type definition.
- Assistant
Let me also check the full-flow test that references models.
- Assistant
Now let me understand the current
/v1/modelsimplementation:-
In
server/src/routes/proxy.ts, the/v1/modelsendpoint only returns models that are:enabled = 1- AND have an enabled API key on the same platform
-
It uses a
ROW_NUMBER() OVER (PARTITION BY model_id ORDER BY intelligence_rank ASC, id ASC)window function to deduplicate models with the samemodel_id. -
The issue wants:
- By default, return the whole catalog with per-model availability annotation
- Each model should have
available(boolean) andunavailable_reason(null|"no_key"|"disabled") - Filter
?available=true(alias?connected=true) to get only connected models - Dedup prefers an available instance of a model id over a disabled/keyless one
- The
autovirtual model is alwaysavailable: true
Let me look at the types more carefully to understand the full picture.
-
- Assistant
Now let me look at the full models test expectations and the rest of the proxy.ts code to understand the test expectations better:
- Assistant
Now let me understand the full picture of the proxy.ts file, particularly the imports and the
isAutoModelhelper: - Assistant
Now I have a clear picture. Let me plan the implementation:
- The current
/v1/modelsinproxy.tsreturns only models that areenabled = 1AND have an enabled API key on the same platform (respectingkey_idfor custom models). - I need to change it to return the full catalog by default, annotated with
availableandunavailable_reason. - Add
?available=trueor?connected=truefilter to return only connected models. - Dedup by
model_id, preferring available instances. autois always available.
Let me now implement the changes:
- The current
- Assistant
Now I have a clear understanding of what needs to change. Let me also look at what the full proxy.ts returns to see the response:
- Assistant
Now I understand the full picture. Let me implement the changes. I need to modify the
/v1/modelsendpoint inproxy.tsto:- Return the full catalog by default (all models from the
modelstable) - Annotate each model with
availableandunavailable_reason - Support
?available=true(alias?connected=true) query parameter filter - Dedup prefers an available instance of a model id over a disabled/keyless one
autovirtual model is alwaysavailable: true
- Return the full catalog by default (all models from the
- Assistant
Now I have a clear picture. Let me implement the changes. I need to modify the
/v1/modelsendpoint to:- Return the whole catalog by default with availability annotations
- Support
?available=true(or?connected=true) filter - Dedup prefers available instances
automodel is always available
- Assistant
Now let me implement the new
/v1/modelsendpoint. First, let me check if there are any relevant test files that I should be aware of: - Assistant
Now let me implement the new
/v1/modelshandler: - Assistant
Good, the edit was applied. Let me verify the full handler:
- Assistant
The implementation looks good. Now let me run the existing tests to verify they still pass:
- Assistant
All tests pass. Now let me run all the tests to make sure I haven't broken anything:
- Assistant
All 46 test files pass, with 456 tests. Let me also verify that the
ModelListRowtype isn't used elsewhere (since I'm no longer using it in this function): - Assistant
The
ModelListRowtype is imported but no longer used. I should clean up the import. Let me check if it's used elsewhere in the file. - Assistant
ModelListRowis no longer used in the file. Let me clean up the import. - Assistant
Now let me run the tests again to make sure everything still passes after the import cleanup:
- Assistant
All 46 test files pass with 456 tests. Let me also write a quick test script to verify the behavior more thoroughly:
- Assistant
Let me just verify the final diff and make sure the changes look good:
- Assistant
Let me do a final run of all tests to confirm everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.