{"record":{"id":"07bad45471ca93e6","repo":"vercel/next.js","slug":"invalid-redirect-arguments-please-use-a-single-ar","errorCode":null,"errorMessage":"Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').","messagePattern":"Invalid redirect arguments\\. Please use a single argument URL, e\\.g\\. res\\.redirect\\('/destination'\\) or use a status code and URL, e\\.g\\. res\\.redirect\\(307, '/destination'\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/api-utils/index.ts","lineNumber":68,"sourceCode":"}\n\n/**\n *\n * @param res response object\n * @param [statusOrUrl] `HTTP` status code of redirect\n * @param url URL of redirect\n */\nexport function redirect(\n  res: NextApiResponse,\n  statusOrUrl: string | number,\n  url?: string\n): NextApiResponse<any> {\n  if (typeof statusOrUrl === 'string') {\n    url = statusOrUrl\n    statusOrUrl = 307\n  }\n  if (typeof statusOrUrl !== 'number' || typeof url !== 'string') {\n    throw new Error(\n      `Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`\n    )\n  }\n  res.writeHead(statusOrUrl, { Location: url })\n  res.write(url)\n  res.end()\n  return res\n}\n\nexport function checkIsOnDemandRevalidate(\n  rawHeaders: Headers | IncomingHttpHeaders,\n  previewProps: __ApiPreviewProps\n): {\n  isOnDemandRevalidate: boolean\n  revalidateOnlyGenerated: boolean\n} {\n  // Headers is a plain object for Node.js, Headers object in Edge runtime\n  if (typeof rawHeaders.get === 'function') {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/api-utils/index.ts#L50-L86","documentation":"Thrown by redirect() (wired to res.redirect in API routes) when the arguments do not match the two accepted signatures: a single string URL, or a numeric status code plus a string URL. This protects against ambiguous calls and ensures a valid HTTP redirect is emitted.","triggerScenarios":"Calling res.redirect() with no arguments, with two strings, with a non-number/non-string mix, or with a status that isn't a number. The check at line 67 fails when statusOrUrl isn't a number or url isn't a string after the single-string normalization.","commonSituations":"Passing res.redirect(url, status) in the wrong order (a common mistake from Express differences); calling res.redirect(200); res.redirect(undefined); or res.redirect(status, url) where status came in as a string.","solutions":["Use res.redirect('/destination') for a default 307 redirect.","Use res.redirect(307, '/destination') — number first, then string URL.","Ensure the status code is a number (not a string) and the URL is a string."],"exampleFix":"// before\nres.redirect('/dest', 307) // wrong order\nres.redirect(307)        // missing url\n// after\nres.redirect('/dest')\nres.redirect(307, '/dest')","handlingStrategy":"type-guard","validationCode":"function safeRedirect(res: any, statusOrUrl: string | number, url?: string) {\n  if (typeof statusOrUrl === 'string') { res.redirect(statusOrUrl); return }\n  if (typeof statusOrUrl === 'number' && typeof url === 'string') { res.redirect(statusOrUrl, url); return }\n  throw new Error('Invalid redirect arguments')\n}","typeGuard":"function isValidRedirectArgs(statusOrUrl: unknown, url?: unknown): boolean {\n  if (typeof statusOrUrl === 'string' && url === undefined) return true\n  if (typeof statusOrUrl === 'number' && typeof url === 'string') return true\n  return false\n}","tryCatchPattern":null,"preventionTips":["Use res.redirect('/path') or res.redirect(307, '/path') — number first.","Do not pass two strings or reversed argument order.","Ensure status codes are numbers, not strings."],"tags":["api-routes","redirect","runtime","validation"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}