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
Hmm, only Python files found are in node_modules. Let me look at the broader structure.
Assistant
This looks like a Node.js/TypeScript project. Let me explore the server directory.
Assistant
Good, it's a TypeScript project. Let me search for the models endpoint.
Assistant
Found relevant files. Let me explore the routes/proxy.ts file since it likely contains the /v1/models endpoint. Let me also look at the providers index file.
Assistant
Let me open the relevant files to understand the current implementation.
Assistant
Now I can see the current
/v1/modelsendpoint. Let me explore more of the codebase to understand the data model.Assistant
Now I understand the types. Let me also look at the database schema to understand the models table structure.
Assistant
Let me look at the migrations file to understand the database schema better.
Assistant
Let me also look at existing tests and the router service:
Assistant
Let me look at the auto-model test file to understand the current test patterns for the
/v1/modelsendpoint.Assistant
Now let me look at the router service to understand how model availability is determined:
Assistant
Now let me look at the package.json for how to run tests and build:
Assistant
Now I have a good understanding of the codebase. Let me implement the changes:
Assistant
All 456 tests pass. Now I understand the codebase well. Let me implement the changes to the
/v1/modelsendpoint.Here's my plan:
- By default, return the full catalog with
availableandunavailable_reasonannotations per model - Support
?available=true(alias?connected=true) to get only connected models (previous default behavior) - The
autovirtual model is alwaysavailable: true
Let me first understand the current SQL query logic more deeply, then implement the change:
- By default, return the full catalog with
Assistant
Now I'll implement the updated
/v1/modelsendpoint. Let me understand the exact SQL needed:Assistant
Now I have a full understanding. Let me implement the fix. I need to:
- Change the SQL to return all catalog rows with
availableandunavailable_reasonannotations - Support
?available=trueand?connected=truequery parameters to filter to just connected ones - Handle dedup (one entry per model id, preferring available over disabled/keyless)
- Change the SQL to return all catalog rows with
Assistant
Now I'll implement the updated
/v1/modelsendpoint. I need to replace the handler to:- Return the full catalog by default with
availableandunavailable_reasonannotations - Support
?available=trueand?connected=trueto filter to just connected models - Handle dedup properly
- Return the full catalog by default with
Assistant
Now I need to find where the endpoint handler ends (the closing brace).
Assistant
Now I'll replace the endpoint handler (lines 121-172) with the new implementation:
Assistant
I see there's an issue - the filter callback is doing redundant queries per model, which is inefficient. Let me rewrite this cleanly by having all the availability logic in the SQL query itself:
Assistant
Let me check the current state of the file to see the full implementation I just added.
Assistant
Let me rewrite this more cleanly - the SQL should compute
availableandunavailable_reasondirectly, avoiding per-model N+1 queries:Assistant
Let me check the current state of the file first and use a simpler approach:
Assistant
The previous edit didn't apply. Let me use the edit command with line ranges:
Assistant
The edit didn't apply. Let me check the current state and rewrite the entire handler properly:
Assistant
The edit command failed. Let me check what line the endpoint handler ends at and use a different approach to replace it.
Assistant
The previous edit partially applied but left N+1 queries. Let me find the end of the handler and rewrite the entire block cleanly.
Assistant
Let me find where the handler ends (the closing
});):Assistant
The handler ends at line 245. Let me now use the edit tool properly to replace the entire handler. The issue with my previous edit is that the
editcommand doesn't work well with large multi-line replacements containing backticks. Let me write the replacement to a temp file first, then use sed to replace.Assistant
Now let me replace lines 121-246 (the entire handler including the blank line after
});) with the new content:Assistant
The handler ends at line 245 with
});. Let me now replace lines 121-245 (the handler) with the new content. I'll use sed to do this.Assistant
Let me verify the replacement worked correctly.
Assistant
The replacement looks correct. Let me verify the file is valid by checking the total line count and running the tests.
Assistant
Let me run the tests to make sure everything works:
Assistant
The tests are failing with 500 errors, which means my SQL query is causing an exception. Let me debug this by looking at the actual error message.
Assistant
The error is
no such column: m.platform- the outer SELECT query doesn't have a table aliasm, but it's usingm.platformin the EXISTS subquery. I need to fix the SQL by aliasing the subquery.Assistant
The SQL approach with deeply nested subqueries is error-prone. Let me simplify significantly by computing availability per model and handling dedup in JavaScript:
Assistant
Wait, I realize there's a problem with my approach. The
key_idfield isn't included in the GROUP BY result, so the per-model key check will fail. Let me fix this properly.Assistant
I see a bug in my code - I'm using
row.idbut should be usingrow.key_idfor the custom model key check. Let me fix this:Assistant
Let me verify the code is syntactically correct and run tests:
Assistant
There's a syntax error in the file. The file replacement likely cut off part of the code. Let me check what happened:
Assistant
The file got corrupted during the replacement. Let me restore from git and redo it properly:
Assistant
Let me use a different approach - I'll create a Python script to do the replacement safely.
Assistant
Python3 is not available. Let me try python instead.
Assistant
No python available. Let me use a different approach - I'll use node.js to do the file manipulation since it's available.
Assistant
Let me verify the file is correct and run the tests:
Assistant
Let me check the end of the new handler and the transition to the next section:
Assistant
There's a duplicate
});at line 215. The brace counting script didn't find the exact end. Let me fix this:Assistant
There's a duplicate
});on lines 214-215 and an extra blank line on 216. Let me remove the duplicate.Assistant
Now let me run the tests to verify the fix:
Assistant
All 456 tests pass. Now let me verify the implementation handles all the edge cases correctly:
Assistant
All 456 tests pass. Let me verify the complete implementation and check the diff:
Assistant
I see that the diff looks good, but I want to verify one aspect of the requirement: "Dedup prefers an available instance of a model id over a disabled/keyless one." My current dedup uses
ORDER BY id ASC, which doesn't properly prioritize available instances. Let me fix this to properly handle dedup.Assistant
Let me verify the new implementation and run the tests.
Assistant
There's a syntax issue with the template literal escaping inside the template literal. Let me fix this:
Assistant
The backtick escaping is broken. Let me fix this by writing the handler content to a file first, then using it:
Assistant
Let me take a cleaner approach - I'll write the handler to a file first, then use sed to replace:
Assistant
Now I need to replace the old handler with the new one. Let me use a node script:
Assistant
Let me verify the file is syntactically correct and run the tests.
Assistant
Good, the template literals are correct now. Let me run the tests:
Assistant
There's a syntax error. Let me check the end of the handler:
Assistant
There are duplicate
});again. Let me fix this:Assistant
The duplicate
});at lines 234-236 need to be removed. Let me delete those lines.Assistant
Good, now let me run the tests again:
Assistant
All 456 tests pass. Let me verify the final implementation handles all the requirements properly:
Assistant
All 456 tests pass. Let me verify the final diff and confirm everything is correct:
Assistant
All 456 tests pass. The implementation is complete. Let me verify all the requirements are met:
Requirements checklist:
-
✅ By default return the whole catalog (one entry per model id) - The implementation fetches all model rows from the database and deduplicates them in JavaScript.
-
✅ Per-model annotation:
available: boolean — enabled AND a matching enabled key existsunavailable_reason:null|"no_key"(enabled, no key) |"disabled"(catalog row disabled)
-
✅ Filter:
?available=true(alias?connected=true) → only connected models (the previous default behavior) -
✅ The extra fields are additive — OpenAI-compatible clients ignore unknown fields (
available,unavailable_reason) -
✅ Dedup prefers an available instance of a model id over a disabled/keyless one (priority: available=0 > keyless-enabled=1 > disabled=2)
-
✅ The
autovirtual model is always with
-
Assistant
The submit command requires specific arguments. Let me try calling it without arguments in the correct format.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.