Significant-Gravitas/AutoGPT · error · HTTPException

User not found.

Error message

User not found.

What it means

Raised (HTTP 404) by the external execute-block endpoint when the API key's `auth.user_id` does not resolve to a user via `user_db.get_user_by_id`. Authentication succeeded (a valid API key), but the backing user record is gone or unreachable, so execution cannot proceed (user record is needed for timezone and billing identity).

Source

Thrown at autogpt_platform/backend/backend/api/external/v1/routes.py:110

        require_permission(APIKeyPermission.EXECUTE_BLOCK)
    ),
) -> CompletedBlockOutput:
    # Sync block exec doesn't pass through ``add_graph_execution`` (no
    # central enqueue), and external API routes use API-key auth instead
    # of JWT so the JWT-based dep doesn't apply either. Inline strict
    # gate with the same fail-closed (503-on-blip) posture as the dep —
    # consistent with chat / internal block / internal graph routes.
    await enforce_payment_paywall(auth.user_id)

    obj = backend.blocks.get_block(block_id)
    if not obj:
        raise HTTPException(status_code=404, detail=f"Block #{block_id} not found.")
    if obj.disabled:
        raise HTTPException(status_code=403, detail=f"Block #{block_id} is disabled.")

    user = await user_db.get_user_by_id(auth.user_id)
    if not user:
        raise HTTPException(status_code=404, detail="User not found.")

    try:
        await charge_for_direct_block_execution(
            user_id=auth.user_id, block=obj, input_data=data, source="external"
        )
    except InsufficientBalanceError as e:
        raise HTTPException(
            status_code=status.HTTP_402_PAYMENT_REQUIRED, detail=str(e)
        ) from e

    # Direct block execution has no graph; build a minimal ExecutionContext
    # carrying the caller's identity + timezone so blocks that depend on
    # those (e.g. time blocks) get correct data.
    execution_context = ExecutionContext(
        user_id=auth.user_id,
        user_timezone=get_user_timezone_or_utc(user.timezone),
    )

View on GitHub (pinned to 9c8bb5550f)

Solutions

  1. Issue a new API key from an active user account and use that.
  2. If you operate the platform, clean up API keys when users are deleted so keys can't outlive their owners.
  3. Check the auth user id tied to the key (backend logs) and restore/recreate the user if the key must keep working.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    client.post(f"/blocks/{block_id}/execute", json=data)
except HTTPError as e:
    if e.response.status_code == 404 and "User not found" in e.response.text:
        raise OrphanedApiKey("re-issue the API key from an active account") from e
    raise

Prevention

When it happens

Trigger: POST `/blocks/{block_id}/execute` with an API key whose owner account was deleted, anonymized, or whose user row is missing due to a DB issue.

Common situations: API key survives user deletion (orphaned key); Supabase user removed without cleaning up API keys; test environments with keys pointing at seeded users that were wiped.

Related errors


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