{"record":{"id":"414b32026165ec7a","repo":"vercel/next.js","slug":"url-parameter-is-valid-but-upstream-response-is","errorCode":null,"errorMessage":"\"url\" parameter is valid but upstream response is invalid","messagePattern":"\"url\" parameter is valid but upstream response is invalid","errorType":"http","errorClass":"ImageError","httpStatus":508,"severity":"error","filePath":"packages/next/src/server/image-optimizer.ts","lineNumber":575,"sourceCode":"    if (err.name === 'TimeoutError') {\n      Log.error('upstream image response timed out for', href)\n      throw new ImageError(\n        504,\n        '\"url\" parameter is valid but upstream response timed out'\n      )\n    }\n    throw err\n  }\n\n  const locationHeader = res.headers.get('Location')\n  if (\n    isRedirect(res.status) &&\n    locationHeader &&\n    URL.canParse(locationHeader, href)\n  ) {\n    if (count === 0) {\n      Log.error('upstream image response had too many redirects', href)\n      throw new ImageError(\n        508,\n        '\"url\" parameter is valid but upstream response is invalid'\n      )\n    }\n    const redirect = new URL(locationHeader, href).href\n    return fetchExternalImage(\n      redirect,\n      dangerouslyAllowLocalIP,\n      maximumResponseBody,\n      count - 1\n    )\n  }\n\n  if (!res.ok) {\n    Log.error('upstream image response failed for', href, res.status)\n    throw new ImageError(\n      res.status,\n      '\"url\" parameter is valid but upstream response is invalid'","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/vercel/next.js/blob/996f957c060aa17957a166216c69565c72996f4a/packages/next/src/server/image-optimizer.ts#L557-L593","documentation":"Redirect-loop guard in fetchExternalImage: the upstream response was a redirect whose Location could still be parsed, but the redirect budget (count) was exhausted — too many redirects. Continuing would loop forever, so the optimizer gives up and throws ImageError 508 declaring the upstream response invalid.","triggerScenarios":"The upstream image response is not valid.","commonSituations":"The remote server returns a non-200 status or bad content for an optimized image.","solutions":["Verify the upstream URL returns a valid image response (correct status and content-type)."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"996f957c060aa17957a166216c69565c72996f4a","analyzedAt":"2026-08-19T02:10:13.922Z","contentChangedAt":"2026-08-19T02:10:13.922Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}