HeyPuter/puter · error · HttpError
unknown_error
unknown_error
Error message
Error calculating cost for Replicate model ${selectedModel.id} What it means
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.
Source
Thrown at src/backend/drivers/ai-image/providers/replicate/ReplicateImageGenerationProvider.ts:148
const allInputUrls = singleImage ? [singleImage] : inputImages;
const inputMp =
allInputUrls.length > 0
? await this.#measureInputMegapixels(allInputUrls)
: 0;
const outputMp = this.#resolveOutputMegapixels(
params.output_megapixels as string | undefined,
);
const totalCostMicroCents = this.#estimateCost(
selectedModel,
outputMp,
goFast,
inputMp,
generationMode,
);
if (totalCostMicroCents <= 0) {
throw new HttpError(
400,
`Error calculating cost for Replicate model ${selectedModel.id}`,
{ legacyCode: 'unknown_error' },
);
}
const usageAllowed = await this.#meteringService.hasEnoughCredits(
actor,
totalCostMicroCents,
);
if (!usageAllowed) {
throw new HttpError(
402,
'Insufficient credits for image generation',
{
legacyCode: 'insufficient_funds',
},
);
}View on GitHub (pinned to 908ec23eda)
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.
Example fix
// models.ts — before
costs: { run: 0, output_mp: 0, input_mp: 0 }
// after
costs: { run: 0.1, output_mp: 0.5, input_mp: 0.2 } Defensive patterns
Strategy: validation
Validate before calling
function assertPositiveCost(model: ReplicateImageModel, costMicroCents: number): void {
if (costMicroCents <= 0) {
throw new Error(`Cost config invalid for Replicate model ${model.id}`);
}
}
// or validate the model's cost map directly before generate():
const c = model.costs;
if ((c.output_mp ?? 0) <= 0 && (c.output ?? 0) <= 0) {
throw new Error(`Model ${model.id} has no valid cost`);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of HeyPuter/puter@908ec23eda (2026-08-12).
Data as JSON: /api/errors/a739eb885a0fa7f4.
Report an issue: GitHub.