-
Notifications
You must be signed in to change notification settings - Fork 28
SetOpenAIKey
Two approaches are possible:
1- Use Omega's built-in API Vault. This is recommended because the API key is stored in a cryptographically secure manner. 2- Store the key in an environment variable. This is best suited for developers that also want to use the OpenAI key for their own projects.
If you have not set the 'OPENAI_API_KEY' environment variable as is typically done, Omega will ask you for your OpenAI API key and will store it safely in an encrypted way on your machine (~/.omega_api_keys/OpenAI.json). The idea is that you might not be able to remember your OpenAI key by heart, obviously, but you might be able to do so with your own password or passphrase.
When you start Omega, you will be asked to enter the API key and a password to secure it:
Next time, you will be treated by a dialog that asks for the password:
Note that you also have the possibility to reset the API key (and the password that secures it). This is useful if you need to change keys.
If you set the API key as an environment variable, Omega will find and use it, never asking to store or retrieve the key from the vault.
To set the OpenAI API key as an environment variable on different operating systems, follow the instructions below for each OS. This will allow you to securely store your API key without hardcoding it into your scripts. Remember to replace YOUR_API_KEY_HERE
with your actual OpenAI API key.
For Windows, environment variables can be set through the Command Prompt or PowerShell. Here's how to do it in both:
- Open Command Prompt as Administrator.
- To set the environment variable for the current session, use:
This command sets the environment variable for the current user. If you want to set it system-wide (for all users), you need to add
setx OPENAI_API_KEY "YOUR_API_KEY_HERE"
/M
to the command:setx /M OPENAI_API_KEY "YOUR_API_KEY_HERE"
- Close and reopen any command prompt windows to use the new environment variable.
- Open PowerShell as Administrator.
- To set the environment variable for the current session, use:
To set it system-wide, replace
[System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY', 'YOUR_API_KEY_HERE', [System.EnvironmentVariableTarget]::User)
[System.EnvironmentVariableTarget]::User
with[System.EnvironmentVariableTarget]::Machine
. - Close and reopen PowerShell to use the new environment variable.
For macOS, environment variables can be set in the terminal. Here's how to do it:
- Open the Terminal.
- Edit your shell profile file (this could be
.bash_profile
,.bashrc
,.zshrc
, etc., depending on your shell). For example, using nano:nano ~/.zshrc
- Add the following line to the file:
export OPENAI_API_KEY="YOUR_API_KEY_HERE"
- Save and close the file (in nano, press
Ctrl + O
,Enter
, and thenCtrl + X
to exit). - Apply the changes by sourcing your profile:
source ~/.zshrc
- Your API key is now set as an environment variable.
The process for Linux is similar to macOS:
- Open the Terminal.
- Edit your shell profile file (
~/.bashrc
,~/.bash_profile
,~/.zshrc
, etc.) using a text editor. For example:nano ~/.bashrc
- Add the following line to the file:
export OPENAI_API_KEY="YOUR_API_KEY_HERE"
- Save and exit the editor (in nano, press
Ctrl + O
,Enter
, and thenCtrl + X
). - To make the variable available in the current session, source the profile file:
source ~/.bashrc
- The API key is now set as an environment variable for your user.