{"record":{"id":"d3bf68c79e06560d","repo":"Significant-Gravitas/AutoGPT","slug":"str-e-d3bf68","errorCode":null,"errorMessage":"str(e)","messagePattern":"str\\(e\\)","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/v1.py","lineNumber":776,"sourceCode":"            status_code=422, detail=\"Amount must be greater than or equal to threshold\"\n        )\n\n    credit_model = await get_credit_model(user_id, ctx.org_id)\n    current_balance = await credit_model.get_credits(user_id)\n\n    try:\n        if current_balance < request.threshold:\n            await credit_model.top_up_credits(user_id, request.amount)\n        else:\n            await credit_model.top_up_credits(user_id, 0)\n    except ValueError as e:\n        known_messages = (\n            \"must not be negative\",\n            \"already exists for user\",\n            \"No payment method found\",\n        )\n        if any(msg in str(e) for msg in known_messages):\n            raise HTTPException(status_code=422, detail=str(e))\n        raise\n\n    try:\n        await set_auto_top_up(\n            user_id, AutoTopUpConfig(threshold=request.threshold, amount=request.amount)\n        )\n    except ValueError as e:\n        raise HTTPException(status_code=422, detail=str(e))\n    return \"Auto top-up settings updated\"\n\n\n@v1_router.get(\n    path=\"/credits/auto-top-up\",\n    summary=\"Get auto top up\",\n    tags=[\"credits\"],\n    dependencies=[Security(requires_user)],\n)\nasync def get_user_auto_top_up(","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/v1.py#L758-L794","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const methods = await api.listPaymentMethods();\nif (methods.length === 0) await redirectToBillingPortal();","typeGuard":null,"tryCatchPattern":"try {\n  await api.configureAutoTopUp(config);\n} catch (e) {\n  if (e.status === 422) {\n    // detail is the raw ValueError: 'No payment method found',\n    // 'already exists for user', or 'must not be negative'\n    handleBillingError(e.detail);\n  } else throw e;\n}","preventionTips":["Ensure a default payment method exists before enabling top-up","Disable submit during in-flight requests","GET the existing config before configuring"],"tags":["billing","stripe","credits","http-422","payment-method"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}