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.
Railway key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Account token Keep private. Only account tokens work with the me query. | — | Yes | All your resources and workspaces (created with "No workspace" selected) | — |
| Workspace token Can be shared with teammates. | — | Yes | One workspace; cannot access personal resources or other workspaces | — |
| Project token Sent in the Project-Access-Token header rather than as a Bearer token. | — | Yes | A single environment within a project | — |
How to create a Railway key
- For account or workspace tokens, open the tokens page in account settings (railway.com/account/tokens).
- Create a token; choose "No workspace" for an account token or select a workspace for a workspace token.
- For a project token, open the tokens page in project settings and create one for an environment.
- 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
- Create a new token of the same type.
- Update
RAILWAY_TOKENorRAILWAY_API_TOKENwhere it is used. - Delete the old token on the tokens page.
Railway's API page does not document a roll flow, so this is create-then-delete.
How to revoke a Railway key
- Open the tokens page (account settings or project settings) and delete the token.
If your Railway key leaked
- Delete the exposed token on the tokens page.
- Create a replacement of the narrowest type and update CI secrets.
- Review recent deployments and variables for changes you did not make.
Environment variables and CLI
Railway's SDKs and docs read the key from RAILWAY_TOKEN or RAILWAY_API_TOKEN.
Railway CLI (railway): railway login (use railway login --browserless over SSH); for CI set RAILWAY_TOKEN (project) or RAILWAY_API_TOKEN (account/workspace)
Things that catch people out
- Account and workspace tokens use
Authorization: Bearer, while project tokens use theProject-Access-Tokenheader. RAILWAY_TOKENandRAILWAY_API_TOKENare different token types; using the wrong one fails or limits what the CLI can do.
Using your Railway 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 Railway 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. |
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. |
Railway 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
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.