{"record":{"id":"1bd126cc096620a4","repo":"nexu-io/open-design","slug":"openai-response-had-neither-b64-json-nor-url","errorCode":null,"errorMessage":"openai response had neither b64_json nor url","messagePattern":"openai response had neither b64_json nor url","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":972,"sourceCode":"  }\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',\n    );\n  }\n  const baseUrl = (credentials.baseUrl || IMAGEROUTER_DEFAULT_BASE_URL).trim();\n  const wireModel = (credentials.model || ctx.wireModel).trim();","sourceCodeStart":954,"sourceCodeEnd":990,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L954-L990","documentation":"Thrown by renderOpenAIImage when data[0] exists but contains neither b64_json nor url. The OpenAI image contract requires exactly one of these fields per entry; their absence indicates a malformed or partial upstream response (e.g. a moderation refusal that returned an empty entry, or an API version that uses a different field name).","triggerScenarios":"Content moderation triggered and the entry was returned empty; using a beta/preview API version that returns a different field (e.g. 'image' instead of 'b64_json'); upstream returned a stub entry on partial failure; Azure deployment configured with output-format the daemon does not recognize.","commonSituations":"Prompt tripped safety filters; preview model on Azure with a non-standard response format; misconfigured deployment returning metadata-only entries.","solutions":["Inspect data[0] to see which fields it does carry, and adjust the renderer or the deployment to emit b64_json or url.","Rephrase the prompt to avoid moderation-triggering content.","Switch to a GA model id with a stable response schema.","For Azure, set the deployment output format to PNG/JPEG so b64_json is populated."],"exampleFix":"// before: preview deployment returns {data:[{revised_prompt:'...'}]}\n// after: use GA deployment that returns {data:[{b64_json:'...'}]}\nod media generate --surface image --model gpt-image-1 --prompt \"...\"","handlingStrategy":"try-catch","validationCode":"function isOpenAIImageEntry(entry: unknown): entry is { b64_json?: string; url?: string } {\n  return Boolean(entry && typeof entry === 'object' && ((entry as any).b64_json || (entry as any).url));\n}","typeGuard":"function isOpenAIImageEntry(entry: unknown): entry is { b64_json?: string; url?: string } {\n  return Boolean(entry && typeof entry === 'object' && ((entry as any).b64_json || (entry as any).url));\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 neither b64_json nor url') {\n    // usually moderation or schema skew; do not retry the same prompt\n    throw new UserActionableError('OpenAI returned an empty image entry (possibly moderation). Rephrase the prompt.');\n  }\n  throw err;\n}","preventionTips":["Avoid prompts likely to trip content filters; this error often masks a moderation refusal.","Use GA model ids whose response schema is stable.","For Azure, set the deployment output format to a known image type so b64_json is populated."],"tags":["network","media","openai","response-shape","moderation"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}