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
- If 'No payment method found': add a payment method in the billing portal, then retry
- 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
- If 'must not be negative': re-check threshold/amount values being sent; they must be non-negative cents
- 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
- Ensure a default payment method exists before enabling top-up
- Disable submit during in-flight requests
- GET the existing config before configuring
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
- Server returned ${status}.
- Stripe didn't return a checkout URL. Check backend logs for
- str(e)
- Rate limit reset is not available (credit system is disabled
- Insufficient credits to reset your rate limit.
AI-assisted analysis of Significant-Gravitas/AutoGPT@9c8bb5550f (2026-08-14).
Data as JSON: /api/errors/d3bf68c79e06560d.
Report an issue: GitHub.