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 first inspect the repository structure and locate the
/v1/modelsroute, model schemas, and relevant tests. Then I’ll reproduce the current filtering behavior, implement availability annotation and query filtering with careful deduplication, and run targeted plus broader tests. - Assistant
The implementation is in
server/src/routes/proxy.ts, with route tests underserver/src/__tests__/routes. I’ll inspect the route, database access methods/types, and test setup to understand row shape, key matching, ordering, and current deduplication semantics before changing code. - Assistant
The current SQL confirms the issue: it excludes disabled/keyless rows before deduplication. The fix should compute availability for every catalog row first, rank duplicate IDs by availability before existing intelligence/id ordering, and optionally filter the deduplicated result. I’ll inspect schema/type definitions and Express query conventions, then use a temporary reproduction script (not a test file) against the app to capture current default and filtered behavior.
- Assistant
ModelListRowcurrently lacks availability fields, so I’ll extend it rather than use an unsafe local cast. A key nuance is whether any providers are intentionally keyless: the current availability definition explicitly requires an enabled matching key, and existing key-management likely creates sentinel key rows for keyless providers. I’ll verify the schema and seed behavior, then run a one-off script that initializes an in-memory catalog with no keys and requests/v1/models. - Assistant
The initial reproduction script hit a tooling-format issue (top-level await from
/tmpwas compiled as CommonJS), not an application failure. I’ll wrap it in an async function and rerun. After that, I’ll implement a CTE that computes availability per row, deduplicates withavailable DESC, and then applies the opt-in filter in TypeScript. Filtering after dedup keeps semantics clear;autoremains present and available under every mode. - Assistant
Reproduction succeeded: with a 25-row catalog and no keys, the default incorrectly returns only
auto, and both query parameters currently have no special behavior. I’ll now update the shared database-row type and route. For duplicate unavailable rows, existing intelligence/id ordering is preserved; the explicitly required availability preference is added ahead of it. The selected row’s reason isdisabledwhen disabled, otherwiseno_key. - Assistant
The compiler caught that my line-range replacement accidentally removed the adjacent
MAX_RETRIESdeclaration; the diff makes this clear and no other logic was affected. I’ll restore it, then rerun the build and the reproduction with stronger assertions for catalog size, annotations, aliases, and disabled versus keyless reasons. - Assistant
The fixed reproduction now returns all 106 distinct catalog IDs plus
autoby default, with bothdisabledandno_keyreasons; each opt-in alias returns onlyautowhen no keys exist. Build passes. Next I’ll run the existing route tests, then use a temporary integration script to validate enabled-key availability and duplicate preference (including an available duplicate losing on rank but still being selected). - Assistant
The existing
/v1/modelsandautoroute tests all pass. I’ll now exercise the dedup edge case in-memory by repurposing two catalog rows: a higher-ranked disabled instance and a lower-ranked enabled instance with a matching enabled key. I’ll also verify disabling that key changes the deduplicated annotation tono_keyand causes both filters to exclude the ID. - Assistant
The edge-case script selected two rows from the same platform, so changing both IDs correctly triggered the schema’s
(platform, model_id)uniqueness constraint; this is a script setup error, not route behavior. I’ll rerun selecting rows from distinct platforms, then inspect final diff and run the full server test suite. - Assistant
All 456 server tests pass, and the temporary duplicate check confirms an available instance wins over a better-ranked disabled instance; when the key is disabled, the ID is annotated unavailable and excluded by both aliases.
Before submission, I’ll do one final diff/status review and verify no temporary files or generated artifacts remain.
- Assistant
Final review shows only the intended source/type changes and no whitespace errors or artifacts. The minor surrounding blank-line normalization is harmless.
Checklist:
- If an error was reported in the issue description, I have successfully reproduced it. With 106 distinct catalog IDs and no keys, the old endpoint returned only the virtual
automodel. - If an error was reported in the issue description, I have confirmed that my fix resolves the error. The default now returned
autoplus all 106 IDs with boolean availability and valid reasons; both opt-in aliases returned only available entries. - I have thought about edge cases and made sure my fix handles them as well. I verified disabled versus keyless annotations, disabled keys, both filter aliases, unique IDs,
autoalways available, key matching, and availability-first deduplication across duplicate model IDs. - I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. TypeScript build passed, targeted route tests passed (5/5), and the complete server suite passed (456/456).
I’m satisfied the implementation meets the requested behavior and will submit it now.
- If an error was reported in the issue description, I have successfully reproduced it. With 106 distinct catalog IDs and no keys, the old endpoint returned only the virtual
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 →