apps/docs/OPENAPI_CACHE.md
The Vercel build was failing with timeout errors when trying to fetch the OpenAPI specification from https://api.prisma.io/v1/doc during the static site generation phase:
docs:build: Error occurred prerendering page "/management-api/endpoints/database-usage/get-databases-id-usage". Read more: https://nextjs.org/docs/messages/prerender-error
docs:build: TypeError: fetch failed
docs:build: [cause]: AggregateError:
docs:build: at ignore-listed frames {
docs:build: code: 'ETIMEDOUT'
docs:build: }
The issue occurred because:
output: "export" statically generates all pages at build timeWe implemented a three-layer caching strategy:
scripts/fetch-openapi.ts)cache/openapi.jsoncache/openapi.json file is checked first during buildssrc/lib/openapi.ts)pnpm build
→ turbo build
→ docs#build
→ fetch-openapi script (fetches & caches to file)
→ next build (reads from cache file, stores in memory)
→ All API pages use in-memory cache
scripts/fetch-openapi.ts: Pre-build script that fetches and caches the specsrc/lib/openapi.ts: Main OpenAPI integration with caching logiccache/openapi.json: Cached OpenAPI specification (gitignored)Both the pre-build script and runtime fetch include:
The cache is automatically regenerated on every build via the fetch-openapi script. No manual cache invalidation is needed.
If the API structure changes, simply run a new build to refresh the cache.
To test the caching behavior:
# Clean build (fetches spec fresh)
rm -rf apps/docs/cache apps/docs/.next
pnpm build
# Subsequent build (uses cached spec)
pnpm build
You should see: