linshenkx/prompt-optimizer · error · ImageError

GENERATION_FAILED

GENERATION_FAILED

Error message

Seedream API error: ${response.status} ${errorMessage}

What it means

The Seedream HTTP API returned a non-2xx status. The adapter attempts to parse the error body for `error.message` or `message`, falls back to `statusText`, and throws GENERATION_FAILED with the status code and message for diagnostics.

Source

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

        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
      try {
        const errorData = await response.json()
        errorMessage = errorData?.error?.message || errorData?.message || response.statusText
      } catch {
        errorMessage = response.statusText
      }
      throw new ImageError(IMAGE_ERROR_CODES.GENERATION_FAILED, `Seedream API error: ${response.status} ${errorMessage}`)
    }
    return await response.json()
  }

  private getModelSpec(modelId: string): SeedreamModelSpec {
    return SEEDREAM_MODEL_SPECS.find(spec => spec.id === modelId) || {
      id: modelId,
      name: modelId,
      description: `Custom Seedream model ${modelId}`,
      capabilities: {
        text2image: true,
        image2image: true,
        multiImage: false
      },
      parameterDefinitions: [
        {
          name: 'size',
          labelKey: 'params.size.label',

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Check the HTTP status in the message: 401/403 → rotate the API key in the connection config; 429 → slow down or raise quota
  2. Inspect the errorMessage text — it usually carries the provider's own reason (e.g. 'insufficient balance')
  3. For 5xx or transient 429, retry with exponential backoff
  4. Verify the base URL and model ID match your Seedream account entitlements
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(/Seedream API error: (\d+)/)?.[1])
    if (status === 429 || status >= 500) return backoffRetry(req)
    if (status === 401 || status === 403) throw new Error('Refresh Seedream API key')
  }
  throw e
}

Prevention

When it happens

Trigger: Any call to the Seedream generation endpoint that returns 4xx/5xx: invalid or expired API key (401), quota/balance exhausted (429/402), malformed request body (400), or upstream server errors (5xx).

Common situations: Expired or revoked Volcengine API key; insufficient account balance/rate limit; prompt or image payload exceeding size limits; wrong region base URL; temporary provider outage.

Related errors


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