{"record":{"id":"b981da44b3c76ff0","repo":"vercel/ai","slug":"black-forest-labs-poll-response-is-ready-but-missi","errorCode":null,"errorMessage":"Black Forest Labs poll response is Ready but missing result.sample","messagePattern":"Black Forest Labs poll response is Ready but missing result\\.sample","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/black-forest-labs/src/black-forest-labs-image-model.ts","lineNumber":352,"sourceCode":"          : undefined,\n        failedResponseHandler: bflFailedResponseHandler,\n        successfulResponseHandler: createJsonResponseHandler(bflPollSchema),\n        abortSignal,\n        fetch: this.config.fetch,\n      });\n\n      const status = value.status;\n      if (status === 'Ready') {\n        if (typeof value.result?.sample === 'string') {\n          return {\n            imageUrl: value.result.sample,\n            seed: value.result.seed ?? undefined,\n            start_time: value.result.start_time ?? undefined,\n            end_time: value.result.end_time ?? undefined,\n            duration: value.result.duration ?? undefined,\n          };\n        }\n        throw new Error(\n          'Black Forest Labs poll response is Ready but missing result.sample',\n        );\n      }\n      if (status === 'Error' || status === 'Failed') {\n        throw new Error('Black Forest Labs generation failed.');\n      }\n\n      await delay(pollIntervalMillis);\n    }\n\n    throw new Error('Black Forest Labs generation timed out.');\n  }\n}\n\nfunction convertSizeToAspectRatio(\n  size: string,\n): BlackForestLabsAspectRatio | undefined {\n  const [wStr, hStr] = size.split('x');","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/black-forest-labs/src/black-forest-labs-image-model.ts#L334-L370","documentation":"Black Forest Labs image generation polls a result endpoint until the response status is 'Ready'. When the response claims Ready but the payload lacks a `result.sample` URL, the SDK cannot build an image URL and throws this plain Error from `pollForImageUrl`. It indicates an unexpected/malformed API response from the BFL polling endpoint rather than a failed generation.","triggerScenarios":"Calling generateImage/doGenerate with a Black Forest Labs image model when the final poll response has status 'Ready' but `value.result.sample` is undefined (e.g. API response shape changed, partial response, or an unexpected proxy/interceptor stripped fields).","commonSituations":"Upstream BFL API schema changes breaking an outdated SDK version; custom `fetch` wrappers or mock servers returning incomplete 'Ready' payloads; network intermediaries truncating the JSON body so `result.sample` is missing while status parses as Ready.","solutions":["Retry the generation; transient malformed responses usually succeed on a second attempt.","Update @ai-sdk/black-forest-labs to the latest version to pick up response-parsing fixes.","Remove or inspect custom fetch/proxy middleware that could alter or truncate the poll response body.","Log the raw poll response body and report the malformed payload to Black Forest Labs support if it persists."],"exampleFix":"// before: no handling around generateImage\nconst { image } = await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });\n\n// after: catch and retry once\nlet result;\ntry {\n  result = await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });\n} catch (e) {\n  if (String((e as Error).message).includes('missing result.sample')) {\n    result = await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });\n  } else { throw e; }\n}","handlingStrategy":"retry","validationCode":"if (!process.env.BFL_API_KEY) throw new Error('BFL_API_KEY is required');\nconsole.warn('BFL poll responses depend on upstream schema; pin @ai-sdk/black-forest-labs to a tested version.');","typeGuard":"function hasSample(r: unknown): r is { result: { sample: string } } {\n  return !!r && typeof r === 'object' && 'result' in r &&\n    !!(r as any).result && typeof (r as any).result.sample === 'string';\n}","tryCatchPattern":"for (let attempt = 0; attempt < 2; attempt++) {\n  try {\n    return await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });\n  } catch (e) {\n    const msg = (e as Error).message ?? '';\n    if (attempt === 1 || !msg.includes('missing result.sample')) throw e;\n  }\n}","preventionTips":["Pin the SDK package version and upgrade deliberately after reading BFL API changelogs.","Avoid custom fetch wrappers that mutate or truncate provider response bodies.","Wrap generateImage calls in a bounded retry for transient response issues."],"tags":["image-generation","polling","api-response","black-forest-labs"],"backgroundTag":"malformed-provider-response","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}