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 find the relevant files for the
/v1/modelsendpoint.Assistant
This seems to be a Node.js project. Let me explore the structure more.
Assistant
Let me look at the current
models.tsfile to understand the current implementation:Assistant
Now let me explore more of the codebase to understand the data models and how keys/models work:
Assistant
Now let me check for tests related to models:
Assistant
I don't see a
models.test.tsfile. Let me check theapp.tsto understand the route structure:Assistant
Now I see there are two different model endpoints:
/api/models- the admin/internal route (behind auth) - this is inmodels.ts/v1/models- the OpenAI-compatible proxy route
Let me check the
proxy.tsandresponses.tsfor how/v1/modelsis handled:Assistant
Let me see the full
/v1/modelsimplementation in proxy.ts:Assistant
Now let me understand the database schema for models. Let me check the migrations:
Assistant
Let me search for the models table schema more broadly.
Assistant
Now let me also look at the shared types:
Assistant
Now let me check the existing tests to understand the test patterns:
Assistant
Now let me look at the AUTO_MODEL_ID constant:
Assistant
Now let me understand the full requirements from the issue. Let me re-read it and plan my changes:
Requirements:
- By default,
/v1/modelsshould return the whole catalog (one entry per model id), each annotated withavailable(boolean) andunavailable_reason(null | "no_key" | "disabled") - An opt-in filter
?available=true(alias?connected=true) to get just connected models (previous default behavior) - 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
autovirtual model is alwaysavailable: true
Let me now look at the current SQL query more carefully:
- By default,
Assistant
Now I understand the current implementation. Let me write my solution. The key changes needed:
- Modify the query to fetch all models from the catalog (not just enabled + connected ones)
- Determine
availableandunavailable_reasonfor each model - Support
?available=trueand?connected=truequery parameters for filtering - Add
availableandunavailable_reasonto the response
Let me first run the existing tests to make sure they pass:
Assistant
All 456 tests pass. Now let me implement the changes. Let me look at the full proxy.ts file to understand the context better:
Assistant
Now let me implement the changes. I'll modify the
/v1/modelsendpoint inproxy.ts:Assistant
Now I'll create the replacement for the
/v1/modelsendpoint. Let me also check the ModelListRow type:Assistant
Now I understand the structure. I need to:
- Create a new SQL query that fetches all models from the catalog
- For each model, determine if it has an enabled key (available) or not
- Determine the
unavailable_reasonif not available - Support
?available=trueand?connected=truefilter parameters - Add
availableandunavailable_reasonfields to each model entry
Let me now write the replacement code:
Assistant
Now let me apply this change to the proxy.ts file. I need to replace the old
/modelsendpoint (lines 119-171) with the new one:Assistant
Let me check lines 172-174 to be sure:
Assistant
So the old endpoint is from line 119 to line 172 (inclusive). Let me now replace it:
Assistant
The edit was applied. Let me verify the complete replacement looks correct:
Assistant
The code looks correct. Now let me run the existing tests to make sure they still pass:
Assistant
All 456 tests pass. Now let me create a test script to verify the new functionality works correctly:
Assistant
Let me run this test file to validate the new functionality:
Assistant
The test file needs to be in the proper test directory and follow naming conventions. Let me create it properly:
Assistant
The imports need to be relative. Let me fix the test file:
Assistant
All 7 new tests pass. Now let me also run all existing tests to make sure nothing is broken:
Assistant
All 463 tests pass (456 original + 7 new). Now let me remove my test file since I was instructed not to modify tests:
Assistant
Let me run the original tests one more time to confirm everything still works:
Assistant
All 456 original tests pass. Let me also check the git diff to review my changes:
Assistant
The changes look correct. Let me verify the final implementation one more time by reviewing the complete
/v1/modelsendpoint:Assistant
The implementation looks complete. Let me now verify that all original tests still pass one final time:
Assistant
All 456 tests pass. Let me also check that the TypeScript compiles without errors:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.