{"record":{"id":"7a6a668f2d35463f","repo":"Significant-Gravitas/AutoGPT","slug":"amount-must-be-greater-than-or-equal-to-500","errorCode":null,"errorMessage":"Amount must be greater than or equal to 500","messagePattern":"Amount must be greater than or equal to 500","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"warning","filePath":"autogpt_platform/backend/backend/api/features/v1.py","lineNumber":753,"sourceCode":"    path=\"/credits/auto-top-up\",\n    summary=\"Configure auto top up\",\n    tags=[\"credits\"],\n    dependencies=[Security(requires_user)],\n)\nasync def configure_user_auto_top_up(\n    request: AutoTopUpConfig,\n    user_id: Annotated[str, Security(get_user_id)],\n    ctx: Annotated[RequestContext, Security(get_request_context)],\n) -> str:\n    \"\"\"Configure auto top-up settings and perform an immediate top-up if needed.\n\n    Raises HTTPException(422) if the request parameters are invalid or if\n    the credit top-up fails.\n    \"\"\"\n    if request.threshold < 0:\n        raise HTTPException(status_code=422, detail=\"Threshold must be greater than 0\")\n    if request.amount < 500 and request.amount != 0:\n        raise HTTPException(\n            status_code=422, detail=\"Amount must be greater than or equal to 500\"\n        )\n    if request.amount != 0 and request.amount < request.threshold:\n        raise HTTPException(\n            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\",","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/v1.py#L735-L771","documentation":"HTTP 422 from POST /credits/auto-top-up when AutoTopUpConfig.amount is below 500 (in credit cents, i.e. 5.00) and not 0. 0 is the explicit 'disable immediate top-up / amounts don't matter' sentinel; any non-zero top-up amount must be at least the 500-cent minimum because it maps to a real Stripe charge.","triggerScenarios":"Sending {\"threshold\": 1000, \"amount\": 300} or amount: 1 in the request body; any non-zero amount under 500.","commonSituations":"Treating amount as dollars instead of cents (5 sent instead of 500); copying test fixtures with tiny amounts; trying to set a custom small top-up granularity; forgetting that 0 is the only allowed sub-500 value.","solutions":["Send amount >= 500 (cents) or exactly 0 to disable immediate top-up","Double the unit: values are integer cents, so $5.00 is 500","Add a form hint/validation showing the minimum top-up is $5.00"],"exampleFix":"// before\n{ threshold: 1000, amount: 100 }\n\n// after\n{ threshold: 1000, amount: 500 }","handlingStrategy":"validation","validationCode":"const MIN_TOP_UP = 500; // cents\nif (amount !== 0 && amount < MIN_TOP_UP) throw new RangeError(\"amount must be 0 or >= 500 cents\");","typeGuard":"function isValidTopUpAmount(a: unknown): a is number {\n  return typeof a === \"number\" && a >= 0 && (a === 0 || a >= 500);\n}","tryCatchPattern":null,"preventionTips":["Remember amounts are integer cents, not dollars","Show a $5.00 minimum hint in the UI"],"tags":["validation","credits","auto-top-up","http-422"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}