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. Let's first look at what's in the repository.
- Assistant
Let me look at the repository structure more broadly.
- Assistant
Let me explore the server directory to understand the structure.
- Assistant
Let me explore the server/src directory to understand the structure better.
- Assistant
Let me look at the main server entry point and find the /v1/models endpoint.
- Assistant
Let me look at the proxy route where /v1/models is handled.
- Assistant
Let me search more broadly for the /v1/models endpoint definition.
- Assistant
Let me look at the current /models endpoint implementation more closely.
- Assistant
Let me look at the test file to understand the current behavior better.
- Assistant
Let me look at the database schema to understand the
modelsandapi_keystables. - Assistant
Let me search for the schema
- Assistant
Let me look at the models and api_keys table schemas.
- Assistant
Let me check if models table has a
key_idcolumn: - Assistant
Let me understand the full current
/modelsendpoint: - Assistant
Let me look at the types used in the endpoint and the AUTO_MODEL_ID constant:
- Assistant
Let me look at the shared types to understand ModelListRow.
- Assistant
Let me look at that interface definition.
- Assistant
Let me first understand the full codebase structure, especially around the types and the models endpoint. Let me also look at how other routes are structured:
- Assistant
Let me look at the full proxy.ts file for imports and structure:
- Assistant
Now let me look at the existing test file to understand the testing setup and the expected behavior more closely:
- Assistant
Now I have a clear understanding of the issue and the codebase. Let me now implement the changes. I need to:
- Update the
ModelListRowtype to includeavailableandunavailable_reasonfields - Modify the
/v1/modelsendpoint to return the full catalog with per-model annotations - Add
?available=true/?connected=truefilter - Ensure dedup prefers available instances
- Ensure
automodel is alwaysavailable: true
Let me start implementing:
- Update the
- Assistant
Now I understand the full picture. Let me implement the changes step by step.
First, let me update the
ModelListRowtype to include the new availability fields: - Assistant
Let me use the correct edit syntax.
- Assistant
Let me use the edit command with the correct syntax.
- Assistant
Let me try the edit command differently.
- Assistant
Let me open the file first and then edit it.
- Assistant
Now I can see the file. Let me edit lines 72-77 to add the new fields.
- Assistant
It seems the edit command is having trouble with the file parameter. Let me try using the
--fileoption. - Assistant
Let me use sed to edit the file:
- Assistant
Let me try using sed to add the new fields after line 76.
- Assistant
Let me verify the change was applied correctly.
- Assistant
Good, the type is updated. Now let me update the
/modelsendpoint in proxy.ts. Let me first look at the current implementation more carefully: - Assistant
Now let me replace the entire
/modelsendpoint with the new implementation. I need to replace lines 119-172: - Assistant
Let me use a different approach to make the edit. I'll use a script:
- Assistant
Let me try with node instead.
- Assistant
Let me try the
replacespecial command: - Assistant
The replacement was successful. Let me verify the full replacement by scrolling down:
- Assistant
Good, the edit looks correct. Now let me run the existing tests to make sure everything still passes:
- Assistant
Let me wait for the tests to complete. Let me run the full test suite and capture all output:
- Assistant
I need to run from the root or the correct directory.
- Assistant
All 46 test files passed with 456 tests. Let me verify the changes by looking at the diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.