Significant-Gravitas/AutoGPT · warning · HTTPException

Threshold must be greater than 0

Error message

Threshold must be greater than 0

What it means

HTTP 422 from POST /credits/auto-top-up when AutoTopUpConfig.threshold is negative. The route requires threshold >= 0 (0 disables the trigger); a negative threshold would make the top-up condition meaningless, so it is rejected before any credit model call. Note the message says 'greater than 0' but the actual check is < 0, so 0 itself is accepted.

Source

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

@v1_router.post(
    path="/credits/auto-top-up",
    summary="Configure auto top up",
    tags=["credits"],
    dependencies=[Security(requires_user)],
)
async def configure_user_auto_top_up(
    request: AutoTopUpConfig,
    user_id: Annotated[str, Security(get_user_id)],
    ctx: Annotated[RequestContext, Security(get_request_context)],
) -> str:
    """Configure auto top-up settings and perform an immediate top-up if needed.

    Raises HTTPException(422) if the request parameters are invalid or if
    the credit top-up fails.
    """
    if request.threshold < 0:
        raise HTTPException(status_code=422, detail="Threshold must be greater than 0")
    if request.amount < 500 and request.amount != 0:
        raise HTTPException(
            status_code=422, detail="Amount must be greater than or equal to 500"
        )
    if request.amount != 0 and request.amount < request.threshold:
        raise HTTPException(
            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:

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Send threshold >= 0; use 0 to trigger a top-up whenever the balance is at or below zero
  2. Add client-side validation to the settings form so the threshold field cannot be negative
  3. If you intended 'always top up', set threshold to 0 and amount to your desired top-up size

Example fix

// before
{ threshold: -1, amount: 500 }

// after
{ threshold: 0, amount: 500 }
Defensive patterns

Strategy: validation

Validate before calling

if (threshold < 0) throw new RangeError("threshold must be >= 0");

Type guard

function isValidThreshold(t: unknown): t is number {
  return typeof t === "number" && t >= 0;
}

Prevention

When it happens

Trigger: Sending {"threshold": -1, "amount": 500} (or any negative threshold) in the auto top-up config request body.

Common situations: Sentinel values like -1 intended to mean 'always top up'; unit tests passing edge values; a frontend form allowing negative numbers without validation; serializing an unset/None field as -1.

Related errors


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