{"record":{"id":"dc650fe69f7f24f9","repo":"nexu-io/open-design","slug":"providertag-response-had-no-data-0","errorCode":null,"errorMessage":"${providerTag} response had no data[0]","messagePattern":"(.+?) response had no data\\[0\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":1139,"sourceCode":"  if (!baseUrl || !model) return false;\n  return model === ctx.model || model === ctx.wireModel;\n}\n\nasync function parseOpenAICompatibleJson(resp: Response, providerTag: string): Promise<any> {\n  const text = await resp.text();\n  if (!resp.ok) {\n    throw new Error(`${providerTag} ${resp.status}: ${truncate(text, 240)}`);\n  }\n  try {\n    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 {","sourceCodeStart":1121,"sourceCodeEnd":1157,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L1121-L1157","documentation":"Thrown by bytesFromOpenAICompatibleData when the parsed JSON lacks a non-empty data array (or data[0] is null). Same contract expectation as the first-party path — OpenAI-compatible gateways must return {data:[{...}]} — generalized via providerTag so any compatible integration surfaces the same defect.","triggerScenarios":"Gateway returns an error envelope with HTTP 200; response schema differs from OpenAI's (e.g. {images:[...]} instead of {data:[...]}); empty data array on a no-op success.","commonSituations":"Compatible gateway that does not fully implement the OpenAI schema; preview/beta endpoint with a different envelope; gateway that wraps responses in an outer metadata object.","solutions":["Log the full parsed JSON to identify the actual envelope used by the gateway.","Choose a gateway that faithfully implements the OpenAI images schema, or extend bytesFromOpenAICompatibleData to handle the alternate envelope.","Switch to a model id on the gateway that returns the standard {data:[...]} shape.","Confirm the gateway is not returning a moderation/error envelope under HTTP 200."],"exampleFix":"// before: gateway returns {images:[{b64_json:'...'}]}\n// after: either reconfigure the gateway or extend the parser to read data.images\nif (!entry && Array.isArray(data.images)) entry = data.images[0];","handlingStrategy":"type-guard","validationCode":"function hasCompatibleDataArray(data: unknown): data is { data: unknown[] } {\n  return Boolean(data && typeof data === 'object' && Array.isArray((data as any).data) && (data as any).data.length > 0);\n}","typeGuard":"function hasCompatibleDataArray(data: unknown): data is { data: unknown[] } {\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 bytesFromOpenAICompatibleData(data, providerTag, requestInit);\n} catch (err) {\n  const m = err instanceof Error ? err.message : '';\n  if (m.endsWith('response had no data[0]')) {\n    throw new ConfigError(`${providerTag}: response did not contain a data[] entry. Verify gateway schema.`);\n  }\n  throw err;\n}","preventionTips":["Use gateways that faithfully implement the OpenAI {data:[...]} envelope.","Log the parsed JSON on this error to identify alternate envelopes (e.g. {images:[...]}).","Avoid preview/beta endpoints that return non-standard schemas."],"tags":["network","media","openai-compatible","response-shape","imagerouter"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}