chatboxai/chatbox · error · Error

Invalid response format from image generation API

Error message

Invalid response format from image generation API

What it means

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.

Source

Thrown at src/shared/providers/definitions/models/chatboxai.ts:439

        'Instance-Id': instanceId,
        'Content-Type': 'application/json',
      },
      method: 'POST',
      body: JSON.stringify({
        prompt,
        ...(modelId ? { model: modelId } : {}),
        images: images?.map((i) => ({ image_url: i.imageUrl })),
        response_format: 'b64_json',
        style: this.options.dalleStyle,
        aspect_ratio: aspectRatio,
        uuid: this.config.uuid,
        language: this.options.language,
      }),
      signal,
    })
    const json = await res.json()
    if (!json['data'] || !json['data'][0]) {
      throw new Error('Invalid response format from image generation API')
    }
    return json['data'][0]['b64_json']
  }

  public async chat(messages: ModelMessage[], options: CallChatCompletionOptions): Promise<StreamTextResult> {
    const cached = this.options.model.apiStyle === 'anthropic' ? addAnthropicCacheControl(messages) : messages
    return super.chat(cached, options)
  }

  public async *chatStream<T extends ToolSet>(
    messages: ModelMessage[],
    options: ChatStreamOptions
  ): AsyncGenerator<ModelStreamPart<T>> {
    const cached = this.options.model.apiStyle === 'anthropic' ? addAnthropicCacheControl(messages) : messages
    yield* super.chatStream<T>(cached, options)
  }

  isSupportSystemMessage() {

View on GitHub (pinned to 81571269ad)

Solutions

  1. Log the full json object when the guard trips so the actual server payload is visible — the message currently discards it.
  2. If the body is an error envelope, map it to a user-facing message (quota/filter) instead of the generic 'Invalid response format'.
  3. Retry once for transient backend issues; if it persists, check ChatboxAI service status.
  4. 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.

Example fix

// before
const json = await res.json()
if (!json['data'] || !json['data'][0]) {
  throw new Error('Invalid response format from image generation API')
}
return json['data'][0]['b64_json']
// after — surface the server payload for diagnosability
const json = await res.json()
if (!json['data'] || !json['data'][0]) {
  throw new Error(`Invalid response format from image generation API: ${JSON.stringify(json)}`)
}
return json['data'][0]['b64_json']
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate the request payload before calling the ChatboxAI image endpoint.
function assertChatboxAIImageRequest(req: { prompt: string; model?: string; response_format: string; uuid: string; language: string }): string | null {
  if (!req.prompt?.trim()) return 'prompt required'
  if (req.response_format !== 'b64_json') return 'response_format must be b64_json'
  if (!req.uuid) return 'uuid required'
  return null
}

Type guard

function isChatboxAIImageResponse(v: unknown): v is { data: { b64_json: string }[] } {
  return typeof v === 'object' && v !== null && Array.isArray((v as any).data) && (v as any).data.length > 0
}

Try / catch

try {
  return await provider.paint(params, signal)
} catch (e) {
  if (e instanceof Error && e.message === 'Invalid response format from image generation API') {
    showUser('Image generation returned an unexpected response. Check quota and try again.')
    return []
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/7c63010937c9cc5e. Report an issue: GitHub.