HeyPuter/puter · error · HttpError

insufficient_funds

insufficient_funds

Error message

Insufficient credits for image generation

What it means

Thrown by OpenAiImageProvider.generate() (OpenAiImageProvider.ts:192) when hasEnoughCredits returns false for the estimated total (input cost estimate + output price). Same insufficient-funds semantics as the Gemini equivalent but for the OpenAI provider. HTTP 402 insufficient_funds.

Source

Thrown at src/backend/drivers/ai-image/providers/openai/OpenAiImageProvider.ts:192

                    estimatedPromptTokenCount + estimatedImageInputTokens,
                inputTextTokens: estimatedPromptTokenCount,
                inputImageTokens: estimatedImageInputTokens,
                cachedInputTokens: 0,
                cachedInputTextTokens: 0,
                cachedInputImageTokens: 0,
            } as OpenAIImageUsage,
        );
        const estimatedOutputCostInCents = outputPriceInCents;
        const estimatedTotalCostInMicroCents = this.#toMicroCents(
            estimatedInputCostInCents + estimatedOutputCostInCents,
        );
        const usageAllowed = await this.#meteringService.hasEnoughCredits(
            actor,
            estimatedTotalCostInMicroCents,
        );

        if (!usageAllowed) {
            throw new HttpError(
                402,
                'Insufficient credits for image generation',
                { legacyCode: 'insufficient_funds' },
            );
        }

        // With input images we use the edit endpoint (gpt-image only);
        // otherwise the standard generate endpoint.
        const result = hasInputImages
            ? await this.#openai.images.edit(
                  await this.#buildEditParams(
                      selectedModel.id,
                      { user: userIdentifier, prompt, size, quality },
                      input_images!,
                      input_image_mime_type,
                  ),
              )
            : await this.#openai.images.generate(

View on GitHub (pinned to 908ec23eda)

Solutions

  1. Top up or grant credits to the actor.
  2. Choose a lower quality level (low instead of high) or smaller size to reduce the estimate.
  3. Confirm the metering balance is current and retry.
Defensive patterns

Strategy: try-catch

Validate before calling

if (!(await meteringService.hasEnoughCredits(actor, estimatedMicroCents))) {
  // prompt top-up or cheaper tier
}

Try / catch

try {
  await provider.generate(params);
} catch (e) {
  if (e instanceof HttpError && e.status_code === 402) {
    // surface insufficient credits; offer lower quality/size or top-up
  }
  throw e;
}

Prevention

When it happens

Trigger: Low-balance actor calling generate(); an expensive size/quality (e.g. high quality, large size) exceeding remaining credits; estimate overestimating slightly vs actual cost.

Common situations: Trial credits exhausted; user selected a high-cost tier; balance stale after a recent top-up.

Related errors


AI-assisted analysis of HeyPuter/puter@908ec23eda (2026-08-12). Data as JSON: /api/errors/addacc3aec12764f. Report an issue: GitHub.