From 20ee940797f8c599a40ffa62e627abe9d7d8280b Mon Sep 17 00:00:00 2001 From: Michael Feng Date: Sat, 30 May 2026 22:28:14 +1000 Subject: [PATCH] fix: raise analyze proxy timeout to 60s for Render free-tier cold start The /api/analyze proxy aborted at 10s, but the Render free instance sleeps after idle and cold-starts in ~30-50s, so the first request after idle 502'd ('ML API timeout'). Bump default to 60s (override via ML_API_TIMEOUT_MS). Co-Authored-By: Claude Opus 4.8 (1M context) --- app/api/analyze/route.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/api/analyze/route.ts b/app/api/analyze/route.ts index 718a409..3d69859 100644 --- a/app/api/analyze/route.ts +++ b/app/api/analyze/route.ts @@ -3,7 +3,10 @@ import { NextRequest, NextResponse } from 'next/server' import { AnalyzeRequest, AnalyzeResponse } from '@/types/analyze' import { enforceRateLimit } from '@/lib/ratelimit' -const DEFAULT_TIMEOUT_MS = 10000 +// The ML API runs on Render's free tier, which sleeps after ~15 min idle and +// takes ~30–50s to cold-start. Allow enough headroom so the first request after +// idle succeeds (slowly) instead of 502-ing. Override via ML_API_TIMEOUT_MS. +const DEFAULT_TIMEOUT_MS = Number(process.env.ML_API_TIMEOUT_MS) || 60000 const ML_API_URL = process.env.ML_API_URL || 'http://localhost:8000' export async function POST(req: NextRequest) {