fix(ai-gateway): set maxDuration on /api/gateway/[...path] route - #4758
Merged
Conversation
The gateway route re-exports POST from the openrouter catch-all route, but Next.js route segment config is not inherited through a handler re-export. Without its own maxDuration export, /api/gateway/* fell back to the Vercel plan default instead of the 1800s the identical /api/openrouter/* handler gets, so long-running streaming requests through /api/gateway timed out early. Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe new commit only removes the explanatory comment above Files Reviewed (1 files)
Previous Review Summary (commit 7df82b8)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 7df82b8)Status: No Issues Found | Recommendation: Merge Executive SummarySingle-line config addition correctly mirrors the Files Reviewed (1 files)
Reviewed by claude-sonnet-5 · Input: 20 · Output: 2.8K · Cached: 389K Review guidance: REVIEW.md from base branch |
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
lambertjosh
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
api/gateway/[...path]/route.tsre-exportsPOSTfrom the openrouter catch-all route, but Next.js route segment config is not inherited through a handler re-export — it must be exported from the route's own file. Without its ownmaxDurationexport,/api/gateway/*fell back to the Vercel plan default (60s Hobby / 300s Pro) instead of the 1800s that the identical/api/openrouter/*handler gets, so long-running streaming requests through/api/gatewaytimed out early.The fix adds
export const maxDuration = 1800;to the gateway route file, matchingapi/openrouter/[...path]/route.ts.Why not re-export
maxDurationtoo?export { POST, maxDuration } from '...'does not work for route segment config. Next.js extracts segment config at build time via static SWC analysis (extractExportedConstValueinnext/dist/build/analysis/extract-const-value.js), which only matches anExportDeclarationcontaining aconstvariable with a literal initializer — i.e.export const maxDuration = 1800written directly in the route file itself. A re-export parses as anExportNamedDeclaration, which the extractor skips, so the value is silently ignored. Vercel then derives the function timeout from Next.js's build-time functions config manifest, so a re-export that is perfectly valid at runtime never reaches the deployed function configuration and the route falls back to the plan default. Verified against the installed Next.js 16.2.6.Verification
validatePathalready accepts both/api/gatewayand/api/openrouterprefixes, confirming these paths are intended aliases of the same handler.Visual Changes
N/A