vercel/ai · error

Black Forest Labs poll response is Ready but missing result.

Error message

Black Forest Labs poll response is Ready but missing result.sample

What it means

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.

Source

Thrown at packages/black-forest-labs/src/black-forest-labs-image-model.ts:352

          : undefined,
        failedResponseHandler: bflFailedResponseHandler,
        successfulResponseHandler: createJsonResponseHandler(bflPollSchema),
        abortSignal,
        fetch: this.config.fetch,
      });

      const status = value.status;
      if (status === 'Ready') {
        if (typeof value.result?.sample === 'string') {
          return {
            imageUrl: value.result.sample,
            seed: value.result.seed ?? undefined,
            start_time: value.result.start_time ?? undefined,
            end_time: value.result.end_time ?? undefined,
            duration: value.result.duration ?? undefined,
          };
        }
        throw new Error(
          'Black Forest Labs poll response is Ready but missing result.sample',
        );
      }
      if (status === 'Error' || status === 'Failed') {
        throw new Error('Black Forest Labs generation failed.');
      }

      await delay(pollIntervalMillis);
    }

    throw new Error('Black Forest Labs generation timed out.');
  }
}

function convertSizeToAspectRatio(
  size: string,
): BlackForestLabsAspectRatio | undefined {
  const [wStr, hStr] = size.split('x');

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Retry the generation; transient malformed responses usually succeed on a second attempt.
  2. Update @ai-sdk/black-forest-labs to the latest version to pick up response-parsing fixes.
  3. Remove or inspect custom fetch/proxy middleware that could alter or truncate the poll response body.
  4. Log the raw poll response body and report the malformed payload to Black Forest Labs support if it persists.

Example fix

// before: no handling around generateImage
const { image } = await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });

// after: catch and retry once
let result;
try {
  result = await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });
} catch (e) {
  if (String((e as Error).message).includes('missing result.sample')) {
    result = await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });
  } else { throw e; }
}
Defensive patterns

Strategy: retry

Validate before calling

if (!process.env.BFL_API_KEY) throw new Error('BFL_API_KEY is required');
console.warn('BFL poll responses depend on upstream schema; pin @ai-sdk/black-forest-labs to a tested version.');

Type guard

function hasSample(r: unknown): r is { result: { sample: string } } {
  return !!r && typeof r === 'object' && 'result' in r &&
    !!(r as any).result && typeof (r as any).result.sample === 'string';
}

Try / catch

for (let attempt = 0; attempt < 2; attempt++) {
  try {
    return await generateImage({ model: bfl.image('flux-pro-1.1'), prompt });
  } catch (e) {
    const msg = (e as Error).message ?? '';
    if (attempt === 1 || !msg.includes('missing result.sample')) throw e;
  }
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/b981da44b3c76ff0. Report an issue: GitHub.