{"record":{"id":"d6b0462813364cc2","repo":"nexu-io/open-design","slug":"openai-image-fetch-imgresp-status","errorCode":null,"errorMessage":"openai image fetch ${imgResp.status}","messagePattern":"openai image fetch (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":968,"sourceCode":"  const text = await resp.text();\n  if (!resp.ok) {\n    const tag = azure ? 'azure-openai' : 'openai';\n    throw new Error(`${tag} ${resp.status}: ${truncate(text, 240)}`);\n  }\n  let data: any;\n  try {\n    data = JSON.parse(text);\n  } catch {\n    throw new Error(`openai non-JSON response: ${truncate(text, 200)}`);\n  }\n  const entry = data && Array.isArray(data.data) ? data.data[0] : null;\n  if (!entry) throw new Error('openai response had no data[0]');\n  let bytes;\n  if (entry.b64_json) {\n    bytes = Buffer.from(entry.b64_json, 'base64');\n  } else if (entry.url) {\n    const imgResp = await fetch(entry.url, withMediaRequestInit(ctx));\n    if (!imgResp.ok) throw new Error(`openai image fetch ${imgResp.status}`);\n    const arr = await imgResp.arrayBuffer();\n    bytes = Buffer.from(arr);\n  } else {\n    throw new Error('openai response had neither b64_json nor url');\n  }\n\n  const tag = azure ? 'azure-openai' : 'openai';\n  return {\n    bytes,\n    providerNote: `${tag}/${ctx.wireModel} · ${ctx.aspect} · ${bytes.length} bytes`,\n    suggestedExt: '.png',\n  };\n}\n\nasync function renderImageRouterImage(ctx: MediaContext, credentials: ProviderConfig): Promise<RenderResult> {\n  if (!credentials.apiKey) {\n    throw new Error(\n      'no ImageRouter API key — configure it in Settings or set OD_IMAGEROUTER_API_KEY',","sourceCodeStart":950,"sourceCodeEnd":986,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L950-L986","documentation":"Thrown by renderOpenAIImage when the response carried entry.url instead of b64_json and the secondary fetch of that URL returned a non-2xx status. OpenAI/Azure sometimes return a hosted image URL instead of inline bytes; the daemon downloads it before writing to disk, and a failure here means that download step broke, not the generation itself.","triggerScenarios":"OpenAI returns a signed url that expired before the follow-up fetch; the hosted-image CDN returns 403/404; a network egress filter blocks the image CDN host while allowing api.openai.com; corporate proxy allows the API but blocks the blob storage host.","commonSituations":"Long latency between generation and download causing URL expiry; restrictive egress firewall; transient CDN 5xx; signed-URL region mismatch.","solutions":["Retry the request — signed URL fetches are often transient.","Request b64_json output instead of url if the integration supports it (forces inline bytes, no second fetch).","Allowlist the OpenAI image CDN host (e.g. *.blob.core.windows.net for Azure, files.oaiusercontent.com for OpenAI) in egress rules.","Check for clock skew on the daemon host — signed URLs validate against the upstream server clock."],"exampleFix":"// before: response_format defaults to url and CDN is blocked\n// after: pin response_format to b64_json in your custom integration path\nbody.response_format = 'b64_json';","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await renderOpenAIImage(ctx, credentials);\n} catch (err) {\n  const m = err instanceof Error ? err.message : '';\n  if (m.startsWith('openai image fetch ')) {\n    // signed-URL download failed; retry once, then suggest b64_json\n    await sleep(backoffMs);\n    return await renderOpenAIImage(ctx, credentials);\n  }\n  throw err;\n}","preventionTips":["Prefer response_format=b64_json where the integration supports it to skip the secondary fetch.","Allowlist the OpenAI blob CDN hosts (*.blob.core.windows.net, files.oaiusercontent.com) in egress rules.","Keep daemon host clock synced (NTP) to avoid signed-URL skew."],"tags":["network","media","openai","secondary-fetch","cdn"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}