Install an OPENAI API KEY in Your .Renviron File for Repeated Use
Source: R/openai_api_key.R
openai_api_key.RdThis function will add your OpenAI API key to your .Renviron file so it can be called securely without being stored
in your code. After you have installed your key, it can be called any time by typing Sys.getenv("OPENAI_API_KEY") and will be
automatically called in package functions. If you do not have an .Renviron file, the function will create one for you.
If you already have an .Renviron file, the function will append the key to your existing file, while making a backup of your
original file for disaster recovery purposes.
Examples
if (FALSE) { # \dontrun{
openai_api_key("111111abc", install = TRUE)
# First time, reload your environment so you can use the key without restarting R.
readRenviron("~/.Renviron")
# You can check it with:
Sys.getenv("OPENAI_API_KEY")
} # }
if (FALSE) { # \dontrun{
# If you need to overwrite an existing key:
openai_api_key("111111abc", overwrite = TRUE, install = TRUE)
# First time, reload your environment so you can use the key without restarting R.
readRenviron("~/.Renviron")
# You can check it with:
Sys.getenv("OPENAI_API_KEY")
} # }