Skip to content

SetOpenAIKey

Loic A. Royer edited this page Feb 19, 2024 · 4 revisions

How to set the OpenAI key on your system for use in Omega?

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.

Omega's built-in API Vault:

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:

image

Next time, you will be treated by a dialog that asks for the password:

image

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.

Setting the 'OPENAI_API_KEY' environment variable:

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.

Windows

For Windows, environment variables can be set through the Command Prompt or PowerShell. Here's how to do it in both:

Command Prompt

  1. Open Command Prompt as Administrator.
  2. To set the environment variable for the current session, use:
    setx OPENAI_API_KEY "YOUR_API_KEY_HERE"
    
    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 /M to the command:
    setx /M OPENAI_API_KEY "YOUR_API_KEY_HERE"
    
  3. Close and reopen any command prompt windows to use the new environment variable.

PowerShell

  1. Open PowerShell as Administrator.
  2. To set the environment variable for the current session, use:
    [System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY', 'YOUR_API_KEY_HERE', [System.EnvironmentVariableTarget]::User)
    
    To set it system-wide, replace [System.EnvironmentVariableTarget]::User with [System.EnvironmentVariableTarget]::Machine.
  3. Close and reopen PowerShell to use the new environment variable.

macOS

For macOS, environment variables can be set in the terminal. Here's how to do it:

  1. Open the Terminal.
  2. Edit your shell profile file (this could be .bash_profile, .bashrc, .zshrc, etc., depending on your shell). For example, using nano:
    nano ~/.zshrc
    
  3. Add the following line to the file:
    export OPENAI_API_KEY="YOUR_API_KEY_HERE"
    
  4. Save and close the file (in nano, press Ctrl + O, Enter, and then Ctrl + X to exit).
  5. Apply the changes by sourcing your profile:
    source ~/.zshrc
    
  6. Your API key is now set as an environment variable.

Linux

The process for Linux is similar to macOS:

  1. Open the Terminal.
  2. Edit your shell profile file (~/.bashrc, ~/.bash_profile, ~/.zshrc, etc.) using a text editor. For example:
    nano ~/.bashrc
    
  3. Add the following line to the file:
    export OPENAI_API_KEY="YOUR_API_KEY_HERE"
    
  4. Save and exit the editor (in nano, press Ctrl + O, Enter, and then Ctrl + X).
  5. To make the variable available in the current session, source the profile file:
    source ~/.bashrc
    
  6. The API key is now set as an environment variable for your user.