Colored pencil drawing of a walled kitchen garden: a green wooden door in a coral brick wall is held shut by an iron bar latch and a brass hook latch, while a stone channel carries water through a small arch at the foot of the wall to rows of seedlings on the other side
All posts

MFA for an AI API account: what it protects, and how not to lock yourself out

Two-factor authentication on an AI API platform guards the console, not the API keys your services run on. How AIVAX separates the two, why a second authenticator is the backup, and what account recovery still asks for.

One of the most-read MFA threads on the OpenAI developer forum this year comes from a developer who lost the authenticator app on their phone while still signed in on a laptop, and found that every way out, from adding a passkey to switching MFA off, asked for the code they no longer had. The thread has 88 replies and more than 3,600 views. Around it sit dozens of variations: locked out of both ChatGPT and the API after losing the device and the recovery codes, locked out after a forced sign-out with the authenticator as the only factor.

We read these threads while building two-factor authentication for the AIVAX console, which shipped in October. Our impression is that people turn on MFA for their API account expecting it to protect something it mostly does not touch, and that the lockout risk is decided on the day they enroll, long before the day they lose the phone.

An API key never sees the second factor

On an AI API platform, the credential that costs you money when it leaks is the API key. It lives in environment variables and CI secrets, and sometimes in a public repository. A second factor cannot protect it, because a server calling /v1/chat/completions at three in the morning has nobody to type a six-digit code. So on AIVAX, API keys keep working with no login key and no authenticator code. The authentication docs state it directly: a login key only opens a console session.

If your worry is the forum post about a leaked key that ran up $300 of bot usage, MFA will not help with it. Give each application its own key with an expiration date, so a leak means revoking one key, and watch spend per call so the leak shows up within hours instead of on the invoice. Reading the cost of each LLM API call from the response headers is how we suggest doing the second part. The same thinking applies when a third party holds the key, whether that is a discounted Claude provider or relay or an MCP server you connect to an agent.

MFA protects the console, where someone can create keys and switch security settings off. That is still worth guarding, because whoever holds the console holds every key it can mint.

A leaked private key cannot mint keys or touch 2FA

The question we would put to any provider is what a stolen API key can do to the account itself. If it can create a fresh key, the attacker survives your revocation, and if it can remove the authenticator, the second factor protects nothing.

On AIVAX, a private key (sk-aiv-acc) reaches every account API except credential management. Since a permissions change on November 2, it cannot manage API keys, authenticators or the login key. Those routes need a console session, and the console session is what 2FA guards. We ran this with a private key against the live API:

curl -H "Authorization: Bearer $AIVAX_API_KEY" \
  https://inference.aivax.net/api/v1/accounts/security
{"error":"This API key does not have the permissions required by this resource: ManagementKeys.","details":null}

The status is 403 Forbidden. A leaked key can still spend, which is why the controls above matter, but it cannot lock you out or plant a replacement key. Public keys (pk-aiv-) are narrower again, limited to inference, generations and RAG retrieval; the key types table lists what each one reaches.

The backup is a second authenticator

Most lockout stories share a shape: one authenticator on one phone, and a recovery path that asks for that same authenticator. AIVAX uses standard TOTP (RFC 6238, six digits, 30-second steps, SHA-1), so any authenticator app works, and an account can hold several at once. A code from any confirmed authenticator signs you in.

Our recommendation is to enroll two on the first day: the app on your phone plus a password manager that stores TOTP secrets, or two phones that do not back up to the same cloud account. Adding the second one later requires a code from the first, so the window for a painless backup closes when the first phone is lost.

Setup lives in My account, Security in the console, or in the AIVAX CLI on a profile that signed in with the login key:

aivax account security totp-setup --name "Phone"
aivax account security totp-confirm --code 123456

aivax account security totp-setup --name "Password manager"
aivax account security totp-confirm --code 654321 --current-code 112233

aivax account security status

totp-setup returns the secret and the otpauth:// URI once. The pending secret expires after ten minutes and is stored only when a valid code confirms it, so an abandoned setup leaves nothing half-enrolled. After confirmation the secret cannot be read back from the console or the API; status returns names and creation dates only. If you want a copy in the password manager, take it during setup.

A CLI profile linked with --api-key gets the same 403 for these commands. We think that is the right trade for coding agents: one you hand an API key to can operate the account, and sign-in stays with the people who have the login key and an authenticator.

E-mail recovery resets the login key and leaves 2FA on

AIVAX signs into the console with a login key sent by e-mail rather than a password. If you lose the login key, Recover login key on the sign-in page sends two links to the registration address, both valid for one hour. One is a one-time sign-in link. The other creates a new login key, e-mails it and signs out every console session. The recovery section of the docs has the whole flow.

Neither link turns two-factor authentication off. The sign-in link still asks for an authenticator code, and the reset link leaves the authenticators where they were. We built it that way on purpose: someone who gets into your mailbox should not be able to strip the second factor with a link sent to that mailbox. The cost is that e-mail alone will not rescue an account whose only authenticator is gone. Disabling 2FA without a current code goes through AIVAX support.

A code can also fail with the phone in your hand. The server accepts the code for the current 30-second step and one step either side, so a phone clock a few seconds off is fine and one several minutes off is not. Code attempts are capped at eight per account in 15 minutes, which stops guessing and also means that retrying a wrong code from a drifting clock will close the prompt for a while.

Unattended jobs should not hold a TOTP secret

The CLI asks for the code when the account needs it, or takes it with --2fa when nobody is at the keyboard:

aivax auth login --login-key "$AIVAX_LOGIN_KEY" --2fa 123456 --profile-name main

If you build your own console client, POST /api/v1/auth/login with only the login key returns requiresTwoFactor: true and creates no session. Send the same login key again with totpCode to get the 180-day console token:

{ "loginKey": "<LOGIN_KEY>", "totpCode": "123456" }

Both paths expect a person with the authenticator. For anything unattended, use an API key instead. A cron job that produces a fresh TOTP code on every run has the TOTP secret stored next to it, and a secret stored next to the job is no longer a second factor.

Checked against the AIVAX implementation, the CLI 1.1 source and the authentication docs on November 16, 2026. The 403 for a private key was observed against the live API on the same date, and the forum view and reply counts were read then too.