Skip to contents

Get API key from R environment variable.

Usage

get_api_key(env_var = "OPENAI_API_KEY")

Arguments

env_var

Character string indicating the name of the temporary R environment variable with the API key and the used AI model. Currently, the argument only takes env_var = "OPENAI_API_KEY". See set_api_key() to set/create this variable.

Value

The specified API key (NOTE: Avoid exposing this in the console).

Details

get_api_key() can be used after executing set_api_key() or by adding the api key permanently to your R environment by using usethis::edit_r_environ(). Then write OPENAI_API_KEY=[insert your api key here] and close the .Renviron window and restart R. For backward compatibility, it will also check CHATGPT_KEY if OPENAI_API_KEY is not set.

Note

Find your personal API key via the OpenAI quickstart guide at https://developers.openai.com/api/docs/quickstart#generate-an-api-key.

See also

Examples

if (FALSE) { # \dontrun{
get_api_key()
} # }