linshenkx/prompt-optimizer · error · ImageError

INVALID_RESPONSE_FORMAT

INVALID_RESPONSE_FORMAT

Error message

INVALID_RESPONSE_FORMAT

What it means

The Seedream adapter parsed the provider's HTTP response as successful (2xx) but the images array came back empty: neither `url` nor `b64_json` fields were present on any returned data item. The adapter guarantees at least one image per successful generation, so it throws INVALID_RESPONSE_FORMAT when the response body shape does not match expectations. This usually indicates an upstream API contract change or an unexpected response schema.

Source

Thrown at packages/core/src/services/image/adapters/seedream.ts:290

      method: 'POST',
      headers: {
        'Authorization': `Bearer ${config.connectionConfig?.apiKey}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(payload)
    })

    const data = response

    // 解析响应
    const images = data.data?.map((item: any) => ({
      url: item.url,
      b64: item.b64_json,
      mimeType: 'image/png'
    })) || []

    if (images.length === 0) {
      throw new ImageError(IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)
    }

      return {
      images,
      metadata: {
        providerId: 'seedream',
        modelId: config.modelId,
        configId: config.id,
        usage: data.usage
      }
    }
  }

  private async apiCall(config: ImageModelConfig, endpoint: string, options: any) {
    const url = this.resolveEndpointUrl(config, endpoint)
    const response = await fetch(url, options)
    if (!response.ok) {
      let errorMessage: string

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Log the raw response JSON in apiCall before parsing to see the actual payload shape
  2. Verify the Seedream API docs for the current response schema and update the field mapping in doGenerate
  3. Confirm the model ID and endpoint are correct (a wrong model can return 200 with no images)
  4. If the provider intermittently returns empty data, retry the generation request once

Example fix

// before
const images = (data?.data || []).map(item => ({
  url: item.url,
  b64: item.b64_json,
  mimeType: 'image/png'
})) || []

// after — tolerate alternate field names
const images = (data?.data || []).map(item => ({
  url: item.url || item.image_url,
  b64: item.b64_json || item.b64,
  mimeType: 'image/png'
})).filter(i => i.url || i.b64) || []
Defensive patterns

Strategy: retry

Validate before calling

const hasImage = (r: any) => Array.isArray(r?.data) && r.data.some((i: any) => i?.url || i?.b64_json)

Type guard

function isSeedreamImageResponse(r: unknown): r is { data: Array<{ url?: string; b64_json?: string }> } {
  const d = (r as any)?.data
  return Array.isArray(d) && d.some(i => !!(i?.url || i?.b64_json))
}

Try / catch

try {
  const result = await adapter.generate(request)
} catch (e) {
  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT) {
    // log raw provider payload; retry once — often transient or an API schema change
    return retryOnce(request)
  }
  throw e
}

Prevention

When it happens

Trigger: Calling generate() on the Seedream adapter where the API returns 200 OK but the `data` array is missing, null, or its items lack both `url` and `b64_json` (e.g. field renamed, empty data array, or a partial/misrouted response).

Common situations: Volcengine/Seedream API version changes renaming response fields; model returning an empty data array under load; regional endpoints returning a differently-shaped payload; proxy or gateway stripping response bodies.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/32d6ae5a7c247c46. Report an issue: GitHub.