irudnyts / openai

An R package-wrapper around OpenAI API
https://irudnyts.github.io/openai/
Other
164 stars 28 forks source link

openai cannot recognize my API keys #21

Closed ManuelSpinola closed 1 year ago

ManuelSpinola commented 1 year ago

I am trying to use openai but when I include my API keys it cannot be recognized.

Sys.setenv(
    SPOTIFY_CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
)
create_completion(
    engine_id = "ada",
    prompt = "Generate a question and an answer"
)

Error: OpenAI API request failed [401]:

You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://beta.openai.com.

irudnyts commented 1 year ago

Oops, my bad 🤦‍♂️ You should use OPENAI_API_KEY instead of SPOTIFY_CLIENT_ID:

Sys.setenv(
    OPENAI_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
)

Please let me know if it works.

ManuelSpinola commented 1 year ago

Thank you very much. It works now.