CLI returns unauthorized on railway up with token
elter71
PROOP

a month ago

Hello Railway Support,

I’m encountering persistent unauthorized errors when deploying via the CLI with a token.

Steps to Reproduce

  1. railway logout && rm -rf ~/.config/railway (to clear state)

  2. export RAILWAY_TOKEN="$(printf %s "<TOKEN>")"

  3. railway whoami

  4. railway up -v

Expected Result

  • railway whoami should succeed (for user token) and railway up should deploy successfully.

  • For a deploy token, railway up should work in a linked directory.

Actual Result

  • railway whoamiunauthorized

  • railway upunauthorized (no additional actionable detail)

Troubleshooting Tried

  • Cleared auth state: railway logout and removed ~/.config/railway

  • Ensured token has no trailing newline (used printf), verified env var present

  • Updated CLI to latest and re-tested

  • Verified project link: .railway/project.json present (railway link <PROJECT_ID>)

  • Selected environment/service explicitly: railway environment <ENV> and railway up --service <SERVICE>

  • Checked system time sync and disabled proxy/mitm temporarily

When I use railway login everything works fine.

Questions

  1. Is it expected that deploy/service tokens return unauthorized for whoami? (If so, can you confirm the minimal required context for railway up to succeed with such tokens?)

  2. Can you verify on your side whether this token is valid/not revoked and mapped to the project/environment above?

  3. Are there any recent permission/scope changes to tokens that could cause this behavior?

Happy to provide additional logs or run any debug builds if helpful.
Thanks in advance!

$10 Bounty

6 Replies

Railway
BOT

a month ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


brody
EMPLOYEE

a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody about 1 month ago


fra
HOBBY

a month ago

Is this a project token or an account token?

Whoami doesn't work with project tokens:

https://docs.railway.com/guides/cli

Can you try passing the token manually?

RAILWAY_TOKEN=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX railway up

Just to check if for any reason the var is not taken if exported?


thereis
PRO

a month ago

I tried both, adding to the action env var and also the inline declaration; neither is working.


hey, so your errors are happening bc you're incorrectly passing the RAILWAY_TOKEN, it should be RAILWAY_API_TOKEN for whoami (for your steps to reproduce). try exporting the token directly in shell

export RAILWAY_API_TOKEN=XXXXXXXXXX

railway whoami

npx railway up --service <SERVICE_NAME> or railway up --service <SERVICE_NAME>


tuergeist
PRO

23 days ago

I am getting Unauthorized for a freshly created token. RAILWAY_API_TOKEN=xxxxxxxx railway whoami

(no RAILWAY_* env var set)


elter71
PROOP

15 days ago

Any update here ?


Loading...