{"record":{"id":"7c63010937c9cc5e","repo":"chatboxai/chatbox","slug":"invalid-response-format-from-image-generation-api","errorCode":null,"errorMessage":"Invalid response format from image generation API","messagePattern":"Invalid response format from image generation API","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/shared/providers/definitions/models/chatboxai.ts","lineNumber":439,"sourceCode":"        'Instance-Id': instanceId,\n        'Content-Type': 'application/json',\n      },\n      method: 'POST',\n      body: JSON.stringify({\n        prompt,\n        ...(modelId ? { model: modelId } : {}),\n        images: images?.map((i) => ({ image_url: i.imageUrl })),\n        response_format: 'b64_json',\n        style: this.options.dalleStyle,\n        aspect_ratio: aspectRatio,\n        uuid: this.config.uuid,\n        language: this.options.language,\n      }),\n      signal,\n    })\n    const json = await res.json()\n    if (!json['data'] || !json['data'][0]) {\n      throw new Error('Invalid response format from image generation API')\n    }\n    return json['data'][0]['b64_json']\n  }\n\n  public async chat(messages: ModelMessage[], options: CallChatCompletionOptions): Promise<StreamTextResult> {\n    const cached = this.options.model.apiStyle === 'anthropic' ? addAnthropicCacheControl(messages) : messages\n    return super.chat(cached, options)\n  }\n\n  public async *chatStream<T extends ToolSet>(\n    messages: ModelMessage[],\n    options: ChatStreamOptions\n  ): AsyncGenerator<ModelStreamPart<T>> {\n    const cached = this.options.model.apiStyle === 'anthropic' ? addAnthropicCacheControl(messages) : messages\n    yield* super.chatStream<T>(cached, options)\n  }\n\n  isSupportSystemMessage() {","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/shared/providers/definitions/models/chatboxai.ts#L421-L457","documentation":"Thrown by the ChatboxAI provider's image-generation method after the POST returns and res.json() resolves: when json['data'] is missing or json['data'][0] is absent. The ChatboxAI image API is expected to echo the OpenAI shape ({ data: [{ b64_json }] }); anything else trips this guard before b64_json is read.","triggerScenarios":"The ChatboxAI image endpoint responded 2xx but the body lacks data[0] — e.g. an error envelope returned with 200, an empty data array, a schema change on the server, a malformed proxy response, or a quota message returned in place of image data.","commonSituations":"ChatboxAI image quota exhausted and server returned { error: ... } with status 200; service-side schema drift after an upgrade; CDN/proxy stripped the body; request was accepted but generation produced no image (content filter); transient backend bug.","solutions":["Log the full json object when the guard trips so the actual server payload is visible — the message currently discards it.","If the body is an error envelope, map it to a user-facing message (quota/filter) instead of the generic 'Invalid response format'.","Retry once for transient backend issues; if it persists, check ChatboxAI service status.","Verify the request included all required fields (model, response_format:'b64_json', uuid, language) — some missing fields can yield a 200 with an empty data array."],"exampleFix":"// before\nconst json = await res.json()\nif (!json['data'] || !json['data'][0]) {\n  throw new Error('Invalid response format from image generation API')\n}\nreturn json['data'][0]['b64_json']\n// after — surface the server payload for diagnosability\nconst json = await res.json()\nif (!json['data'] || !json['data'][0]) {\n  throw new Error(`Invalid response format from image generation API: ${JSON.stringify(json)}`)\n}\nreturn json['data'][0]['b64_json']","handlingStrategy":"validation","validationCode":"// Pre-validate the request payload before calling the ChatboxAI image endpoint.\nfunction assertChatboxAIImageRequest(req: { prompt: string; model?: string; response_format: string; uuid: string; language: string }): string | null {\n  if (!req.prompt?.trim()) return 'prompt required'\n  if (req.response_format !== 'b64_json') return 'response_format must be b64_json'\n  if (!req.uuid) return 'uuid required'\n  return null\n}","typeGuard":"function isChatboxAIImageResponse(v: unknown): v is { data: { b64_json: string }[] } {\n  return typeof v === 'object' && v !== null && Array.isArray((v as any).data) && (v as any).data.length > 0\n}","tryCatchPattern":"try {\n  return await provider.paint(params, signal)\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid response format from image generation API') {\n    showUser('Image generation returned an unexpected response. Check quota and try again.')\n    return []\n  }\n  throw e\n}","preventionTips":["Log the full json payload when the guard trips so quota/filter envelopes are visible.","If the body is an error envelope, map it to a quota/filter message instead of the generic 'Invalid response format'.","Retry once — transient backend issues can yield a 200 with empty data."],"tags":["chatbox-ai","image-generation","api-contract","response-shape"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}