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
It seems this is a JavaScript/TypeScript project with Node.js modules. Let me look more carefully at the structure.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /freellmapi/ </tool_call>
Assistant
The user wants me to explore the repository structure. Let me use bash to list the files and directories.
Assistant
This is a Node.js project. Let me explore the server directory where the API routes likely are.
Assistant
Let me search for the
/v1/modelsroute handler.Assistant
Let me look for the actual handler that serves
GET /v1/models.<tool_call> <function=bash_terminal> <parameter=command> grep -rn "'/v1/models'" /freellmapi/server/src/ --include="*.ts" | grep -v "tests" </tool_call>
Assistant
The user wants me to find the handler for GET /v1/models. Let me search more broadly for route definitions.
Assistant
I found a dedicated models.ts route file. Let me examine both files:
Assistant
Now let me also look at the proxy.ts models handler and the hasProvider function:
Assistant
Let me understand how these routers are mounted and check the hasProvider function:
Assistant
Now I can see that the
GET /v1/modelsendpoint is inroutes/proxy.tsand themodelsRouterinroutes/models.tsseems to be defined but I need to check if it's actually being used. Let me check the app.ts file and also see the hasProvider function.Assistant
I can see the architecture now. Let me analyze:
GET /v1/modelsis handled inroutes/proxy.ts(proxyRouter) - this is the OpenAI-compatible endpointGET /api/modelsis handled inroutes/models.ts(modelsRouter) - this is behind auth for admin purposes
The issue is about
GET /v1/models. Currently it returns only connected models. The requirement is:- By default, return the whole catalog (one entry per model id), each annotated with whether it's usable
- Per-model annotation:
available(boolean),unavailable_reason(null | "no_key" | "disabled") - Filter:
?available=true(alias?connected=true) → only connected models
Now let me look at the
hasProviderfunction:<tool_call> <function=bash_terminal> <parameter=command> cat /freellmapi/server/src/providers/index.ts </tool_call>
Assistant
The user wants me to look at the hasProvider function in providers/index.ts. Let me read that file.
Assistant
Now let me look at the AUTO_MODEL_ID and the existing tests:
Assistant
Now let me look at the existing tests for this endpoint:
Assistant
Let me look at the proxy-auto-model test file since it specifically tests /v1/models:
Assistant
Let me see the full proxy.ts file to understand the model list query better:
Assistant
Let me look at the shared types to understand the data structures:
Assistant
Let me now look at the database schema to understand the models table:
Assistant
Let me see the models table schema:
Assistant
Let me check how the fallback_config table is defined and also look at the existing routes/models.ts more carefully:
Assistant
Now I have a good understanding of the codebase. Let me now understand what I need to do:
- Currently
GET /v1/modelsreturns only connected models (enabled AND has an enabled key) - I need to modify it to:
- By default, return the whole catalog (one entry per model id)
- Each model should be annotated with
available(boolean) andunavailable_reason(null | "no_key" | "disabled") - Add opt-in filter
?available=true(alias?connected=true) to get just connected models - The
autovirtual model is alwaysavailable: true - Dedup prefers an available instance of a model id over a disabled/keyless one
Let me now modify the
GET /v1/modelsendpoint inroutes/proxy.ts. </tool_call>- Currently
Assistant
Now I understand the codebase. Let me implement the fix for the
GET /v1/modelsendpoint. I need to modify the handler inroutes/proxy.tsto return the full catalog with per-model availability annotations and support opt-in filtering.Assistant
Assistant
Now I need to replace the
/v1/modelshandler. Let me write the replacement:Assistant
Let me find the exact line range for the current
/modelshandler to replace:Assistant
So the handler spans from line 119 (comment start) to line 173 (closing
});), withconst MAX_RETRIES = 20;on line 175. Let me check line 174:Assistant
I need to find the exact line range of the
/v1/modelshandler to replace it. Let me look more carefully at the boundaries.From what I can see:
- Line 119-120: Comment
- Line 121:
proxyRouter.get('/models', ...)start - The handler ends with
}); - Line 173 or 174: Should be the end of the handler
- Line 175:
const MAX_RETRIES = 20;
Let me check the exact ending.
Assistant
Now I can see the handler ends at line 172. Let me replace it:
Assistant
Let me verify the replacement file looks correct:
Assistant
Let me continue verifying the replacement file and then apply it.
Assistant
The replacement file looks correct. Let me apply it:
Assistant
Now let me verify the file was correctly updated and run the existing tests:
Assistant
Let me run the existing tests, particularly the one that tests the
/v1/modelsendpoint:Assistant
All 46 test files passed (456 tests). Let me verify the specific proxy-auto-model tests and also check TypeScript compilation:
Assistant
TypeScript compilation passed. Let me verify the implementation once more by looking at the final code:
Assistant
All 46 test files passed (456 tests). Let me verify the full changes with git diff:
Assistant
The diff looks correct. All 46 test files passed (456 tests). Let me verify the implementation one more time and run the specific auto-model tests:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.