8 months ago
Hi, I’m experiencing an issue with environment variables in my Railway deployment. Although I’ve set all necessary variables in the Variables tab (e.g., OPENAIAPIKEY), they don’t seem to be accessible in the runtime environment.
Here’s what I’ve done so far:
Verified that the variable OPENAIAPIKEY is correctly added in the Variables tab with the right value.
Logged all environment variables using os.environ.keys() in Python, but the OPENAIAPIKEY is missing.
Redeployed the service and cleared the build cache to ensure no caching issues.
Verified that my .env file is ignored in the repository using .gitignore.
The application works perfectly in my local environment when using dotenv and a .env file.
Logs: In the logs, I see this error:
ValueError: OPENAIAPIKEY not found in environment variables
Could this be an issue with how Railway handles environment variables in the runtime environment, or am I missing something in the setup?
Thank you for your help!
ⓘ Deployment information is only viewable by project members and Railway employees.
2 Replies
8 months ago
Hello,
Only 7 minutes ago you applied the changes to save the environment variables.
Since then I can see that you are no longer getting the ValueError: No OpenAI API key found in environment variables
error, instead you are getting the AttributeError: module 'openai' has no attribute 'OpenAI'
error.
Meaning the variable is found, but the OpenAI client is being initialized incorrectly.
Status changed to Solved brody • 9 months ago