{"record":{"id":"b0eb12143d251bac","repo":"Significant-Gravitas/AutoGPT","slug":"amount-must-be-greater-than-or-equal-to-threshold","errorCode":null,"errorMessage":"Amount must be greater than or equal to threshold","messagePattern":"Amount must be greater than or equal to threshold","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"warning","filePath":"autogpt_platform/backend/backend/api/features/v1.py","lineNumber":757,"sourceCode":")\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\",\n            \"already exists for user\",\n            \"No payment method found\",\n        )\n        if any(msg in str(e) for msg in known_messages):","sourceCodeStart":739,"sourceCodeEnd":775,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/v1.py#L739-L775","documentation":"HTTP 422 from POST /credits/auto-top-up when a non-zero amount is smaller than the configured threshold. Auto top-up exists to restore the balance above the trigger level; topping up by less than the threshold would immediately re-trigger, so the route rejects it up front.","triggerScenarios":"Sending e.g. {\"threshold\": 2000, \"amount\": 1000} where both pass the minimum-500 rule but amount < threshold.","commonSituations":"Raising the threshold without raising the amount; thinking amount is the remaining-balance target rather than the increment; stale frontend state after editing threshold first.","solutions":["Set amount >= threshold (both non-zero), e.g. threshold 1000 / amount 1500","Use amount = 0 if you only want to record the threshold without an immediate top-up"],"exampleFix":"// before\n{ threshold: 2000, amount: 1000 }\n\n// after\n{ threshold: 2000, amount: 2500 }","handlingStrategy":"validation","validationCode":"if (amount !== 0 && amount < threshold) throw new RangeError(\"amount must be >= threshold\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Update amount and threshold together in the form","When raising the threshold, re-check the amount field"],"tags":["validation","credits","auto-top-up","http-422"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}