{"record":{"id":"90b7353b0baaabda","repo":"Significant-Gravitas/AutoGPT","slug":"insufficient-balance-of-current-balance-100","errorCode":null,"errorMessage":"Insufficient balance of ${current_balance / 100}, where this will cost ${abs(amount) / 100}","messagePattern":"Insufficient balance of (.+?), where this will cost (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":402,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/v1.py","lineNumber":536,"sourceCode":"    user_id: Annotated[str, Security(get_user_id)],\n    ctx: Annotated[RequestContext, Security(get_request_context)],\n) -> CompletedBlockOutput:\n    obj = get_block(block_id)\n    if not obj:\n        raise HTTPException(status_code=404, detail=f\"Block #{block_id} not found.\")\n    if obj.disabled:\n        raise HTTPException(status_code=403, detail=f\"Block #{block_id} is disabled.\")\n\n    user = await get_user_by_id(user_id)\n    if not user:\n        raise HTTPException(status_code=404, detail=\"User not found.\")\n\n    try:\n        await execution_utils.charge_for_direct_block_execution(\n            user_id=user_id, block=obj, input_data=data, source=\"internal\"\n        )\n    except InsufficientBalanceError as e:\n        raise HTTPException(status_code=HTTP_402_PAYMENT_REQUIRED, detail=str(e)) from e\n\n    # Direct block execution has no graph; build a minimal ExecutionContext\n    # carrying the caller's identity + timezone so blocks that depend on\n    # those (e.g. time blocks) get correct data.\n    execution_context = ExecutionContext(\n        user_id=user_id,\n        user_timezone=get_user_timezone_or_utc(user.timezone),\n    )\n\n    start_time = time.time()\n    try:\n        output = defaultdict(list)\n        async for name, data in obj.execute(\n            data,\n            user_id=user_id,\n            execution_context=execution_context,\n        ):\n            output[name].append(data)","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/v1.py#L518-L554","documentation":"HTTP 402 raised by POST /blocks/{block_id}/execute when the user's credit balance is too low to pay for a direct (graph-less) block execution. execution_utils.charge_for_block_execution raises InsufficientBalanceError (a ValueError subclass in backend/util/exceptions.py), and the route maps it to 402 PAYMENT_REQUIRED. The detail message reports current balance and estimated cost, both divided by 100 because credits are stored as integer cents.","triggerScenarios":"Calling the direct block execution endpoint (e.g. POST /api/v1/blocks/{block_id}/execute) with an input that makes the block's computed execution cost exceed the user's current credit balance; e.g. an LLM block with an expensive model selected, or a large input, while the user's balance is near zero.","commonSituations":"New accounts with only the sign-up grace credits; auto-top-up not configured or its threshold set too low; long-running sessions that drained credits; running expensive models (e.g. premium LLM slugs) with a minimal balance; test environments where the credit table was seeded with 0.","solutions":["Top up credits via the billing/credits endpoint (POST /credits) or buy a subscription, then retry the execution","Enable auto top-up (POST /credits/auto-top-up) with a threshold above the typical cost of the blocks you run","Pick a cheaper block configuration/model so the execution cost fits the remaining balance","If you administer the platform: grant credits via grant_credits()/admin tooling for beta testers or refunds"],"exampleFix":"// before\nconst res = await fetch(`/api/v1/blocks/${blockId}/execute`, {...});\n// 402 {detail: \"Insufficient balance of 0.5, where this will cost 2.0\"}\n\n// after\nif (res.status === 402) {\n  await topUpCredits();\n  return retryExecute(blockId, input);\n}","handlingStrategy":"validation","validationCode":"const balance = (await api.getCredits()).balance; // cents\nconst estimated = await api.estimateBlockCost(blockId, input); // if available\nif (estimated > balance) {\n  await topUpOrPromptUser(estimated - balance);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(`/api/v1/blocks/${blockId}/execute`, opts);\n  if (res.status === 402) { /* prompt top-up, enable auto-top-up */ }\n} catch (e) { /* network error only */ }","preventionTips":["Keep auto top-up enabled with a threshold above typical block cost","Check GET /credits before running expensive blocks","Prefer cheaper models for exploratory runs"],"tags":["billing","credits","http-402","block-execution"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}