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 current implementation of the
/v1/modelsendpoint. I need to:- Explore the repository structure
- Find the current implementation of
GET /v1/models - Understand how models are currently returned
- Implement the changes as described in the issue
Let me begin by exploring the repository.
Assistant
Let me look at the current models route implementation:
Assistant
Now let me understand the current behavior better. Let me look at the tests for this route and related files:
Assistant
I don't see a models.test.ts file. Let me check the integration tests and also look at related files:
Assistant
Now let me look at how the
/v1/modelsroute is currently set up and what the old behavior was. Let me also look at the app.ts to understand the routing:Assistant
Now I see that
/v1/modelsis served by theproxyRouter. Let me look at the proxy router to understand how/v1/modelsis handled:Assistant
Now I understand the current behavior. The
/v1/modelsendpoint only returns models that are:- Enabled (
m.enabled = 1) - Have an enabled API key that can serve them
Let me also look at the
hasProviderfunction and understand the providers:- Enabled (
Assistant
Now let me look at the db module to understand the database schema and the
AUTO_MODEL_IDconstant:Assistant
Now let me check the database schema to understand the models table structure:
Assistant
Now I have a good understanding of the codebase. Let me also look at what the
shareddirectory has and check for any type definitions:Assistant
Now let me run the existing tests to understand the current behavior and make sure they pass:
Assistant
All 456 tests pass. Now I understand the full picture. Let me also look at the
ModelListRowtype used in the proxy.ts file:Assistant
Now I have a full understanding of the codebase. Let me create a plan:
Plan
The issue asks to modify
GET /v1/modelsto:-
By default, return the whole catalog (one entry per model id), each annotated with:
available: boolean — enabled AND a matching enabled key existsunavailable_reason:null|"no_key"(enabled, no key) |"disabled"(catalog row disabled)
-
Opt-in filter:
?available=true(alias?connected=true) → only connected models (the previous default behavior) -
Dedup: prefers an available instance of a model id over a disabled/keyless one
-
The
autovirtual model is alwaysavailable: true
Now let me implement the changes in
/freellmapi/server/src/routes/proxy.ts:-
Assistant
Now let me see the full current implementation of the
/v1/modelsendpoint:Assistant
Now I understand the current implementation. Let me implement the changes. I need to:
- Query ALL models from the catalog (not just enabled ones with keys)
- For each model, determine if it's available (enabled AND has a matching enabled key)
- Determine the
unavailable_reasonif not available - Deduplicate by
model_id, preferring available instances over disabled/keyless ones - Add
availableandunavailable_reasonfields - Support
?available=trueand?connected=truequery params to filter to only available models - Always include
autoasavailable: true
Let me write the updated implementation:
Assistant
Now I'll replace the
/v1/modelsendpoint with the new implementation:Assistant
Let me use the replace command instead:
Assistant
The replacement looks good. Let me verify the rest of the edited section:
Assistant
The replacement looks correct. Now let me run the tests to verify the changes work:
Assistant
All 456 tests still pass. Now let me write a quick test script to verify the new behavior works correctly:
Assistant
The test file needs to be in the right location. Let me run the test differently:
Assistant
Let me fix the import paths:
Assistant
The test failure is in my test logic - some models in the catalog are already disabled (like
gemini-2.5-pro), so theirunavailable_reasonis"disabled"rather than"no_key". This is actually correct behavior! The test was just wrong - it expected ALL unavailable models to haveno_keybut some havedisabled. Let me fix my test:Assistant
All 7 tests pass. Now let me clean up by removing the test file (since I was told not to add tests to the repository):
Assistant
Now let me run the full test suite to make sure all existing tests still pass:
Assistant
Let me check if the
ModelListRowimport is still needed after my changes:Assistant
The
ModelListRowtype is no longer used after my changes. Let me clean up the import:Assistant
I need to verify that the import change didn't break anything by running the tests again. Let me run the test suite to confirm everything still works.
Assistant
All 456 tests pass. Let me review the final changes I made:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.