invoke-ai/InvokeAI · error · HTTPException

User not found

Error message

User not found

What it means

get_current_user_info looks up the authenticated user's id via user_service.get(); if the store returns None it raises 404 'User not found'. Per the docstring this 'should not happen normally' — the auth dependency validated the token, but the underlying user record disappeared.

Source

Thrown at invokeai/app/api/routers/auth.py:347

def get_current_user_info(
    current_user: CurrentUser,
) -> UserDTO:
    """Get current authenticated user's information.

    Args:
        current_user: The authenticated user's token data

    Returns:
        UserDTO containing user information

    Raises:
        HTTPException: 404 if user is not found (should not happen normally)
    """
    user_service = ApiDependencies.invoker.services.users
    user = user_service.get(current_user.user_id)

    if user is None:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")

    return user


@auth_router.post("/setup", response_model=SetupResponse)
def setup_admin(
    request: Annotated[SetupRequest, Body(description="Admin account details")],
) -> SetupResponse:
    """Set up initial administrator account.

    This endpoint can only be called once, when no admin user exists. It creates
    the first admin user for the system.

    Args:
        request: Admin account details (email, display_name, password)

    Returns:
        SetupResponse containing the created admin user

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Re-login to obtain a token bound to an existing user (old token will keep failing)
  2. Recreate the user with that id, or re-run /auth/setup to recreate the admin
  3. If the DB was replaced, clear old tokens on clients
  4. Check the users backend didn't get swapped/reset between requests
Defensive patterns

Strategy: try-catch

Validate before calling

# verify the token still maps to a live user before relying on /auth/me
def token_user_missing(user: object | None) -> bool:
    return user is None  # if a lookup returns None, the token's user_id is stale

Type guard

def user_exists(user: object | None) -> bool:
    return user is not None and hasattr(user, 'user_id')

Try / catch

try:
    resp = requests.get(f'{base}/auth/me', headers={'Authorization': f'Bearer {token}'})
    resp.raise_for_status()
except requests.HTTPError as e:
    if e.response.status_code == 404:
        clear_stored_token()
        relogin()  # token points to a deleted user; start a fresh session

Prevention

When it happens

Trigger: GET /auth/me with a valid token whose user_id no longer exists in the users store (user deleted after token issuance, users DB replaced/reset).

Common situations: Admin deleted the user while their client still holds a valid token; database file swapped/recreated (fresh setup) while old tokens remain in a browser; multiuser store corruption or a different backend between requests.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/9b3b0f342b1c3937. Report an issue: GitHub.