How to Create a Environment Variable to Store OpenAI API Key

I am new to retool so help me here :slightly_smiling_face:
I am using python sdk to access openai models in the workflow code block but I don't know how to add an environment variable to store API key then access it in the retool workflow.

Hi @Shirina

If you're calling the Workflow from an App, you can store the API key into the global JS in settings, such as window.openaiKey = 'your key' and in the query call just pass it as parameter.

While for scheduled Workflow, I guess the only way is to put the key in the block that is making the OpeAI request.

Hope this help.

Hi @abusedmedia
Thank you for replying.
Just to be clear, if I add the key this way, it will be visible to others users (those who has access to the same environment) right?

I guess so unless you're adding the key in setting of the App and not the Org, and that App is limited to some user group. It's a guess, didn't test it.

I am not allowed to sore the key in the frontend, so I guess I will use it in the workflow then. But thanks for the feedback.

Hi @Shirina - we support referencing secret configuration variables in workflows! You can create them in the "Configuration variables" page in the Settings. Is this what you're looking for?

1 Like

I know it's not the most secure way to store API key but it's possible to save secret variables in workflow settings. I don't know for JS but for Python there's an option for python configuration and if the key is saved here, it can be accessible by using the config variable name

1 Like