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/models endpoint. Let's first look at the overall structure.
- Assistant
Let me explore the repository structure better.
- Assistant
This is a Node.js project. Let me look at the server directory first to understand the structure.
- Assistant
Let me look for files related to the /v1/models endpoint.
- Assistant
Let me look at the routes and models-related files.
- Assistant
Let me look at the models route file first.
- Assistant
Now let me look at the proxy.ts route to see the
/v1/modelsendpoint: - Assistant
Now let me look at the shared types to understand
ModelListRow: - Assistant
Let me look at the shared types to understand the ModelListRow type.
- Assistant
Now let me look at the database schema to understand the models table structure:
- Assistant
Let me look at the database migrations to understand the schema:
- Assistant
Let me look at the models table definition more closely.
- Assistant
Let me look at the api_keys table structure:
- Assistant
Let me check the api_keys table and also check if there's a
key_idcolumn on models table (I seem.key_idreferenced in the proxy's models query). - Assistant
Let me search for where
key_idis added to the models table. - Assistant
Let me check if there's a
supports_toolscolumn too - I seesupports_toolsreferenced in the models route. - Assistant
Now let me look at the existing tests to understand what's expected:
- Assistant
Let me check the proxy-auto-model test to understand what tests exist for models endpoint.
- Assistant
Now let me look at the router service to understand how models are currently determined to be "available":
- Assistant
Now let me understand the full picture. I need to:
- Modify the
/v1/modelshandler inproxy.tsto return the full catalog by default with availability annotations - Add
availableandunavailable_reasonfields - Support
?available=trueor?connected=truequery parameter filter - Dedup prefers available instance of a model id over disabled/keyless one
- Auto model always available: true
- Update
ModelListRowtype inshared/types.ts
Let me also check what the current
ModelListRowinterface looks like in the shared types:Now let me look at how the router currently works to understand model availability:
- Modify the
- Assistant
Let me also check the tests for models endpoint:
- Assistant
Let me check if there are any tests that specifically test the
/v1/modelsendpoint response format: - Assistant
Let me also check the
hasProviderfunction: - Assistant
Let me check if
ModelListRowis used elsewhere: - Assistant
Now let me look at the
m.key_idcolumn usage and understand the custom model key binding: - Assistant
Let me see the hasProvider function:
- Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
- Current behavior:
/v1/modelsendpoint inproxy.tsreturns only models that are enabled AND have an enabled API key. - Desired behavior: Return the whole catalog by default, annotated with
availableandunavailable_reason, plus?available=truefilter.
Let me now implement the changes. First, I'll update the
ModelListRowinterface inshared/types.ts: - Current behavior:
- Assistant
Now let me look at the existing tests first to understand what's expected:
- Assistant
Now I have a good understanding of the codebase and the requirements. Let me plan the changes:
- Update the
ModelListRowinterface inshared/types.tsto includeavailableandunavailable_reason - Update the
/v1/modelsendpoint inproxy.tsto:- Return the whole catalog by default (all model ids)
- Each annotated with
availableandunavailable_reason - Support
?available=true(alias?connected=true) filter autovirtual model is alwaysavailable: true- Dedup prefers an available instance of a model id over a disabled/keyless one
Let me first run the existing tests to make sure they pass:
- Update the
- Assistant
Let me wait for the full test output:
- Assistant
All tests pass. Now let me implement the changes. First, I'll update the
ModelListRowinterface inshared/types.ts: - Assistant
Let me use the edit command properly.
- Assistant
Let me use bash to edit the file directly:
- Assistant
Let me verify the change:
- Assistant
Now I need to update the
/v1/modelsendpoint inproxy.ts. Let me find the exact lines: - Assistant
Let me look at the current models endpoint in proxy.ts more carefully:
- Assistant
Now let me look at the remaining part of the models endpoint:
- Assistant
Now I have a clear picture. Let me implement the changes. I'll need to replace the models endpoint handler in proxy.ts. Let me first open the file to understand the exact structure:
- Assistant
Now let me replace the models endpoint handler (lines 119-172):
- Assistant
Let me use sed to do the replacement instead:
- Assistant
Let me try with
pythonornode. - Assistant
Let me use node to do the replacement.
- Assistant
Let me verify the replacement was done correctly:
- Assistant
Good. Now let me run the existing tests to see if they pass:
- Assistant
All 46 test files passed, 456 tests passed. Now let me also verify that TypeScript compilation works:
- Assistant
Good, TypeScript compilation passes. Now let me run the specific models test to make sure it passes:
- Assistant
All existing tests pass. Now let me also look at the
models.tsroute file to check if it needs updates: - Assistant
Good, the models.ts route is a separate dashboard endpoint, not the OpenAI-compatible one. My changes are only to the proxy endpoint. Let me now run the full test suite one more time to make sure everything still passes:
- Assistant
Wait, I need to check something. The SQLite CASE expression returns 0/1 (not true/false). Let me fix the mapping to properly convert to boolean:
- Assistant
Let me check the part where models are mapped:
- Assistant
Wait, I need to fix the boolean conversion. SQLite returns 0/1, not true/false. Let me fix the mapping:
- Assistant
I need to fix the boolean conversion. SQLite returns 0/1, not true/false. Let me update the code:
- Assistant
Now let me run the tests again to make sure everything still passes:
- Assistant
All tests still pass. Let me also run TypeScript compilation check:
- Assistant
Now let me also write a quick test script to verify the behavior manually:
- Assistant
The server is TypeScript, can't test with plain node. Let me run a quick integration test using vitest:
- Assistant
The test failures show that the groq models aren't showing as available. The issue is the key creation is failing because I'm passing unified key auth when the dashboard auth is needed. Let me fix the test:
- Assistant
All 6 new tests pass. Now let me remove the test file since the instructions say not to add new tests:
- Assistant
Now let me run the full test suite one final time to make sure everything is clean:
- Assistant
All 456 tests pass. Let me review the final state of my changes:
- Assistant
The changes look correct. Let me also verify TypeScript compilation still works:
- Assistant
Let me verify the changes are complete and correct:
- Assistant
All changes are clean. Let me now submit:
- Assistant
All tests pass. Let me now submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.