Browse Source

fix(03-01): add capabilities filtering to /api/models endpoint

UAT-005: Video models were showing in image-only dropdown because
the API wasn't filtering by capabilities param. Now filters results
based on ?capabilities=text-to-image,image-to-image query param.

UAT-004: Replicate shows first page only (~25 models) - this is
expected API behavior. Full pagination can be added later.
handoff-20260429-1057
shrimbly 6 months ago
parent
commit
f2895c3ff3
  1. 21
      src/app/api/models/route.ts

21
src/app/api/models/route.ts

@ -281,6 +281,10 @@ export async function GET(
| null;
const searchQuery = request.nextUrl.searchParams.get("search") || undefined;
const refresh = request.nextUrl.searchParams.get("refresh") === "true";
const capabilitiesParam = request.nextUrl.searchParams.get("capabilities");
const capabilitiesFilter: ModelCapability[] | null = capabilitiesParam
? (capabilitiesParam.split(",") as ModelCapability[])
: null;
// Get API keys from headers
const replicateKey = request.headers.get("X-Replicate-Key");
@ -403,8 +407,19 @@ export async function GET(
);
}
// Filter by capabilities if specified
let filteredModels = allModels;
if (capabilitiesFilter && capabilitiesFilter.length > 0) {
filteredModels = allModels.filter((model) =>
model.capabilities.some((cap) => capabilitiesFilter.includes(cap))
);
console.log(
`[Models:${requestId}] Filtered to ${filteredModels.length} models with capabilities: ${capabilitiesFilter.join(", ")}`
);
}
// Sort models by provider, then by name
allModels.sort((a, b) => {
filteredModels.sort((a, b) => {
if (a.provider !== b.provider) {
return a.provider.localeCompare(b.provider);
}
@ -412,12 +427,12 @@ export async function GET(
});
console.log(
`[Models:${requestId}] Returning ${allModels.length} models from ${Object.keys(providerResults).length} providers`
`[Models:${requestId}] Returning ${filteredModels.length} models from ${Object.keys(providerResults).length} providers`
);
const response: ModelsSuccessResponse = {
success: true,
models: allModels,
models: filteredModels,
cached: anyFromCache && allFromCache,
providers: providerResults,
};

Loading…
Cancel
Save