# How to give an AI agent one-time codes without the TOTP seed

> Store the TOTP seed as a secret, bind it to a TOTP service, and let the agent request a code with totp.generate without receiving the seed.

Store the TOTP seed as a secret, bind it to a TOTP service, and give the agent a service-only credential. The agent asks Guardry for a code with the `totp.generate` operation and receives the current code, never the seed. The code is itself sensitive for the short time it is valid.

## Why the seed should stay in the vault

A TOTP seed is the long-lived half of the arrangement. Whoever holds it can produce valid codes for as long as that seed is in use. A code is valid only for a short time. Giving an agent a code when it needs one hands over far less than giving it the seed.

## 1. Store the seed

Add the base32 seed to the vault as a secret, for example `BILLING_TOTP_SEED`. Keep it a secret, not a variable, because a variable is visible to every agent credential that covers its environment.

## 2. Bind the seed to a TOTP service

In the dashboard, bind the stored secret to a TOTP service. The seed stays where it is.

## 3. Create a service-only credential

Under Agent access, create an agent credential with the permission to use assigned services without ever receiving their credentials, and assign the TOTP service. Leave the permissions that read secret values off, and pick a short lifetime. The credential is shown once.

```sh
# Paste the credential at the hidden prompt
guardry login --profile coding-agent
```

## 4. Request and generate a code

```sh
# Find the ID of the assigned service
guardry services list

# Ask for approval to generate a code
guardry grants request --service SERVICE_ID --operation totp.generate --purpose "Sign in to the billing sandbox" --minutes 5

# Check whether a person has approved or denied it
guardry grants status GRANT_ID

# Generate the code; the seed stays in the vault
guardry services execute SERVICE_ID --grant GRANT_ID
```

You approve or deny the request in the dashboard. The approval expires and has a use limit.

## 5. Handle the code as a secret

A TOTP code is itself sensitive for the short time it is valid. The agent should use it straight away and should not print it into the conversation or a log.

## What this does not do

- It does not automate the rest of a login. Guardry returns a code. Entering the user name, the password and the code into the site is still the agent's work, and any password it needs is a separate secret with its own permission.
- It does not stop a credential with a read permission from reading the seed. If any agent credential can read the entry, that agent can receive the seed and copy it. The dashboard shows, for every entry, which agents can reach it and how.
- TOTP codes are the only short-lived credentials Guardry generates. It does not create dynamic provider credentials on demand.

## Questions

### Can the agent read the TOTP seed?

Not with a service-only credential. The agent asks Guardry to generate a code and never receives the stored seed. Check the entry's agent reach in the dashboard to confirm that no other credential can read it.

### Is a one-time code safe to show in a chat or a log?

No. A TOTP code is itself sensitive for the short time it is valid. The agent should use the code at once and not print it.

### Does Guardry complete the login for the agent?

No. Guardry generates the one-time code from the stored seed. It does not automate the rest of the login.

### Can a person approve each code before the agent gets it?

Yes. The agent asks with `guardry grants request`, and a person approves or denies the request in the dashboard. The approval expires and has a use limit.

---

Source: https://guardry.ai/guides/totp-codes-for-ai-agents/ · Updated 2026-11-27 · Guardry for language models: https://guardry.ai/llms.txt
