# Fly.io API tokens: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/fly-io
Last checked: 2026-10-25

Fly.io tokens are created with `fly tokens create`, for example `fly tokens create deploy` for one app or `fly tokens create org` for a whole organization. Tokens last 20 years by default, so Fly says to set the shortest `--expiry` that works. Provide a token to flyctl through the `FLY_API_TOKEN` environment variable.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| App deploy token | — | Yes | One app | 20 years by default; set `--expiry` (for example 48h) |
| Org token | — | Yes | All apps in one organization | 20 years by default; set `--expiry` |
| Read-only org token | — | Yes | Read an organization and its resources without changing them | 20 years by default; set `--expiry` |
| App SSH and machine-exec tokens | — | Yes | SSH into one app's Machines (plus the org's WireGuard network), or run restricted commands on them | 20 years by default; set `--expiry` |

## How to create a Fly.io key

1. Install flyctl and sign in with `fly auth login`.
2. Run `fly tokens create deploy --name "staging one" --expiry 48h` for an app, or `fly tokens create org --name prod --expiry 168h` for an organization.
3. Copy the printed token and store it as a secret; set it as `FLY_API_TOKEN` where it is used.

## Limiting what the key can do

Pick the narrowest token type: app-scoped deploy, SSH or machine-exec tokens for a single app, a read-only org token for read access, or an org token for everything in the org. Add `--expiry` to shorten the 20-year default. `fly auth token` returns a short-lived all-powerful token that Fly advises against using for deployments.

## How to rotate a Fly.io key

1. Create a new token with `fly tokens create` and a short `--expiry`.
2. Update `FLY_API_TOKEN` in your CI and local environments.
3. List tokens with `fly tokens list` (add `--scope org` for org tokens), then revoke the old one with `fly tokens revoke <token ID>`.

## How to revoke a Fly.io key

1. List tokens: `fly tokens list` for app tokens or `fly tokens list --scope org` for org tokens.
2. Revoke by ID with `fly tokens revoke <token ID>`.

## If the key leaked

1. Revoke the exposed token with `fly tokens revoke <token ID>`.
2. Create a replacement with the narrowest scope and a short expiry.
3. Update `FLY_API_TOKEN` in every place it was used.

## Environment variables

- `FLY_API_TOKEN`

## Gotchas

- Tokens last 20 years by default, so always pass `--expiry` unless you really want that.
- `fly auth token` is short-lived but all-powerful; Fly says not to use it for deployments.
- Org tokens manage every app in the org, so prefer app-scoped deploy tokens for CI.

## Using this key with AI agents (BotPassword)

- `list_credentials`: Lists the credentials this agent is granted and what it may do with each. Never values.
- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `cli_login`: Lets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
- `rotate`: Partly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
- `store_secret`: Saves a value the agent already holds as a new vault item.
- `capture_secret`: Planned, not built yet: will read a newly created key straight from the page or command output into the vault.

## FAQ

### How do I create a Fly.io deploy token?

Run `fly tokens create deploy --name "my token" --expiry 48h` in the app's directory or with `-a <app>`. Copy the printed token.

### Which environment variable does flyctl use for tokens?

`FLY_API_TOKEN`.

### How do I revoke a Fly.io token?

List tokens with `fly tokens list`, then run `fly tokens revoke <token ID>`.

### How long does a Fly.io token last?

20 years by default, unless you set `--expiry`.

### Can an AI agent use my Fly.io key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `list_credentials`, `run_with`, `store_secret`, so the agent gets the result and never the value.

## Sources

- https://docs.fly.io/security/tokens
- https://docs.fly.io/model-context-protocol
