# Railway API tokens: find, store, rotate, and use them safely with AI agents

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

Railway has account, workspace and project tokens. Account and workspace tokens are created on the tokens page in account settings (railway.com/account/tokens), and project tokens in project settings. In the CLI, `RAILWAY_TOKEN` is a project token and `RAILWAY_API_TOKEN` is an account or workspace token.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Account token | — | Yes | All your resources and workspaces (created with "No workspace" selected) | — |
| Workspace token | — | Yes | One workspace; cannot access personal resources or other workspaces | — |
| Project token | — | Yes | A single environment within a project | — |

## How to create a Railway key

1. For account or workspace tokens, open the tokens page in account settings (railway.com/account/tokens).
2. Create a token; choose "No workspace" for an account token or select a workspace for a workspace token.
3. For a project token, open the tokens page in project settings and create one for an environment.
4. Copy the token and store it as a secret.

## Limiting what the key can do

Choose the narrowest type: a project token for one environment, a workspace token for one workspace, or an account token for everything you own. OAuth access tokens from Login with Railway are limited to the scopes the user approved.

## How to rotate a Railway key

1. Create a new token of the same type.
2. Update `RAILWAY_TOKEN` or `RAILWAY_API_TOKEN` where it is used.
3. Delete the old token on the tokens page.

## How to revoke a Railway key

1. Open the tokens page (account settings or project settings) and delete the token.

## If the key leaked

1. Delete the exposed token on the tokens page.
2. Create a replacement of the narrowest type and update CI secrets.
3. Review recent deployments and variables for changes you did not make.

## Environment variables

- `RAILWAY_TOKEN`
- `RAILWAY_API_TOKEN`

## Gotchas

- Account and workspace tokens use `Authorization: Bearer`, while project tokens use the `Project-Access-Token` header.
- `RAILWAY_TOKEN` and `RAILWAY_API_TOKEN` are different token types; using the wrong one fails or limits what the CLI can do.

## 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.
- `http_request`: Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.
- `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.

## FAQ

### Where do I create a Railway API token?

At railway.com/account/tokens for account and workspace tokens, or the tokens page in project settings for project tokens.

### What is the difference between RAILWAY_TOKEN and RAILWAY_API_TOKEN?

`RAILWAY_TOKEN` is a project token for project-level actions; `RAILWAY_API_TOKEN` is an account or workspace token for account-level actions.

### How do I log in to the Railway CLI without a browser?

Run `railway login --browserless`.

### Can an AI agent use my Railway 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`, `http_request`, so the agent gets the result and never the value.

## Sources

- https://docs.railway.com/integrations/api
- https://docs.railway.com/cli
- https://docs.railway.com/ai/mcp-server
