Overview
HAPI CLI uses theCLI_API_TOKEN to authenticate with the HAPI hub. Authentication commands help you configure and manage this token.
Token Priority
Tokens are loaded in the following order (highest to lowest priority):CLI_API_TOKENenvironment variable- Token saved in
~/.hapi/settings.json(viahapi auth login) - Interactive prompt on first run
Commands
hapi auth status
Display current authentication configuration and token status.Output Example
When Token Is Missing
hapi auth login
Interactively enter and save yourCLI_API_TOKEN to the settings file.
This command requires an interactive TTY. For non-interactive environments, use the
CLI_API_TOKEN environment variable instead.Interactive Prompt
Token Storage
The token is saved to~/.hapi/settings.json (or $HAPI_HOME/settings.json if HAPI_HOME is set):
hapi auth logout
Clear saved credentials (token and machine ID) from the local settings file.Output Example
Getting Your Token
There are several ways to obtain yourCLI_API_TOKEN:
1. From Server Startup Logs
When the HAPI hub starts for the first time, it generates and displays the token:2. From Server Settings File
On the server machine, read~/.hapi/settings.json:
3. From Environment Variable
If your administrator set the token via environment variable, ask them for the value:Using Environment Variables
For automation or CI/CD, set the token directly as an environment variable:In Shell Configuration
Add to your~/.bashrc, ~/.zshrc, or equivalent:
In CI/CD
Machine ID
The machine ID uniquely identifies your computer to the HAPI hub. It’s automatically generated on first connection.Viewing Machine ID
Clearing Machine ID
The machine ID is cleared when you runhapi auth logout:
Multiple Namespaces
If you use multiple HAPI hubs or namespaces, each needs its own machine ID. Use separateHAPI_HOME directories:
Troubleshooting
Authentication Error
If you see “Authentication error” or “Unauthorized”:-
Verify token is set:
-
Re-login with correct token:
-
Check hub URL:
Machine Access Denied
If you see “Machine access denied”:-
Logout and re-login:
-
Or use separate HAPI_HOME:
Non-TTY Environment
If you see “Cannot prompt for token in non-TTY environment”:Security Best Practices
Do:
- Store tokens securely (use secrets managers in CI/CD)
- Use separate tokens per environment (dev/staging/prod)
- Rotate tokens periodically
- Use environment variables for automation
Don’t:
- Commit tokens to version control
- Share tokens in plain text
- Use the same token across different systems
- Log or display tokens in output
Help
View authentication help:Next Steps
- Environment Variables - Configure hub URL and more
- Settings File - Understand the settings.json structure
- Session Commands - Start your first session