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
Let me start by exploring the repository structure to understand the codebase and find the relevant files for the
/v1/modelsendpoint.Assistant
Let me explore the repository structure more broadly to find the main source code.
Assistant
This appears to be a Node.js project with a server directory. Let me explore the server directory to find the code that handles the
/v1/modelsendpoint.<tool_call> <function=bash_terminal> <parameter=command> ls -la /freellmapi/server </tool_call>
Assistant
Let me run the command to explore the server directory.
Assistant
Let me explore the server/src directory to find the code handling the
/v1/modelsendpoint.<tool_call> <function=bash_terminal> <parameter=command> find /freellmapi/server/src -type f -name "*.ts" | head -30 </tool_call>
Assistant
Let me run the command to find TypeScript files in the server/src directory.
Assistant
Now let me search for where the
/v1/modelsendpoint is handled. Let me search for "models" in the codebase.<tool_call> <function=bash_terminal> <parameter=command> grep -r "models" /freellmapi/server/src --include="*.ts" | grep -v node_modules </tool_call>
Assistant
Let me try the grep command again to search for "models" in the codebase.
Assistant
I found a relevant file:
/freellmapi/server/src/routes/models.ts. This seems to be the main file handling the/v1/modelsendpoint. Let me examine it to understand the current implementation.<tool_call> <function=bash_terminal> <parameter=command> cat /freellmapi/server/src/routes/models.ts </tool_call>
Assistant
Let me run the cat command to view the models.ts file.
Assistant
Now I understand the current implementation. Let me also look at the test file for this endpoint to understand the expected behavior better, and check how the API determines whether a model is "available".
Let me search for tests related to the models endpoint.
<tool_call> <function=bash_terminal> <parameter=command> cat /freellmapi/server/src/tests/routes/proxy-auto-model.test.ts </tool_call>
Assistant
Let me run the cat command to view the test file.
Assistant
Now I understand the current behavior better. The test shows that the
/v1/modelsendpoint returns data with a specific format (includingobject,data, etc.), but the current implementation inmodels.tsreturns a simple array. Let me look at how the/v1/modelsendpoint is actually served. Let me check the proxy.ts file as well.<tool_call> <function=bash_terminal> <parameter=command> grep -A 50 "proxyRouter.get('/models'" /freellmapi/server/src/routes/proxy.ts </tool_call>
Assistant
Let me run the grep command to see how the
/v1/modelsendpoint is implemented.Assistant
Now I understand the current implementation. The
/v1/modelsendpoint inproxy.tsreturns:- Only models that are connected (enabled AND have an enabled key)
- Adds a virtual "auto" model as the first entry
Based on the issue description, I need to:
- Return the full catalog (all models) with per-model availability info
- Add
availableandunavailable_reasonfields to each model - Add an opt-in filter
?available=true(alias?connected=true) to get just the connected models - The "auto" virtual model is always
available: true
Let me look at the full
proxy.tsfile to understand the structure better, then update it.<tool_call> <function=bash_terminal> <parameter=command> cat /freellmapi/server/src/routes/proxy.ts | head -150 </tool_call>
Assistant
Let me run the cat command to view the proxy.ts file.
Assistant
Now I understand the current implementation. Let me look at what shared types are available to understand what type definitions exist.
<tool_call> <function=bash_terminal> <parameter=command> cat /freellmapi/shared/types.ts </tool_call>
Assistant
Let me run the cat command to view the shared types file.
Assistant
Now I have a good understanding of the codebase. Let me now:
- First, I'll look at how to determine if a model is "available" (enabled AND has an enabled key)
- Then update the
/v1/modelsendpoint to:- Return the full catalog by default
- Add
availableandunavailable_reasonfields - Support
?available=trueand?connected=truefilters to return only connected models
Let me also check how the API key lookup works to understand how to check if a model has an enabled key.
Looking at the current implementation in
proxy.ts:WHERE m.enabled = 1 AND EXISTS ( SELECT 1 FROM api_keys k WHERE k.platform = m.platform AND k.enabled = 1 AND (m.key_id IS NULL OR k.id = m.key_id) )So a model is "available" when:
- It's enabled in the catalog (
m.enabled = 1)
Assistant
Let me run the grep command to search for "available" in the tests.
Assistant
I need to implement the changes for the
/v1/modelsendpoint. Let me first understand what changes are needed by examining the current implementation more carefully.<tool_call> <function=bash_terminal> <parameter=command> grep -A 100 "proxyRouter.get('/models'" /freellmapi/server/src/routes/proxy.ts </tool_call>
Assistant
Let me run the grep command to view the full proxy.ts models endpoint implementation.
Assistant
Now I understand the full context. Let me implement the required changes to the
/v1/modelsendpoint. I need to:- Return the full catalog (all models) by default
- Add
availableandunavailable_reasonfields per model - Support
?available=trueand?connected=truefilter to return only connected models - The "auto" virtual model is always
available: true
Let me first check the full structure of the proxy.ts file to see what other types I might need:
Assistant
Assistant
Let me run the cat command to see the content of the file.
Assistant
The heredoc command didn't complete properly. Let me try a different approach and use the
editcommand to modify the proxy.ts file directly.First, let me find the exact line numbers of the models endpoint in proxy.ts.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "proxyRouter.get('/models'" /freellmapi/server/src/routes/proxy.ts </tool_call>
Assistant
Let me run the grep command to find the line number of the models endpoint.
Assistant
Now I know the endpoint starts at line 121. Let me see more context around it to understand the full function.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '121,180p' /freellmapi/server/src/routes/proxy.ts </tool_call>
Assistant
Let me run the sed command to see the models endpoint function.
Assistant
Now I can see the current implementation. Let me use the
editcommand to replace the models endpoint with the new implementation that returns the full catalog with availability info and supports the optional filter.Assistant
The edit command was applied successfully. Let me verify the changes are correct by viewing the updated code.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '121,220p' /freellmapi/server/src/routes/proxy.ts </tool_call>
Assistant
Let me run the sed command to view the updated code.
Assistant
The changes look correct. Now I need to make sure there's a closing brace for the function. Let me check what comes after.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '210,230p' /freellmapi/server/src/routes/proxy.ts </tool_call>
Assistant
Let me run the sed command to see what comes after the models endpoint.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '210,230p' /freellmapi/server/src/routes/proxy.ts </tool_call>
Assistant
The sed command didn't execute. Let me try again with proper formatting.
Assistant
The code looks correct - the function is properly closed and the constant
MAX_RETRIESfollows. Now let me verify the TypeScript compiles correctly and check if there are any tests I should run.Assistant
No TypeScript errors. Now let me run the tests to make sure the existing tests pass with the new implementation.
Assistant
Let me continue to check if all tests pass.
<tool_call> <function=bash_terminal> <parameter=command> cd /freellmapi/server && npx vitest run --reporter=verbose 2>&1 | tail -100 </tool_call>
Assistant
Let me continue to check if all tests pass.
Assistant
All 456 tests passed. Now I need to look at the test for the
/v1/modelsendpoint to make sure the test expectations are compatible with the new implementation. Let me check the test file that tests the models endpoint.Looking at the test file
/freellmapi/server/src/__tests__/routes/proxy-auto-model.test.ts, I see that it tests the format of the response. The current test expects:statusto be 200body.objectto be 'list'body.data[0]to have specific properties
Let me check if my implementation is compatible with these tests. Looking at the test, it expects
body.datato be an array (since it accessesbody.data[0]), but my implementation wraps it in an object withobject: 'list'anddata: [...].Wait, looking at the test more closely:
Assistant
The user is running a command to test the proxy-auto-model test file. Let me execute that command to see if the test passes.
Assistant
All 5 tests in the proxy-auto-model.test.ts file passed! This is great news. The tests confirm that:
- The "auto" model is listed first
- The response format is correct (with
objectanddata)
Assistant
Let me review the current implementation of the models endpoint to ensure it's correct and efficient.
Assistant
I see that the SQL query calls
NOT EXISTStwice - once in the main query and once in the ORDER BY clause. This could be inefficient. Let me refactor to use a CTE (Common Table Expression) to calculateavailability_statusonce and then use it in the ORDER BY.Assistant
The edit command failed because of a parsing issue. Let me try a different approach to update the SQL query.
Let me first check the line numbers more carefully and then use a more precise edit command.
Assistant
Let me try to find the line where the query ends.
Assistant
Let me find the line where the SQL query ends (after
.all() as any[]).Assistant
So lines 136-171 contain the query I want to replace. Let me use the goto command to navigate to line 136 and then use edit to replace the relevant portion.
Assistant
Let me try a different approach using the
replacecommand with a simpler search pattern.Assistant
Let me use the correct format for the replace command:
Assistant
The SQL query has been updated to use a CTE (Common Table Expression) for better efficiency. Now let me run the tests to ensure everything still passes:
Assistant
There's a test failure. Let me check what the error is by looking at the full error message:
Assistant
The error is "no such column: id" - this is because in my CTE I renamed
idtomodel_id_row, but then in the ORDER BY I'm still usingid. Let me fix this by using the correct column name:Assistant
Now let me run the tests again to verify the fix:
<tool_call> <function=bash_terminal> <parameter=command> cd /freellmapi/server && npx vitest run src/tests/routes/proxy-auto-model.test.ts 2>&1 </tool_call>
Assistant
Let me run the test command to verify the fix works.
Assistant
All tests in the proxy-auto-model.test.ts file pass now. Let me run all the tests to ensure nothing else is broken:
<tool_call> <function=bash_terminal> <parameter=command> cd /freellmapi/server && npx vitest run 2>&1 | tail -20 </tool_call>
Assistant
Let me run all tests to ensure nothing else is broken.
Assistant
All 456 tests pass. Now let me verify the TypeScript compilation:
<tool_call> <function=bash_terminal> <parameter=command> cd /freellmapi/server && npx tsc --noEmit 2>&1 </tool_call>
Assistant
Let me check TypeScript compilation status.
Assistant
The TypeScript compilation passed without errors (exit code 0).
Now let me review my implementation one more time to make sure it meets all the requirements from the issue description:
-
✅ Return the full catalog (one entry per model id): The query now selects all models from the
modelstable, not just enabled ones with keys. -
✅ 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
autovirtual model is always : In my implementation, the auto model has and
-
Assistant
Let me run the command to see the current implementation.
Assistant
The implementation looks good and meets all the requirements. Let me do a final verification by checking the git diff to see all changes:
<tool_call> <function=bash_terminal> <parameter=command> cd /freellmapi && git diff server/src/routes/proxy.ts </tool_call>
Assistant
Let me run git diff to see the changes made to the proxy.ts file.
Assistant
The git diff shows the changes I've made:
- Added query parameter parsing for
?available=trueand?connected=true - Changed the SQL query to return all models with availability information using a CTE
- Added deduplication logic that prefers available instances
- Added filtering for connected models when requested
- Added
availableandunavailable_reasonfields to each model in the response - The
automodel now hasavailable: trueandunavailable_reason: null
Let me also check if there are any other changes in the repository that I need to be aware of:
<tool_call> <function=bash_terminal> <parameter=command> cd /freellmapi && git status </tool_call>
- Added query parameter parsing for
Assistant
Let me run the git status command to check if there are any other changes in the repository.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.