Significant-Gravitas/AutoGPT · error · HTTPException

str(e)

Error message

str(e)

What it means

HTTP 422 from POST /credits/auto-top-up wrapping a ValueError raised inside top_up_credits when the message matches a known set ('must not be negative', 'already exists for user', 'No payment method found'). Unknown ValueErrors are re-raised as 500s. The Stripe charge path surfaces these when the requested top-up fails at the payment layer.

Source

Thrown at autogpt_platform/backend/backend/api/features/v1.py:776

            status_code=422, detail="Amount must be greater than or equal to threshold"
        )

    credit_model = await get_credit_model(user_id, ctx.org_id)
    current_balance = await credit_model.get_credits(user_id)

    try:
        if current_balance < request.threshold:
            await credit_model.top_up_credits(user_id, request.amount)
        else:
            await credit_model.top_up_credits(user_id, 0)
    except ValueError as e:
        known_messages = (
            "must not be negative",
            "already exists for user",
            "No payment method found",
        )
        if any(msg in str(e) for msg in known_messages):
            raise HTTPException(status_code=422, detail=str(e))
        raise

    try:
        await set_auto_top_up(
            user_id, AutoTopUpConfig(threshold=request.threshold, amount=request.amount)
        )
    except ValueError as e:
        raise HTTPException(status_code=422, detail=str(e))
    return "Auto top-up settings updated"


@v1_router.get(
    path="/credits/auto-top-up",
    summary="Get auto top up",
    tags=["credits"],
    dependencies=[Security(requires_user)],
)
async def get_user_auto_top_up(

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. If 'No payment method found': add a payment method in the billing portal, then retry
  2. If 'already exists for user': fetch the current config via GET /credits/auto-top-up and use the update path instead of creating a new one
  3. If 'must not be negative': re-check threshold/amount values being sent; they must be non-negative cents
  4. Unknown ValueError text -> this becomes a 500; check server logs for the full traceback
Defensive patterns

Strategy: try-catch

Validate before calling

const methods = await api.listPaymentMethods();
if (methods.length === 0) await redirectToBillingPortal();

Try / catch

try {
  await api.configureAutoTopUp(config);
} catch (e) {
  if (e.status === 422) {
    // detail is the raw ValueError: 'No payment method found',
    // 'already exists for user', or 'must not be negative'
    handleBillingError(e.detail);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the auto top-up endpoint when: the amount would make something negative; a top-up config row already exists for the user (duplicate creation); or the user's Stripe customer has no default payment method and an immediate top-up is attempted.

Common situations: Users who signed up but never added a card; double-submitting the settings form creating a duplicate config; race between balance check and charge; Stripe customer created without an attached payment method.

Related errors


AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14). Data as JSON: /api/errors/d3bf68c79e06560d. Report an issue: GitHub.