{"record":{"id":"e10456193cb0ddd9","repo":"HeyPuter/puter","slug":"insufficient-funds-e10456","errorCode":"insufficient_funds","errorMessage":"Insufficient credits for image generation","messagePattern":"Insufficient credits for image generation","errorType":"http","errorClass":"HttpError","httpStatus":402,"severity":"error","filePath":"src/backend/drivers/ai-image/providers/replicate/ReplicateImageGenerationProvider.ts","lineNumber":159,"sourceCode":"            selectedModel,\n            outputMp,\n            goFast,\n            inputMp,\n            generationMode,\n        );\n        if (totalCostMicroCents <= 0) {\n            throw new HttpError(\n                400,\n                `Error calculating cost for Replicate model ${selectedModel.id}`,\n                { legacyCode: 'unknown_error' },\n            );\n        }\n        const usageAllowed = await this.#meteringService.hasEnoughCredits(\n            actor,\n            totalCostMicroCents,\n        );\n        if (!usageAllowed) {\n            throw new HttpError(\n                402,\n                'Insufficient credits for image generation',\n                {\n                    legacyCode: 'insufficient_funds',\n                },\n            );\n        }\n\n        const input = this.#buildRequest(selectedModel, {\n            prompt,\n            ratio,\n            transformed,\n            inputImages,\n            singleImage,\n        });\n\n        const output = await this.#client.run(\n            selectedModel.replicateId as `${string}/${string}`,","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/HeyPuter/puter/blob/908ec23eda38526170322c3edf71ba45ecb1ca95/src/backend/drivers/ai-image/providers/replicate/ReplicateImageGenerationProvider.ts#L141-L177","documentation":"Thrown by ReplicateImageGenerationProvider.generate() (ReplicateImageGenerationProvider.ts:159) when hasEnoughCredits returns false for the computed totalCostMicroCents. Same insufficient-funds semantics as the Gemini/OpenAI equivalents, specific to the Replicate provider. HTTP 402 insufficient_funds.","triggerScenarios":"Low-balance actor calling a Replicate model; a high-megapixel output or image-input-heavy request inflating the cost estimate beyond remaining credits; go_fast or a premium generation_mode raising the cost.","commonSituations":"Trial credits exhausted; user selected a large output_megapixels value; multiple input images adding input-megapixel cost; balance not refreshed after payment.","solutions":["Top up or grant credits to the actor.","Reduce output_megapixels (default is 1; lower tiers cost less).","Use a cheaper model (e.g. flux-schnell) or disable go_fast.","Reduce the number of input images to cut input-megapixel cost.","Confirm the metering balance is current and retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!(await meteringService.hasEnoughCredits(actor, totalCostMicroCents))) {\n  // prompt top-up, reduce output_megapixels, fewer input images, or cheaper model\n}","typeGuard":null,"tryCatchPattern":"try {\n  await provider.generate(params);\n} catch (e) {\n  if (e instanceof HttpError && e.status_code === 402) {\n    // surface insufficient credits; offer cheaper model/lower megapixels/top-up\n  }\n  throw e;\n}","preventionTips":["Pre-check balance against the estimated cost before calling generate.","Lower output_megapixels or input image count to reduce cost.","Default to flux-schnell or disable go_fast when balance is low."],"tags":["billing","credits","replicate","ai-image","insufficient-funds","payment"],"backgroundTag":null,"analyzedSha":"908ec23eda38526170322c3edf71ba45ecb1ca95","analyzedAt":"2026-08-12T20:53:15.911Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}