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 to understand the codebase and locate relevant files. Let me first get an overview.
- Assistant
Let me get a better overview of the repository structure.
- Assistant
Let me explore the server directory and understand the structure better.
- Assistant
Let me search for the /v1/models endpoint to understand how it's currently implemented.
- Assistant
Let me look at the route file that handles /v1/models
- Assistant
Let me search for where the /v1/models route is defined.
- Assistant
Let me look at the routes/proxy.ts file and app.ts to understand the models endpoint.
- Assistant
I can see there's a
proxyRouterthat handles/v1routes, and also amodelsRouterfor/api/models. Let me look at the proxyRouter to understand the current/v1/modelsendpoint. - Assistant
Now let me look at the models router:
- Assistant
Let me look at the shared types to understand the ModelListRow type:
- Assistant
Let me check the shared types file.
- Assistant
Now let me look at the existing tests to understand the expected behavior:
- Assistant
Let me also look at the database schema and relevant queries:
- Assistant
Now let me check what tests exist for the models endpoint and run them to see current state:
- Assistant
Let me check the database schema to understand the models and api_keys tables structure:
- Assistant
Let me run the existing tests to understand the current state:
- Assistant
Let me run the tests to completion to see if they all pass.
- Assistant
All 46 test files pass with 456 tests. Now I understand the codebase. Let me plan the changes:
Current behavior of
GET /v1/models: Returns only models that are "connected" (enabled AND has an enabled key).Wanted behavior:
- By default, return the whole catalog (one entry per model_id), annotated with
availableandunavailable_reason available= boolean (enabled AND matching enabled key exists)unavailable_reason:null|"no_key"(enabled, no key) |"disabled"(disabled)- Filter:
?available=true(alias?connected=true) → only connected models - Dedup prefers an available instance of a model_id over disabled/keyless one
autovirtual model is alwaysavailable: true
Let me implement this:
- By default, return the whole catalog (one entry per model_id), annotated with
- Assistant
Let me look at the exact lines for the
/v1/modelshandler. - Assistant
Let me view lines 121-180 to see the full handler.
- Assistant
Now I understand the current implementation. Let me also check what the
supports_toolscolumn looks like: - Assistant
Let me check the
key_idcolumn in models table: - Assistant
Let me check what key_id means in the models table:
- Assistant
Now I have a clear picture. Let me implement the changes to the
/v1/modelsendpoint inproxy.ts. I'll replace the handler: - Assistant
Let me verify the full handler:
- Assistant
Now let me run the tests to see if the existing tests still pass:
- Assistant
There's a syntax error. Let me check the file around line 219:
- Assistant
I see - the old code is still present below the new code. Let me remove it:
- Assistant
I see - there's leftover old code after the new handler. Let me remove lines 217-231:
- Assistant
Let me check the area around line 216:
- Assistant
Let me check if the closing
});is missing: - Assistant
The handler is missing the closing
});. Let me add it: - Assistant
There's a duplicate
const MAX_RETRIES = 20;. Let me fix it: - Assistant
Let me verify the entire handler section looks correct:
- Assistant
I see the
dataarray is missing its closing]. Let me fix it: - Assistant
The issue is the
<<in the command conflicts with the shell heredoc. Let me use the edit command differently - directly with a string. - Assistant
I see the problem - the
],closing the data array is missing. Let me fix this: - Assistant
Let me use sed to fix this.
- Assistant
Let me use node to fix this.
- Assistant
Let me write a script file instead:
- Assistant
Let me verify the fix:
- Assistant
Now let me run the tests again to see if they pass:
- Assistant
All 46 test files pass with 456 tests. Now let me create a verification script to ensure the behavior matches the requirements:
- Assistant
Let me run the existing auto model test to make sure it still passes:
- Assistant
Good, the existing tests still pass. Let me now verify my changes produce the correct output by creating a quick test:
- Assistant
The implementation is working correctly. Let me verify one more edge case — adding a key makes the correct models available:
- Assistant
Everything works correctly. Let me run the full test suite one final time:
- Assistant
All 46 tests pass with 456 tests. Let me clean up the temporary files:
- Assistant
Let me also clean up the test file I placed in the wrong place:
- Assistant
Let me check the git diff to see the final changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.