SDK / API ReferenceVault
Use Backup Code
Atomically consume one TOTP backup code
Scope: vault:write
Pop one single-use backup code from a TOTP credential. The popped code is moved from data.backupCodes to data.usedBackupCodes (kept as an audit trail) so it can never be returned again.
Use this when the live TOTP code is unavailable (clock skew, lost device).
Request
import { Loomal } from "@loomal/sdk";
const loomal = new Loomal({ apiKey: process.env.LOOMAL_API_KEY! });
const { code, remaining } = await loomal.vault.totpUseBackup("github-2fa");import os
from loomal import Loomal
loomal = Loomal(api_key=os.environ["LOOMAL_API_KEY"])
result = loomal.vault.totp_use_backup("github-2fa")loomal vault totp-use-backup github-2favault.totp_use_backup(name="github-2fa")Available through @loomal/mcp — see MCP setup.
curl -X POST https://api.loomal.ai/v0/vault/github-2fa/totp/backup \
-H "Authorization: Bearer loid-your-api-key"Response
{
"code": "abcd-1234",
"remaining": 7
}| Field | Type | Description |
|---|---|---|
code | string | The consumed backup code. Use it once and discard. |
remaining | number | Backup codes still unused after this call. |
Errors
| Status | Code | Description |
|---|---|---|
400 | bad_request | No unused backup codes remaining |
404 | not_found | Credential not found |
410 | expired | Credential has expired |
Notes
- The operation is atomic — concurrent calls cannot return the same code twice.
- Used codes are preserved under
data.usedBackupCodesand visible viaGET /v0/vault/:name. They are never returned byvault.totpor this endpoint. - To inspect remaining backup-code count without consuming one, call
GET /v0/vault/:name/totp(returnsbackupCodesRemaining) orGET /v0/vault/:name(returns the fulldata.backupCodesarray).