API keys not recognized when accessed through SECRETS

When accessing an API key in the SECRETS section in python code, it is not recognized when trying to access the 3rd party app

When accessing the key via my_secret = os.environ[‘OPENAI_API_KEY’] it is not recognized by OpenAI. If the key is pasted directly my_secret = st123etc… it works as expected

Actual behavior:

Steps to reproduce:

Bug appears at this link:


Hi @AssafCohen2!

Could you try either using an if statement to compare the two keys or print out the environment variable? The API key you specified may be incorrect, hence why it isn’t working.

(Something like this should do)

key = "thisIsMyKey123"
environment_var = os.environ['OPENAI_API_KEY']

if key != environment_var:
    print("API keys dont match")

You don’t really need an else statement because nothing will output if the key’s don’t match.

You probably want to clear your code history so people can’t find your api key


Yeah, that’s a good point, I should add to my previous reply.

To make sure malicious users don’t find/steal your key, you should try what I suggested in the Console so it doesn’t show up in your code history. (The Console acts as a Python REPL when your program is not executing)


are you trying to have other people access your token from console? Because replit deletes it if the user is not the owner for your safety