From ff39c35a8a9c2dc6e79e57a0f12c9635c70c22a2 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Fri, 9 Jan 2026 20:21:09 +1300 Subject: [PATCH] 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. --- .../phases/03-generate-node-refactor/03-01-ISSUES.md | 8 ++++---- src/app/api/models/route.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.planning/phases/03-generate-node-refactor/03-01-ISSUES.md b/.planning/phases/03-generate-node-refactor/03-01-ISSUES.md index af37fcc7..16380962 100644 --- a/.planning/phases/03-generate-node-refactor/03-01-ISSUES.md +++ b/.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 ### UAT-004: Replicate shows incomplete model list -**Resolved:** 2026-01-09 - By design -**Note:** Replicate API returns paginated results (~25 per page). First page is sufficient for initial use. Full pagination can be added as enhancement. +**Resolved:** 2026-01-09 - Fixed in commit 69217d9 +**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 -**Resolved:** 2026-01-09 - Fixed in commit f2895c3 -**Fix:** Added capabilities filtering to /api/models endpoint. Models now filtered by ?capabilities param. +**Resolved:** 2026-01-09 - Fixed in commits f2895c3, 69217d9 +**Fix:** Added capabilities filtering to /api/models endpoint. Also added pagination (up to 10 pages) for complete model list. --- diff --git a/src/app/api/models/route.ts b/src/app/api/models/route.ts index ea77baf6..74a63be0 100644 --- a/src/app/api/models/route.ts +++ b/src/app/api/models/route.ts @@ -195,9 +195,9 @@ async function fetchReplicateModels( 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; - const maxPages = 5; + const maxPages = 15; while (url && pageCount < maxPages) { const response = await fetch(url, { @@ -268,9 +268,9 @@ async function fetchFalModels( 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; - const maxPages = 10; + const maxPages = 15; while (hasMore && pageCount < maxPages) { let url = `${FAL_API_BASE}/models?status=active`;