openai api key issue in railway.com env
starlumenirupam
FREEOP

5 months ago

My code is working fine in local with valid openai api key .
but when i run the same in railway.com with same valid openai key.its provide error-.
I have set up variable (open ai api key) in railway.
I dont have any idea why its not working.
Thanks for support in advanced

Extracted 36 units from NKBA Kitchen Planning Guidelines.pdf

Processing 35 chunks...

ChromaDB will automatically generate embeddings using OpenAI...

Adding 35 chunks to collection...

Error adding to collection: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-svcac***********************************************************************************************************************************************************B44A. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

$10 Bounty

4 Replies

Railway
BOT

5 months 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!


starlumenirupam
FREEOP

5 months ago

This is not the solution. . Openai key is failing to validate from the railway environment


remi-choffat
PRO

5 months ago

If it works locally but fails on Railway with a 401 error, it's likely an issue with how the API key is set in Railway.

Double-check that your OPENAI_API_KEY is:

  • Set correctly in the Variables tab

  • Has no extra spaces (use .strip() in code)

  • Not being overridden later in your code
    You can try to print your key in your code just before sending it to the OpenAI API (in debug mode), to see if the key is exactly what is should be.


xardent
FREE

5 months ago

You are seeing this because incorrect api key provided, set correctly.

openai.api_key = os.getenv("OPENAI_API_KEY")


Loading...