{"record":{"id":"f4d1019838aafdb1","repo":"nexu-io/open-design","slug":"providertag-media-fetch-mediaresp-status","errorCode":null,"errorMessage":"${providerTag} media fetch ${mediaResp.status}","messagePattern":"(.+?) media fetch (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":1149,"sourceCode":"    return JSON.parse(text);\n  } catch {\n    throw new Error(`${providerTag} non-JSON response: ${truncate(text, 200)}`);\n  }\n}\n\nasync function bytesFromOpenAICompatibleData(data: any, providerTag: string, requestInit: MediaRequestInit = {}): Promise<Buffer> {\n  const entry = data && Array.isArray(data.data) ? data.data[0] : null;\n  if (!entry) throw new Error(`${providerTag} response had no data[0]`);\n  if (typeof entry.b64_json === 'string' && entry.b64_json) {\n    const raw = entry.b64_json.includes(',')\n      ? entry.b64_json.slice(entry.b64_json.indexOf(',') + 1)\n      : entry.b64_json;\n    return Buffer.from(raw, 'base64');\n  }\n  if (typeof entry.url === 'string' && entry.url) {\n    const mediaResp = await fetch(entry.url, requestInit);\n    if (!mediaResp.ok) {\n      throw new Error(`${providerTag} media fetch ${mediaResp.status}`);\n    }\n    const arr = await mediaResp.arrayBuffer();\n    return Buffer.from(arr);\n  }\n  throw new Error(`${providerTag} response had neither b64_json nor url`);\n}\n\nfunction imageRouterSizeFor(aspect: string | undefined, surface: 'image' | 'video'): string {\n  if (surface === 'video') {\n    if (aspect === '1:1') return '1024x1024';\n    if (aspect === '9:16') return '576x1024';\n    if (aspect === '4:3') return '1024x768';\n    if (aspect === '3:4') return '768x1024';\n    return '1024x576';\n  }\n  if (aspect === '16:9') return '1024x576';\n  if (aspect === '9:16') return '576x1024';\n  if (aspect === '4:3') return '1024x768';","sourceCodeStart":1131,"sourceCodeEnd":1167,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L1131-L1167","documentation":"Thrown by bytesFromOpenAICompatibleData when the entry carries entry.url and the follow-up fetch of that URL returns non-2xx. Mirrors the first-party 'openai image fetch' path but applies to any OpenAI-compatible gateway that chooses url-style responses over inline b64_json.","triggerScenarios":"Gateway returns a short-lived signed URL that expires before download; the gateway's blob host is unreachable from the daemon host; CDN rate-limiting on the secondary fetch.","commonSituations":"High-latency link causing URL expiry; egress firewall allows the API host but blocks the blob host; gateway returns URLs to a private network.","solutions":["Retry — signed-URL fetch failures are often transient.","Prefer a gateway/model configuration that returns b64_json inline so no secondary fetch is needed.","Allowlist the gateway's blob/CDN host in egress rules.","If the gateway exposes a 'response_format=b64_json' option, set it."],"exampleFix":"// before: gateway returns url, blob host blocked\n// after: force b64_json via the gateway's request option (renderer config)\nbody.response_format = 'b64_json';","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await bytesFromOpenAICompatibleData(data, providerTag, requestInit);\n} catch (err) {\n  const m = err instanceof Error ? err.message : '';\n  if (m.endsWith('media fetch ')) {\n    // signed-URL download failed — retry once, then prefer b64_json\n    await sleep(backoffMs);\n    return await bytesFromOpenAICompatibleData(data, providerTag, requestInit);\n  }\n  throw err;\n}","preventionTips":["Prefer gateways/models that return b64_json inline to avoid the secondary fetch entirely.","Allowlist the gateway's blob/CDN host in egress rules.","Treat signed-URL fetch failures as transient — retry before escalating."],"tags":["network","media","openai-compatible","secondary-fetch","cdn","imagerouter"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}