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 the repo might be JavaScript/TypeScript or another language. Let me look at the structure more carefully.
Assistant
This is a Node.js/TypeScript project. Let me explore the server directory.
Assistant
Good, this is a Node.js/TypeScript project. Let me find the
/v1/modelsendpoint implementation.Assistant
The
/v1/modelsendpoint isn't directly in the proxy routes. Let me search more broadly.Assistant
Let me look at the main server entry point and all route files.
Assistant
Found it! Let me examine the models route file.
Assistant
Now I understand the current code. Let me also check the git history and the providers module to understand the
hasProviderfunction.Assistant
Let me look at the providers index to understand what
hasProviderdoes, and also look at the database schema:Assistant
Let me now look at the database schema and check for existing tests:
Assistant
Let me check the database migrations to understand the schema and also look for any existing tests:
Assistant
I need to look at the models table schema more carefully and find any existing tests for the
/v1/modelsendpoint.Assistant
Now I understand the structure. Let me look for existing tests related to models:
Assistant
Let me check if there's an existing test file for models routes:
Assistant
Interesting! The test shows that the
/v1/modelsendpoint returns OpenAI-style format withobject: 'list'anddataarray, and the first entry should beid: 'auto'. But the current code I saw inmodels.tsreturns a plain array. Let me check the app setup and see how routes are organized.Assistant
I see
/v1/modelsis NOT served bymodelsRouter(which is mounted at/api/models). Let me check the proxy routes:Assistant
Let me look at the
/v1/modelsendpoint in the proxy routes more carefully.Assistant
Now I understand the full picture. Let me look at the ModelListRow type and understand the full current response format:
Assistant
Let me check the shared types:
Assistant
Now I have a complete understanding. Let me also check for existing tests to run:
Assistant
I need to understand the current state of the code and make my changes step by step. Let me look at the proxy.ts file more carefully to understand the full endpoint, and check if there are tests I can run.
Assistant
Now I have a thorough understanding of the codebase. Let me first run the existing tests to confirm baseline, then implement the changes.
Assistant
Now I have a thorough understanding of the codebase. Let me implement the changes. The
/v1/modelsendpoint is inproxy.ts(lines 119-169). I need to:- Return the full catalog (not just connected models)
- Add
availableandunavailable_reasonfields per model - Add
?available=true/?connected=truefilter - Keep the
autovirtual model always available
Let me first see the exact lines to replace:
Assistant
Now I have the complete picture. Let me also check what's on the
api_keystable to understand the key checking logic:Assistant
Now I have a complete understanding of the codebase and requirements. Let me implement the changes:
- Current:
/v1/modelsreturns only connected models (enabled + has an enabled key) - Wanted: Return the whole catalog with per-model
availableandunavailable_reasonannotations, plus an opt-in?available=true/?connected=truefilter
Let me edit the
/v1/modelsendpoint:- Current:
Assistant
Now I have a thorough understanding of the codebase. Let me implement the changes to the
/v1/modelsendpoint inproxy.ts. The changes needed are:- Return the whole catalog (one entry per model id), annotated with
availableandunavailable_reason - Support
?available=true/?connected=truefilter to get only connected models - Keep the
autovirtual model always available
- Return the whole catalog (one entry per model id), annotated with
Assistant
Now I need to replace the
/v1/modelsendpoint. Let me construct the new implementation:Assistant
Let me use the
bash_terminalwith a heredoc approach to do the edit:Assistant
Let me use a script to do the replacement since there are special characters:
Assistant
Let me try with
nodeinstead since this is a Node.js project:Assistant
Let me use Node.js to do the replacement since python3 isn't available.
Assistant
Let me verify the changes were applied correctly:
Assistant
Let me check the rest of the function to make sure it's complete:
Assistant
The changes look correct. Now let me compile to verify TypeScript is happy:
Assistant
I need to fix the TypeScript type. The inline tuple type syntax with semicolons doesn't work in TypeScript the way I wrote it. Let me define a proper interface instead:
Assistant
Let me fix the TypeScript type issue by using
anyfor the database result (consistent with the existing code pattern in the same file):Assistant
Let me verify the changes and try to build again.
Assistant
There seems to be a template literal issue. Let me look at the file more carefully around line 166.
Assistant
The backtick was consumed by the string template literal in my fix script. The
`before.all()was lost. I need to fix this - the backtick at the end of the template literal was removed. Let me check and fix it.The backtick at the end of the template literal was consumed by my replacement. Let me fix it:
<tool_call> <function=bash_terminal> <parameter=command> cat > /tmp/fix_backtick.mjs << 'NODEEOF' import { readFileSync, writeFileSync } from 'fs';
const content = readFileSync('/freellmapi/server/src/routes/proxy.ts', 'utf8');
// Fix: the backtick was consumed - need to restore it const bad = 'ORDER BY intelligence_rank ASC, id ASC\n
.all() as any[];'; const good = 'ORDER BY intelligence_rank ASC, id ASC\n).all() as any[];';const result = content.replace(bad, good);
if (result !== content) { writeFileSync('/freellmapi/server/src/routes/proxy.ts', result, 'utf8'); console.log("SUCCESS: Fixed backtick"); } else { console.log("ERROR: Could not find text to fix"); process.exit(1); } NODEEOF node /tmp/fix_backtick.mjs </tool_call>
Assistant
The backtick was consumed by the string template literal in my fix script. The
`before.all()was lost. Let me fix this - the backtick at the end of the template literal was removed. Let me check and fix it.Actually, looking at the output more carefully, I see
.all()right afterASC\nwithout the backtick. The replacement script replaced the entire string including the backtick. I need to fix this.Assistant
Good, the backtick is restored. Let me verify the fix and try building again.
Assistant
Good, the backtick is restored. Let me try building again.
Assistant
I need to fix the SQL parameter binding. Let me check how the rest of the codebase uses parameters:
Assistant
Let me check how better-sqlite3 is used in the codebase for parameterized queries.
Assistant
I see - better-sqlite3's
.get()takes params as arguments, not in the.prepare()call. Let me check the proper syntax:Assistant
I see the issue - better-sqlite3's
.prepare()only takes SQL, and parameters go into.get(params). Let me fix this:Assistant
Let me fix the better-sqlite3 parameter passing syntax.
Assistant
The better-sqlite3 parameter passing syntax was wrong - parameters should be passed to
.get(), not to.prepare(). Let me fix that and try building again.Assistant
The build succeeded. Now let me run the existing tests to confirm nothing broke:
Assistant
The tests are failing with a 500 error. The issue is likely with the SQL query - the
${keyCheck}interpolation in the template literal might be causing a problem. Let me debug:Assistant
The issue is that
EXISTS(${keyCheck})producesEXISTS(( ... ))— double parentheses. ThekeyCheckalready has parentheses, soEXISTSaround it creates invalid SQL. Let me fix this:Assistant
The
keyCheckvariable already includes parentheses, soEXISTS(${keyCheck})producesEXISTS(( ... ))— double parentheses, which is invalid SQL. I need to fix this by removing the outer parentheses fromkeyCheck.Assistant
Good. Let me verify the fix and run the tests again.
Assistant
All 456 tests pass. Let me verify my implementation is complete and correct by reviewing the final code:
Assistant
The implementation looks complete. Let me now create a quick verification script to test the behavior:
Assistant
The existing tests already pass. Let me verify the full implementation one more time and check the test output confirms the endpoint works:
Assistant
All tests pass. Let me verify the implementation against all requirements:
Assistant
All 456 tests pass. Let me verify the implementation against every requirement from the issue:
Assistant
The implementation is complete. Let me summarize the checklist verification:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.