{"record":{"id":"a739eb885a0fa7f4","repo":"HeyPuter/puter","slug":"unknown-error-a739eb","errorCode":"unknown_error","errorMessage":"Error calculating cost for Replicate model ${selectedModel.id}","messagePattern":"Error calculating cost for Replicate model (.+?)","errorType":"http","errorClass":"HttpError","httpStatus":400,"severity":"error","filePath":"src/backend/drivers/ai-image/providers/replicate/ReplicateImageGenerationProvider.ts","lineNumber":148,"sourceCode":"        const allInputUrls = singleImage ? [singleImage] : inputImages;\n        const inputMp =\n            allInputUrls.length > 0\n                ? await this.#measureInputMegapixels(allInputUrls)\n                : 0;\n\n        const outputMp = this.#resolveOutputMegapixels(\n            params.output_megapixels as string | undefined,\n        );\n\n        const totalCostMicroCents = this.#estimateCost(\n            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        }","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/HeyPuter/puter/blob/908ec23eda38526170322c3edf71ba45ecb1ca95/src/backend/drivers/ai-image/providers/replicate/ReplicateImageGenerationProvider.ts#L130-L166","documentation":"Thrown by ReplicateImageGenerationProvider.generate() (ReplicateImageGenerationProvider.ts:148) when #estimateCost() returns a value <= 0. This is the outer guard after #estimateCost; note #estimateCost itself throws more specific errors for missing per-image cost (line 407) or missing output_mp cost (line 418), so reaching the <= 0 guard means costs were present but computed to zero (e.g. zero run cost, zero output_mp, zero input). HTTP 400 unknown_error — effectively a billing-config defect for the model.","triggerScenarios":"A Replicate model whose resolved costs object (base, costs_go_fast, or costs_by_generation_mode) has output_mp = 0 and run = 0 and input_mp = 0; a per-image model with output = 0 (though that throws earlier at line 407); selecting go_fast or a generation_mode that resolves to a costs object with all-zero values; a model whose costs map is empty.","commonSituations":"Maintainer adds a model with placeholder zero costs; a generation_mode key typo that falls back to a sparse costs object; go_fast flag selecting a costs_go_fast map that lacks output_mp.","solutions":["Fix the model's cost configuration in src/backend/drivers/ai-image/providers/replicate/models.ts: ensure output_mp (or output for per-image) is a positive number.","Verify the selected costs variant (base vs costs_go_fast vs costs_by_generation_mode) has valid non-zero rates.","If you are a consumer, try without go_fast or with a different model to isolate which costs branch is zero.","Audit #estimateCost inputs (outputMp, inputMp, generationMode) to ensure they are positive."],"exampleFix":"// models.ts — before\ncosts: { run: 0, output_mp: 0, input_mp: 0 }\n\n// after\ncosts: { run: 0.1, output_mp: 0.5, input_mp: 0.2 }","handlingStrategy":"validation","validationCode":"function assertPositiveCost(model: ReplicateImageModel, costMicroCents: number): void {\n  if (costMicroCents <= 0) {\n    throw new Error(`Cost config invalid for Replicate model ${model.id}`);\n  }\n}\n// or validate the model's cost map directly before generate():\nconst c = model.costs;\nif ((c.output_mp ?? 0) <= 0 && (c.output ?? 0) <= 0) {\n  throw new Error(`Model ${model.id} has no valid cost`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure every Replicate model has positive output_mp (or output for per-image) in its costs.","Verify costs_go_fast and costs_by_generation_mode variants also have valid rates if present.","Add a config test asserting all Replicate models compute a positive cost."],"tags":["configuration","billing","replicate","ai-image","cost-estimation","unknown-error"],"backgroundTag":null,"analyzedSha":"908ec23eda38526170322c3edf71ba45ecb1ca95","analyzedAt":"2026-08-12T20:53:15.911Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}