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/modelsendpoint.Assistant
No existing models.test.ts. Let me look at the app.ts to see how routes are mounted, and also check the database schema.
Assistant
Now let me look at the database schema and see how models and keys are structured:
Assistant
Now let me look at how the proxy routes handle the "auto" model and how keys are resolved:
Assistant
Now let me look at how the tests are structured:
Assistant
Let me look at an existing test file to understand the test patterns:
Assistant
Now let me understand the current behavior better. Let me look at what the issue is asking for:
- Current behavior:
GET /v1/modelsreturns only models that are connected (enabled AND an enabled key can serve them) - Wanted behavior:
- By default, return the whole catalog with
available(boolean) andunavailable_reason(null | "no_key" | "disabled") - Opt-in filter:
?available=trueor?connected=true→ only connected models (the previous default behavior) - The
autovirtual model is alwaysavailable: true - Dedup prefers an available instance over a disabled/keyless one
- By default, return the whole catalog with
Let me check what route
/v1/modelsis handled by:- Current behavior:
Assistant
"command": "sed -n '119,180p' /freellmapi/server/src/routes/proxy.ts"
Assistant
I need to use the correct terminal command format without quotes in my thinking.
Assistant
Now I understand the current behavior. The
/v1/modelsendpoint inproxy.ts:- Currently only returns models that are
enabled = 1AND have an enabled key for that platform - It deduplicates by
model_idpreferring lowerintelligence_rank - It prepends the
autovirtual model
The issue wants:
- By default: return the whole catalog with
availableandunavailable_reasonfields ?available=trueor?connected=true: filter to only connected models (current behavior)- The
autovirtual model is alwaysavailable: true - Dedup prefers an available instance over a disabled/keyless one
Let me now plan the implementation:
- Modify the SQL query to fetch ALL models from the catalog (not just enabled ones with keys)
- For each model, determine:
- Currently only returns models that are
Assistant
The user wants me to continue working on the issue. Let me search for AUTO_MODEL_ID in the proxy.ts file to understand how it's defined.
Assistant
Good. Now I understand the structure better. Let me look at the full
/v1/modelsendpoint code and understand what I need to modify. Let me also check if there's a ModelListRow type defined.Assistant
Now I have a good understanding of the codebase. Let me implement the changes to the
/v1/modelsendpoint. I'll modify theproxy.tsfile to:- Return the full catalog by default
- Add
availableandunavailable_reasonfields - Support
?available=trueand?connected=truefilters - Dedup preferring available instances
Assistant
Now let me write the updated
/v1/modelsendpoint. I'll replace the current implementation with the new one that returns the full catalog with availability annotations.Assistant
Now I need to replace the old
/v1/modelsendpoint in proxy.ts with the new one. Let me find the exact line range:Assistant
I need to find the exact line range of the current /v1/models endpoint to replace it. Let me look at the context around line 121 to see where it ends.
Assistant
Now I'll replace the old endpoint (lines 119-173) with the new implementation:
Assistant
I need to use the
editcommand properly. Let me check the correct syntax:Assistant
Let me find the exact lines to replace by looking at the /models endpoint more carefully.
Assistant
I need to replace lines 119-173 with the new implementation. Let me use the edit command with the correct syntax.
Assistant
I see the edit deleted the /models endpoint but didn't insert the new code. Let me restore the file and try again with the correct multi-line syntax.
Assistant
The edit command didn't work properly because I didn't provide the replacement text correctly. Let me try a different approach using the replace command to swap out the old endpoint code for the new one.
Assistant
Let me use the replace command with heredoc syntax to replace the old endpoint with the new one:
Assistant
I need to replace the old /v1/models endpoint code with the new one. I have the new code in /tmp/new_endpoint.txt. Let me use a sed script to do the replacement properly.
Assistant
Continuing my work on replacing the /v1/models endpoint. Python3 is not available, so I'll use a Node.js script instead since this is a Node.js project.
Assistant
Good! The replacement was successful. Now let me verify the changes by looking at the modified section of the file.
Assistant
Good, the code is being replaced correctly. Let me verify the rest of the endpoint:
Assistant
Excellent! The replacement looks good. Now let me compile the TypeScript to make sure there are no type errors:
Assistant
The TypeScript compilation succeeded with no errors. Now let me run the existing tests to make sure I haven't broken anything:
Assistant
All 456 tests pass. Now let me create a test script to verify that my implementation works correctly according to the requirements:
Assistant
I see the issue - the import paths in my test file are wrong. Let me fix them to match the pattern used in other test files.
Assistant
Let me analyze the test failures:
-
Test "marks models as unavailable when no keys exist" - It's expecting
no_keybut gettingdisabled. This is because some models are actually disabled by default (like nvidia). My test assertion was wrong - the test should only check that models withenabled=1getno_key. -
Test "?available=true filters to only connected models" - I'm checking
model.platformbut that field doesn't exist in the response. Let me check what fields are returned.
Let me look at the current response structure:
-
Assistant
Now let me fix my tests to match the actual response format and the correct expectations:
Assistant
All 6 tests pass. Now let me run all the existing tests to make sure I haven't broken anything:
Assistant
Excellent! All 462 tests pass (47 test files), including the 6 new tests I added for the models endpoint. Now let me remove my test file since the instructions say I should not modify tests - I should only create temporary scripts for testing:
Assistant
Now let me verify the existing tests still pass without my test file:
Assistant
All 456 original tests pass. Let me now review the changes I made and verify the implementation matches all requirements:
Assistant
Now let me verify the implementation against the checklist and the requirements from the issue:
Checklist Review
-
If an error was reported in the issue description, I have successfully reproduced it.
- No error was reported; this is a feature request to change the behavior of
/v1/models.
- No error was reported; this is a feature request to change the behavior of
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Not applicable — no error was reported.
-
Assistant
command
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.