Cloud and hosting

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

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

TypePrefixSecret?ScopeExpiry
App deploy token
Default name is flyctl deploy token.
—YesOne app20 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.
—YesAll apps in one organization20 years by default; set `--expiry`
Read-only org token
Created with fly tokens create readonly.
—YesRead an organization and its resources without changing them20 years by default; set `--expiry`
App SSH and machine-exec tokens
fly tokens create ssh and fly tokens create machine-exec --command "<command>". Machine-exec with no command allows all commands.
—YesSSH into one app's Machines (plus the org's WireGuard network), or run restricted commands on them20 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 your Fly.io 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 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 --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 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:

IntentWhat BotPassword does
list_credentialsLists the credentials this agent is granted and what it may do with each. Never values.
run_withRuns 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_loginLets 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.
rotatePartly 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_secretSaves a value the agent already holds as a new vault item.
capture_secretPlanned, 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.

Stop pasting Fly.io keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.