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.
Fly.io key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| App deploy token Default name is flyctl deploy token. | — | Yes | One app | 20 years by default; set `--expiry` (for example 48h) |
| Org token Default name is Org deploy token. Examples in Fly's docs start with fm2_, but the docs do not state a prefix rule. | — | Yes | All apps in one organization | 20 years by default; set `--expiry` |
| Read-only org token Created with fly tokens create readonly. | — | Yes | Read an organization and its resources without changing them | 20 years by default; set `--expiry` |
App SSH and machine-exec tokensfly tokens create ssh and fly tokens create machine-exec --command "<command>". Machine-exec with no command allows all commands. | — | 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
- Install flyctl and sign in with
fly auth login. - Run
fly tokens create deploy --name "staging one" --expiry 48hfor an app, orfly tokens create org --name prod --expiry 168hfor an organization. - Copy the printed token and store it as a secret; set it as
FLY_API_TOKENwhere 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
- Create a new token with
fly tokens createand a short--expiry. - Update
FLY_API_TOKENin your CI and local environments. - List tokens with
fly tokens list(add--scope orgfor org tokens), then revoke the old one withfly tokens revoke <token ID>.
How to revoke a Fly.io key
- List tokens:
fly tokens listfor app tokens orfly tokens list --scope orgfor org tokens. - Revoke by ID with
fly tokens revoke <token ID>.
If your Fly.io key leaked
- Revoke the exposed token with
fly tokens revoke <token ID>. - Create a replacement with the narrowest scope and a short expiry.
- Update
FLY_API_TOKENin every place it was used.
Environment variables and CLI
Fly.io's SDKs and docs read the key from FLY_API_TOKEN.
flyctl (fly): fly auth login for interactive sign-in; use FLY_API_TOKEN in CI
Things that catch people out
- Tokens last 20 years by default, so always pass
--expiryunless you really want that. fly auth tokenis 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 your Fly.io key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Fly.io key, these intents fit:
| Intent | What BotPassword does |
|---|---|
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. |
Fly.io also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
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.