{"record":{"id":"7a5a3639c56ba6a4","repo":"nexu-io/open-design","slug":"openai-response-had-no-data-0","errorCode":null,"errorMessage":"openai response had no data[0]","messagePattern":"openai response had no data\\[0\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":962,"sourceCode":"    headers,\n    body: JSON.stringify(body),\n    dispatcher: ctx.requestInit.dispatcher\n      ?? openAIImageDispatcher as unknown as NonNullable<RequestInit['dispatcher']>,\n    signal: AbortSignal.timeout(Math.max(OPENAI_IMAGE_HEADERS_TIMEOUT_MS, OPENAI_IMAGE_BODY_TIMEOUT_MS)),\n  }));\n  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  };","sourceCodeStart":944,"sourceCodeEnd":980,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L944-L980","documentation":"Thrown by renderOpenAIImage after JSON parsed successfully but data is missing or data[0] is null/undefined. The OpenAI image response contract is {data:[{b64_json|url,...}]}; an empty array or absent data field means the upstream returned an unexpected (but JSON) shape, e.g. an error envelope with a 200 status or a different API version.","triggerScenarios":"Upstream returned {error:...} with HTTP 200 (misconfigured gateway); pointing baseUrl at /v1/chat/completions by mistake (different schema); API version skew where OpenAI/Azure changed the envelope; a transparent gateway that wraps responses.","commonSituations":"BaseUrl pointing at a chat completions endpoint; Azure API-version query string missing so a different schema is returned; using an OpenAI-compatible shim that omits the data array.","solutions":["Log the full parsed JSON (the error only says data[0] is missing) to see what envelope was actually returned.","Confirm baseUrl targets the images endpoint host (the path /images/generations is appended by buildOpenAIImageUrl).","For Azure, ensure the deployment URL includes the api-version query parameter expected by Azure.","Switch to a model id the upstream actually serves for image generation."],"exampleFix":"// before: baseUrl pointed at chat endpoint\nOD_OPENAI_BASE_URL=https://api.openai.com/v1/chat\n// after\nOD_OPENAI_BASE_URL=https://api.openai.com/v1","handlingStrategy":"try-catch","validationCode":"function isOpenAIImageEnvelope(data: unknown): data is { data: [{ b64_json?: string; url?: string }] } {\n  return Boolean(data && typeof data === 'object' && Array.isArray((data as any).data) && (data as any).data.length > 0);\n}","typeGuard":"function isOpenAIImageEnvelope(data: unknown): data is { data: [{ b64_json?: string; url?: string }] } {\n  return Boolean(data && typeof data === 'object' && Array.isArray((data as any).data) && (data as any).data.length > 0);\n}","tryCatchPattern":"try {\n  return await renderOpenAIImage(ctx, credentials);\n} catch (err) {\n  const m = err instanceof Error ? err.message : '';\n  if (m === 'openai response had no data[0]') {\n    throw new ConfigError('Upstream returned an unexpected JSON envelope. Verify baseUrl targets the images API.');\n  }\n  throw err;\n}","preventionTips":["Confirm baseUrl targets the host root (the path /images/generations is appended automatically).","For Azure, include the api-version query parameter so the correct schema is returned.","Log the parsed JSON when this fires to identify the alternate envelope."],"tags":["network","media","openai","response-shape","azure"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}