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.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /freellmapi, current file: none) bash-$
- Assistant
I’ll inspect the repository structure and locate the
/v1/modelsimplementation and its tests before making changes. - Assistant
The initial search was polluted by dependencies. I’ll narrow it to server source/tests and inspect package scripts and data-layer types to understand catalog and key semantics.
- Assistant
I’ll now locate route declarations directly and inspect the complete handler plus related database schema/helpers and integration test setup.
- Assistant
The OpenAI endpoint is in
proxy.ts; there is also an internal models route that may share model shaping logic. I’ll inspect both, app mounting, schema, and representative route tests. - Assistant
The current handler confirms the reported behavior: it filters enabled/key-backed rows before deduplication and emits no availability fields. Before changing it, I’ll verify the shared row type and exact key matching rules used by the router—especially custom-provider
key_idand potentially keyless platforms—so endpoint availability mirrors actual usability. - Assistant
Provider metadata includes
keyless, so availability cannot be expressed by SQL key existence alone. I’ll inspect routing candidate/key synthesis to determine whether keyless catalog rows should be marked available (the issue’s wording says “matching enabled key exists,” but “usable” and router behavior may treat synthetic keyless entries specially). - Assistant
The router uses enabled key rows (including sentinel rows for keyless providers), while
/v1/modelsintentionally has a simpler “connected” definition than live cooldown/health. I’ll implement availability in the catalog query, deduplicate after computing it, prioritize states as available → enabled/no-key → disabled, annotateauto, and treat either exactavailable=trueorconnected=trueas the opt-in filter. I’ll first check query-boolean conventions and TypeScript settings, then edit only production code. - Assistant
Before editing, I’ll reproduce the reported default behavior against an in-memory migrated database with no provider keys. The temporary script will live outside the repository and verify that the current endpoint returns only
auto, despite the seeded catalog. - Assistant
The reproduction script hit a module-format limitation rather than application behavior. I’ll wrap it in an async function and rerun.
- Assistant
Python is unavailable in this environment, so I’ll rewrite the small temporary script directly with an async
main. - Assistant
The reproduction confirms 110 catalog rows collapse to only
autowith no keys. I’ll now replace the pre-filtering query with state computation followed by availability-aware deduplication, add both query aliases, and emit the required fields. - Assistant
The core change is in place. I’ll compile the server and rerun the endpoint reproduction for default,
available=true, andconnected=true, checking uniqueness and annotation consistency. - Assistant
Compilation passes and default now returns all 106 unique catalog IDs plus
auto; both filters preserve the prior no-key result. I’ll exercise edge cases in a temporary script: matching enabled keys, disabled keys, duplicate model IDs across platforms, disabled rows, and custom models bound to a specific key. This validates both reason precedence and dedup preference without adding repository tests. - Assistant
I’ll construct isolated synthetic rows and make assertions through the HTTP endpoint, including that an available lower-ranked duplicate beats a disabled/higher-ranked one and that custom
key_idmatching is enforced. - Assistant
All synthetic edge-case assertions pass. I’ll search existing tests for
/v1/modelsassumptions, run the route/integration suites most likely affected, then run the full server test suite. - Assistant
The direct Vitest invocation used the repository root while the config’s include pattern is server-relative, so it found no tests. I also found an existing dedicated
/v1/modelstest file; I’ll inspect it and invoke Vitest from the server workspace. - Assistant
All 23 route/integration files (180 tests), including the existing
/v1/modelstests, pass. I’ll clean up the now-inaccurate endpoint comment, then run the complete server suite and inspect the final diff/status for unintended generated files. - Assistant
The full server suite passes: 46 files and 456 tests. I’ll perform final hygiene checks (
git status, whitespace diff check, final diff), and verify no temporary files or build artifacts are tracked. - Assistant
Final review is clean: only
server/src/routes/proxy.tschanged, andgit diff --checkreports no whitespace errors.Checklist:
- If an error was reported in the issue description, I have successfully reproduced it. This was a behavioral defect rather than a thrown error; with 110 catalog rows and no keys, the old default
/v1/modelsresponse returned onlyauto. - If an error was reported in the issue description, I have confirmed that my fix resolves the error. The same setup now returns 106 unique catalog model IDs plus
auto, with required availability annotations; both?available=trueand?connected=truereturn only available entries. - I have thought about edge cases and made sure my fix handles them as well. Temporary HTTP assertions covered available-vs-disabled duplicate preference,
disabledandno_keyreasons, disabled keys, custom-model key binding, uniqueness, both filter aliases, and always-availableauto. - I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Server TypeScript compilation passed; route/integration tests passed (23 files, 180 tests); the complete server suite passed (46 files, 456 tests). No tests were modified or added.
I’m satisfied that the implementation meets the requested behavior, so I’ll submit the single production-code change.
- If an error was reported in the issue description, I have successfully reproduced it. This was a behavioral defect rather than a thrown error; with 110 catalog rows and no keys, the old default
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-lunaCompare side by side →