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
Let me start by understanding the repository structure and the codebase. This appears to be a FastAPI-based API for LLM models. Let me explore the repository structure first.
The issue is about modifying the
/v1/modelsendpoint to:- Return the full catalog with per-model availability annotation
- Add
available(boolean) andunavailable_reason(null, "no_key", or "disabled") fields - Support
?available=true(or?connected=true) filter - Dedup prefers available instances
autovirtual model alwaysavailable: true
Let me explore the codebase.
Assistant
Hmm, that doesn't look right. Let me look at the actual repo structure.
Assistant
The server directory seems to be where the main code is. Let me explore that.
Assistant
No .py files in server. Let me check what's in server.
Assistant
It's a TypeScript project. Let me find the
/v1/modelsendpoint.Assistant
The models route is in
/freellmapi/server/src/routes/models.ts. Let me look at itAssistant
Let me just use cat to read the file.
Assistant
Let me also look at related services and the router for better context
Assistant
Let me look at the DB schema to understand the models and api_keys tables.
Assistant
Let me also search for "auto" model references and look at how the models are used elsewhere
Assistant
Let me look at the health service and the proxy to see how "auto" model works.
Assistant
Let me look at the shared types and the proxy route for the "auto" model handling.
Assistant
Let me check for any existing tests for the models route.
Assistant
Let me check the full-flow test and the catalog-sync test for models endpoint
Assistant
Let me check the app.ts and also look at the full router.ts (the rest of it).
Assistant
The
/v1/modelsendpoint is part of the proxy. Let me check the proxy routeAssistant
Now I have a good understanding of the codebase. Let me look at the current
/v1/modelshandler in proxy.ts more carefully and then implement the changesAssistant
Let me see lines 119-170 of proxy.ts
Assistant
Now I have a clear understanding of the current implementation and what needs to change. Let me implement the fix
Assistant
Now let me make the edit to the
/v1/modelsendpoint in proxyAssistant
Let me find the exact lines to replace
Assistant
Let me find the start and end of the handler.
Assistant
Let me check the exact lines
Assistant
Let me count lines precisely
Assistant
Now let me use the edit command to replace the handler. I'll open the file first
Assistant
Now let me replace lines 119-172 with the new handler
Assistant
Let me use a different approach - write the replacement to a temp file and use sed
Assistant
Let me write a script to a file first
Assistant
Let me verify the changes were applied correctly
Assistant
The changes weren't applied. Let me check if python is available and try a different approach
Assistant
No Python. Let me use Node.js to do the replacement
Assistant
Let me adjust the search for the end of the
Assistant
Now let me use Node.js to do the actual
Assistant
Let me verify the
Assistant
Good, the changes look correct. Let me verify the transition and check the full file compiles correctly
Assistant
Let me check around line 240:
Assistant
The transition is clean. Now let me check if TypeScript compiles. Let me first see how to build/test
Assistant
Let me run the TypeScript compiler to check for
Assistant
TypeScript compiles cleanly. Let me now run the existing tests to make sure nothing is
Assistant
All 456 tests pass. Let me also check if there are any specific tests for the
/v1/modelsendpointAssistant
Let me check those test files
Assistant
Let me check the proxy-auto-model test file for
/v1/modelstestsAssistant
Let me run the specific auto-model test to check
Assistant
Let me also check how keyless platforms are handled in the codebase
Assistant
Let me check how keyless platforms are handled
Assistant
Let me check the providers to find the keyless ones and how they set up sentinel keys.
Assistant
Let me check where sentinel keys are created
Assistant
Let me search for sentinel key creation
Assistant
Let me check where sentinel rows are auto-created for keyless providers
Assistant
Let me run the full test suite one more time to be
Assistant
All 456 tests pass. Let me verify the changes with git diff
Assistant
Let me verify the
ModelListRowimport isn't broken (it was used by the old handler but is no longer needed in my new code but might be used elsewhere)Assistant
Let me check if unused imports would cause issues
Assistant
The import is unused but won't cause errors. Let me clean it up for good practice
Assistant
Let me verify it still compiles and tests pass
Assistant
Everything passes. Let me verify the final diff
Assistant
The implementation is complete. Let me summarize what was done:
Changes Made
File:
server/src/routes/proxy.ts-
Changed the
/v1/modelsendpoint to return the full catalog with per-model availability annotations instead of only connected models. -
Key behavior changes:
- Default response: Now returns ALL models from the catalog (not just connected ones)
- New fields per model:
available(boolean):trueif the model is enabled AND a matching enabled API key existsunavailable_reason(string|null):nullif available,"no_key"if enabled but no key,"disabled"if the catalog row is disabled
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.