linshenkx/prompt-optimizer · error · ImageError

GENERATION_FAILED

GENERATION_FAILED

Error message

SiliconFlow API error: ${response.status} ${response.statusText}${requestId ? ` (requestId=${requestId})` : ''}${bodyText ? `\n\n${bodyText}` : ''}

What it means

The SiliconFlow HTTP API returned a non-2xx status. The adapter enriches the error with a request ID harvested from several response headers (x-request-id, x-siliconflow-request-id, cf-ray, x-amzn-requestid, x-requestid) plus the response body text, then throws GENERATION_FAILED.

Source

Thrown at packages/core/src/services/image/adapters/siliconflow.ts:335

    const response = await fetch(url, options)
    if (!response.ok) {
      let bodyText = ''
      try {
        bodyText = await response.text()
      } catch {
        bodyText = ''
      }

      const headers: any = (response as any)?.headers
      const getHeader = (name: string) => (headers?.get ? headers.get(name) : undefined)
      const requestId =
        getHeader('x-request-id') ||
        getHeader('x-siliconflow-request-id') ||
        getHeader('cf-ray') ||
        getHeader('x-amzn-requestid') ||
        getHeader('x-requestid')

      throw new ImageError(
        IMAGE_ERROR_CODES.GENERATION_FAILED,
        `SiliconFlow API error: ${response.status} ${response.statusText}` +
          (requestId ? ` (requestId=${requestId})` : '') +
          (bodyText ? `\n\n${bodyText}` : '')
      )
    }
    return await response.json()
  }

  protected getParameterDefinitions(modelId: string): readonly ImageParameterDefinition[] {
    const modelName = modelId.toLowerCase()

    // 基础参数
    const baseParams: ImageParameterDefinition[] = [
      {
        name: 'image_size',
        labelKey: 'params.imageSize.label',
        descriptionKey: 'params.imageSize.description',

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Read the status code and bodyText in the message — they carry SiliconFlow's specific reason
  2. Capture the requestId from the message and include it when contacting SiliconFlow support
  3. 401 → refresh API key; 429 → back off and retry with exponential delay
  4. For 5xx with cf-ray, retry — it's a transient edge failure
Defensive patterns

Strategy: retry

Try / catch

try {
  const r = await adapter.generate(req)
} catch (e) {
  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.GENERATION_FAILED) {
    const status = Number(e.message.match(/SiliconFlow API error: (\d+)/)?.[1])
    if (status === 429 || status >= 500) return backoffRetry(req)
    // include requestId from the message when reporting to SiliconFlow
  }
  throw e
}

Prevention

When it happens

Trigger: Any text2image or image2image API call returning 4xx/5xx: auth failure (401), rate limiting (429), invalid parameters (400), content policy rejection, or upstream 5xx.

Common situations: Rate limits on the free SiliconFlow tier; expired API key; prompt flagged by content moderation; image payload too large; transient Cloudflare 502/503 (note cf-ray header presence).

Related errors


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