KeyError: 'ANTHROPIC_API_KEY'
naydanova
HOBBYOP

11 days ago

I've spent several hours debugging a backend service (FastAPI on Python 3.13) where environment variables set in the Variables tab — and confirmed via Raw Editor — are not actually received by the running process at startup. I verified this directly inside the app via a debug endpoint that reads os.environ.

Initial symptom (Free plan):

ADZUNA_APP_ID, ADZUNA_APP_KEY, and RAPIDAPI_KEY were visible in Variables but caused KeyError at runtime, while ANTHROPIC_API_KEY and ALLOWED_ORIGINS worked fine. I assumed this might be some Free plan limitation on the number of variables or similar restriction, so I upgraded to Pro.

After upgrading to Pro: The problem got worse, not better. I deleted and recreated the service, then deleted and recreated the entire project. On the new project/service (new domain, freshly connected from the same GitHub repo), even ANTHROPIC_API_KEY — which always worked before — now also fails with KeyError at runtime, despite being visible in the Variables UI immediately after adding it and after an explicit manual redeploy.

Things I tried, none of which fixed it:

Recreating variables via the standard + New Variable form

Recreating variables via Raw Editor

Removing quotes around values

Manual Redeploy

Manual Restart

Deleting and recreating the service

Deleting and recreating the entire project

Upgrading from Free to Pro plan

This is blocking a production app with real users waiting on a fix. Any help figuring out why Variables aren't reaching the runtime would be hugely appreciated.

0 Replies

Welcome!

Sign in to your Railway account to join the conversation.

Loading...