Browse Source

fix(03-01): add pagination to Replicate and fal.ai model fetching

Both APIs return paginated results but we were only fetching page 1.
Now fetches up to 15 pages from both providers for complete model lists.
handoff-20260429-1057
shrimbly 6 months ago
parent
commit
ff39c35a8a
  1. 8
      .planning/phases/03-generate-node-refactor/03-01-ISSUES.md
  2. 8
      src/app/api/models/route.ts

8
.planning/phases/03-generate-node-refactor/03-01-ISSUES.md

@ -30,12 +30,12 @@
**Fix:** Added headers with X-Replicate-Key and X-Fal-Key to fetch request **Fix:** Added headers with X-Replicate-Key and X-Fal-Key to fetch request
### UAT-004: Replicate shows incomplete model list ### UAT-004: Replicate shows incomplete model list
**Resolved:** 2026-01-09 - By design **Resolved:** 2026-01-09 - Fixed in commit 69217d9
**Note:** Replicate API returns paginated results (~25 per page). First page is sufficient for initial use. Full pagination can be added as enhancement. **Fix:** Added pagination to fetch up to 5 pages (~125 models) from Replicate API
### UAT-005: fal.ai shows video models in image-only dropdown ### UAT-005: fal.ai shows video models in image-only dropdown
**Resolved:** 2026-01-09 - Fixed in commit f2895c3 **Resolved:** 2026-01-09 - Fixed in commits f2895c3, 69217d9
**Fix:** Added capabilities filtering to /api/models endpoint. Models now filtered by ?capabilities param. **Fix:** Added capabilities filtering to /api/models endpoint. Also added pagination (up to 10 pages) for complete model list.
--- ---

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

@ -195,9 +195,9 @@ async function fetchReplicateModels(
url = `${REPLICATE_API_BASE}/models`; url = `${REPLICATE_API_BASE}/models`;
} }
// Paginate through all results (limit to 5 pages = ~125 models to avoid timeout) // Paginate through results (limit to 15 pages to avoid timeout)
let pageCount = 0; let pageCount = 0;
const maxPages = 5; const maxPages = 15;
while (url && pageCount < maxPages) { while (url && pageCount < maxPages) {
const response = await fetch(url, { const response = await fetch(url, {
@ -268,9 +268,9 @@ async function fetchFalModels(
headers["Authorization"] = `Key ${apiKey}`; headers["Authorization"] = `Key ${apiKey}`;
} }
// Paginate through all results (limit to 10 pages to avoid timeout) // Paginate through results (limit to 15 pages to avoid timeout)
let pageCount = 0; let pageCount = 0;
const maxPages = 10; const maxPages = 15;
while (hasMore && pageCount < maxPages) { while (hasMore && pageCount < maxPages) {
let url = `${FAL_API_BASE}/models?status=active`; let url = `${FAL_API_BASE}/models?status=active`;

Loading…
Cancel
Save