{"record":{"id":"11ca54f467e7e3fd","repo":"PrefectHQ/fastmcp","slug":"horizon-authentication-is-required","errorCode":null,"errorMessage":"Horizon authentication is required","messagePattern":"Horizon authentication is required","errorType":"exception","errorClass":"AuthenticationRequiredError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/cli/deploy/command.py","lineNumber":315,"sourceCode":"        \"login\",\n        user,\n        json_output=json_output,\n    )\n\n\nasync def whoami(\n    *,\n    json_output: JsonOption = False,\n) -> None:\n    \"\"\"Show the current Prefect Horizon user.\"\"\"\n    credentials = CredentialStore()\n    configuration: HorizonConfiguration | None = None\n    credential: ResolvedCredential | None = None\n\n    try:\n        configuration, credential = _load_session_snapshot(credentials)\n        if credential is None:\n            raise AuthenticationRequiredError(\"Horizon authentication is required\")\n        user = await _get_user(\n            configuration.api_origin,\n            credential,\n        )\n    except HorizonUnauthorizedError as error:\n        if (\n            configuration is not None\n            and credential is not None\n            and credential.source == \"stored\"\n        ):\n            try:\n                credentials.clear_if_matches(\n                    credential.api_key,\n                    expected_api_origin=configuration.api_origin,\n                )\n            except StateFileError as cleanup_error:\n                _fail_for_expected_error(\n                    \"whoami\",","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/cli/deploy/command.py#L297-L333","documentation":"whoami() loads the session snapshot and, if no credential (API key) is stored, raises AuthenticationRequiredError('Horizon authentication is required') instead of calling the user endpoint without auth.","triggerScenarios":"Running `fastmcp deploy whoami` (or calling whoami) before ever running `login`, or after the credentials file was deleted/corrupted such that no credential resolved.","commonSituations":"Fresh machines/CI environments without logged-in sessions; manually cleared credentials; HOME differences between shells pointing at a different credentials path.","solutions":["Run `fastmcp deploy login` to authenticate, then retry whoami","Verify the credentials file exists at the expected path (check HOME/env differences)","In scripts, call login() programmatically before whoami()"],"exampleFix":"// before\nuser = await whoami(credentials)  # AuthenticationRequiredError\n// after\nawait login(client, host=host)\nuser = await whoami(credentials)","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\ncred_path = Path.home() / \".fastmcp\" / \"horizon-credentials.json\"\nlogged_in = cred_path.exists()","typeGuard":null,"tryCatchPattern":"from fastmcp.cli.deploy.command import AuthenticationRequiredError\ntry:\n    user = await whoami(credentials)\nexcept AuthenticationRequiredError:\n    await login(host=host)\n    user = await whoami(credentials)","preventionTips":["Run `fastmcp deploy login` before commands that need auth","Don't delete or overwrite the credentials file in cleanup scripts","Check HOME/config-dir differences when running in CI or containers"],"tags":["cli","authentication","missing-credentials"],"backgroundTag":"authentication-required","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}