Skip to main content
Two-factor authentication (2FA) adds a second layer of security to your account. After logging in with your API key, CLI commands that require sensitive actions verify your identity using a code from your phone or email.

Supported Methods


Setting Up 2FA

Setting up 2FA requires three steps: authorize the addition of a new method, configure the method, then activate it with a verification code.

Step 1: Authorize a new method

Before adding any 2FA method, authorize your account. For your first method, authorization uses email by default. For subsequent methods, use an existing 2FA method.
When prompted, enter the code sent to your email (or existing 2FA method). If you exit before completing, resume with:

Step 2: Configure the method

For Authenticator App (TOTP):
This displays a QR code and a manual entry key. Scan the QR code or type the key into your authenticator app. For SMS:
A 6-digit code is sent to the specified phone number, and a secret token is returned. If the code expires, use vastai tfa resend-sms --secret <SECRET>.
Email is not a 2FA method you add in this step — it is the verification channel used by tfa auth-new (Step 1) to authorize adding your first method (TOTP or SMS).

Step 3: Activate the method

After activating your first 2FA method, backup codes are generated and displayed. Save these backup codes in a secure location — they are the only way to recover access if you lose your 2FA device.

Logging In with 2FA

If your account has 2FA enabled and your session key has expired, use tfa login to re-authenticate:
On success, the session key is saved to ~/.config/vastai/vast_tfa_key. The CLI uses this session key for subsequent authenticated requests. If this file is deleted or the session expires (returns a 404), run tfa login again.

Managing Methods

View current status

Shows whether 2FA is enabled, lists all active methods with their IDs, and shows the number of remaining backup codes.

Update a method

Use the method ID from vastai tfa status.

Delete a method

Warning: Deleting your last 2FA method fully disables 2FA and invalidates all backup codes.

Backup Codes

Backup codes let you log in if you lose access to your 2FA device. Each code is one-time use.

Regenerate backup codes

Warning: Regenerating codes invalidates all existing backup codes immediately. Save the new codes in a secure location — they are not shown again.

Session Key Lifecycle

After a successful tfa login, a session key is saved to ~/.config/vastai/vast_tfa_key (or $XDG_CONFIG_HOME/vastai/vast_tfa_key if XDG_CONFIG_HOME is set). The CLI automatically uses this key for authenticated requests. The session key expires after inactivity. When it expires, affected CLI commands return a 404 error. Run vastai tfa login to get a new session key.

Error Reference


See Also