{"record":{"id":"32d6ae5a7c247c46","repo":"linshenkx/prompt-optimizer","slug":"invalid-response-format-32d6ae","errorCode":"INVALID_RESPONSE_FORMAT","errorMessage":"INVALID_RESPONSE_FORMAT","messagePattern":"INVALID_RESPONSE_FORMAT","errorType":"error_code","errorClass":"ImageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/image/adapters/seedream.ts","lineNumber":290,"sourceCode":"      method: 'POST',\n      headers: {\n        'Authorization': `Bearer ${config.connectionConfig?.apiKey}`,\n        'Content-Type': 'application/json'\n      },\n      body: JSON.stringify(payload)\n    })\n\n    const data = response\n\n    // 解析响应\n    const images = data.data?.map((item: any) => ({\n      url: item.url,\n      b64: item.b64_json,\n      mimeType: 'image/png'\n    })) || []\n\n    if (images.length === 0) {\n      throw new ImageError(IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT)\n    }\n\n      return {\n      images,\n      metadata: {\n        providerId: 'seedream',\n        modelId: config.modelId,\n        configId: config.id,\n        usage: data.usage\n      }\n    }\n  }\n\n  private async apiCall(config: ImageModelConfig, endpoint: string, options: any) {\n    const url = this.resolveEndpointUrl(config, endpoint)\n    const response = await fetch(url, options)\n    if (!response.ok) {\n      let errorMessage: string","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/image/adapters/seedream.ts#L272-L308","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Log the raw response JSON in apiCall before parsing to see the actual payload shape","Verify the Seedream API docs for the current response schema and update the field mapping in doGenerate","Confirm the model ID and endpoint are correct (a wrong model can return 200 with no images)","If the provider intermittently returns empty data, retry the generation request once"],"exampleFix":"// before\nconst images = (data?.data || []).map(item => ({\n  url: item.url,\n  b64: item.b64_json,\n  mimeType: 'image/png'\n})) || []\n\n// after — tolerate alternate field names\nconst images = (data?.data || []).map(item => ({\n  url: item.url || item.image_url,\n  b64: item.b64_json || item.b64,\n  mimeType: 'image/png'\n})).filter(i => i.url || i.b64) || []","handlingStrategy":"retry","validationCode":"const hasImage = (r: any) => Array.isArray(r?.data) && r.data.some((i: any) => i?.url || i?.b64_json)","typeGuard":"function isSeedreamImageResponse(r: unknown): r is { data: Array<{ url?: string; b64_json?: string }> } {\n  const d = (r as any)?.data\n  return Array.isArray(d) && d.some(i => !!(i?.url || i?.b64_json))\n}","tryCatchPattern":"try {\n  const result = await adapter.generate(request)\n} catch (e) {\n  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.INVALID_RESPONSE_FORMAT) {\n    // log raw provider payload; retry once — often transient or an API schema change\n    return retryOnce(request)\n  }\n  throw e\n}","preventionTips":["Pin the Seedream API version / base URL in connection config","Wrap generate calls in a single place so empty-response handling and logging is centralized","Monitor provider changelog for response schema updates"],"tags":["seedream","image-generation","response-parsing","api-contract"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}