{"record":{"id":"454be33cb71bf9e4","repo":"HeyPuter/puter","slug":"unknown-error","errorCode":"unknown_error","errorMessage":"Cloudflare image generation failed with status ${response.status}","messagePattern":"Cloudflare image generation failed with status (.+?)","errorType":"http","errorClass":"HttpError","httpStatus":400,"severity":"error","filePath":"src/backend/drivers/ai-image/providers/cloudflare/CloudflareImageProvider.ts","lineNumber":410,"sourceCode":"        ).toLowerCase();\n        if (contentType.startsWith('image/')) {\n            const imageBuffer = Buffer.from(await response.arrayBuffer());\n            return `data:${contentType};base64,${imageBuffer.toString('base64')}`;\n        }\n\n        const text = await response.text();\n        let payload: unknown;\n        try {\n            payload = text ? JSON.parse(text) : {};\n        } catch {\n            payload = { raw: text };\n        }\n\n        if (!response.ok) {\n            const message =\n                this.#extractErrorMessage(payload) ||\n                `Cloudflare image generation failed with status ${response.status}`;\n            throw new HttpError(400, message, { legacyCode: 'unknown_error' });\n        }\n\n        if (typeof payload === 'object' && payload !== null) {\n            const envelope = payload as Record<string, unknown>;\n            if (envelope.success === false) {\n                const message =\n                    this.#extractErrorMessage(payload) ||\n                    'Cloudflare image generation failed';\n                throw new HttpError(400, message, {\n                    legacyCode: 'unknown_error',\n                });\n            }\n        }\n\n        const imageString = this.#extractImageString(payload);\n        if (!imageString) {\n            throw new HttpError(\n                400,","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/HeyPuter/puter/blob/908ec23eda38526170322c3edf71ba45ecb1ca95/src/backend/drivers/ai-image/providers/cloudflare/CloudflareImageProvider.ts#L392-L428","documentation":"After POSTing to Cloudflare's endpoint, if the HTTP response is not ok (non-2xx), the provider tries to extract a message from the JSON payload; if extraction fails it throws HTTP 400 unknown_error with 'Cloudflare image generation failed with status <status>'. The raw status comes from Cloudflare's API response.","triggerScenarios":"Cloudflare returns a non-2xx for the generation request — auth error (bad API token → 401), rate limit (429), bad request (400), or upstream error (5xx) — and either no error message or a non-JSON body.","commonSituations":"Wrong/expired Cloudflare API token (config), exhausted Cloudflare quota, invalid model id sent to Cloudflare, Cloudflare API incident, malformed request payload.","solutions":["Check the Cloudflare API token/account config is valid and has the right permissions.","Verify the model id and request shape are accepted by Cloudflare (consult Cloudflare Workers AI docs).","If status is 429, back off and retry with exponential delay.","Inspect Cloudflare status page for incidents if status is 5xx."],"exampleFix":"// before — bad/expired token in config causes non-ok response\n// after — verify the token and model id, then retry on 429\n// config: ensure cloudflare.api_token is valid and account has Workers AI access","handlingStrategy":"retry","validationCode":"// No pure pre-check for upstream non-ok; validate config instead.\nif (!cloudflareConfig.api_token) throw new Error('Cloudflare API token not configured');","typeGuard":null,"tryCatchPattern":"try {\n  await provider.generate({ prompt });\n} catch (e) {\n  const status = /status (\\d+)/.exec(e?.message ?? '')?.[1];\n  if (e?.code === 'unknown_error' && status === '429') {\n    await sleep(backoffMs); await provider.generate({ prompt }); // retry on rate limit\n  } else throw e;\n}","preventionTips":["Keep the Cloudflare API token valid and scoped with Workers AI access.","Verify model ids against current Cloudflare Workers AI docs.","Back off and retry on 429; check Cloudflare status on 5xx."],"tags":["ai-image","cloudflare","provider","network","unknown-error","retryable"],"backgroundTag":null,"analyzedSha":"908ec23eda38526170322c3edf71ba45ecb1ca95","analyzedAt":"2026-08-12T20:53:15.911Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}