{"record":{"id":"f1d52aaeb5803e9c","repo":"home-assistant/core","slug":"client-name-is-required-for-long-lived-access-toke","errorCode":null,"errorMessage":"Client_name is required for long-lived access token","messagePattern":"Client_name is required for long-lived access token","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"homeassistant/auth/__init__.py","lineNumber":494,"sourceCode":"\n        if token_type is models.TOKEN_TYPE_NORMAL:\n            expire_at = time.time() + REFRESH_TOKEN_EXPIRATION\n        else:\n            expire_at = None\n\n        if user.system_generated != (token_type == models.TOKEN_TYPE_SYSTEM):\n            raise ValueError(\n                \"System generated users can only have system type refresh tokens\"\n            )\n\n        if token_type == models.TOKEN_TYPE_NORMAL and client_id is None:\n            raise ValueError(\"Client is required to generate a refresh token.\")\n\n        if (\n            token_type == models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN\n            and client_name is None\n        ):\n            raise ValueError(\"Client_name is required for long-lived access token\")\n\n        if token_type == models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN:\n            for token in user.refresh_tokens.values():\n                if (\n                    token.client_name == client_name\n                    and token.token_type == models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN\n                ):\n                    # Each client_name can only have one\n                    # long_lived_access_token type of refresh token\n                    raise ValueError(f\"{client_name} already exists\")\n\n        return await self._store.async_create_refresh_token(\n            user,\n            client_id,\n            client_name,\n            client_icon,\n            token_type,\n            access_token_expiration,","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/auth/__init__.py#L476-L512","documentation":"Thrown by AuthManager.async_create_refresh_token (homeassistant/auth/__init__.py:494) when creating a TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN without a client_name. Long-lived tokens are surfaced in the UI by name, so the name is required and doubles as the uniqueness key.","triggerScenarios":"Calling async_create_refresh_token(user, token_type=models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN, client_name=None).","commonSituations":"API wrappers that omit client_name; porting scripts that used only client_id for normal tokens.","solutions":["Provide a descriptive client_name, e.g. client_name=\"My script\"","Ensure it is unique among the user's existing long-lived token names to avoid the '{client_name} already exists' error next"],"exampleFix":"// before\nawait hass.auth.async_create_refresh_token(\n    user, token_type=models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN\n)\n\n# after\nawait hass.auth.async_create_refresh_token(\n    user,\n    token_type=models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN,\n    client_name=\"My script\",\n)","handlingStrategy":"validation","validationCode":"if token_type == models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN:\n    assert client_name\nawait hass.auth.async_create_refresh_token(\n    user, token_type=token_type, client_name=client_name\n)","typeGuard":"def long_lived_ready(token_type, client_name) -> bool:\n    return token_type is not models.TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN or bool(client_name)","tryCatchPattern":null,"preventionTips":["Treat client_name as a required field in any long-lived token UI or CLI","Default it to a descriptive name so users can recognize the token later"],"tags":["auth","python","home-assistant","long-lived-token","valueerror"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}