Skip to contents

We encourage the use of the keyring package to securely store API keys. This function attempts to load your OpenAI API key from keyring if it is available, or from an environment variable otherwise.

Usage

oai_get_default_key(key_name = "OPENAI_API_KEY")

Arguments

key_name

The name of the keyring service or of the environment variable.

Value

A string with the value if available, or "".

Examples

Sys.setenv(TEMP_OAI_API_KEY = "test_value")
test_result <- oai_get_default_key("TEMP_OAI_API_KEY")
test_result
#> [1] "test_value"
Sys.unsetenv("TEMP_OAI_API_KEY")