I am a fresh ruby programmer and I am trying to use OpenAI API for a school project. I keep receiving this error when trying to run my ruby code. I used curl to see if it was something to do with api key and curl worked fine I am not sure what my next steps should be. Here is my code:
Here’s what a 401 means when thrown by OpenAI API:
Code
Overview
401 - Invalid Authentication
Cause: Invalid Authentication Solution: Ensure the correct API key and requesting organization are being used.
401 - Incorrect API key provided
Cause: The requesting API key is not correct. Solution: Ensure the API key used is correct, clear your browser cache, or generate a new one.
401 - You must be a member of an organization to use the API
Cause: Your account is not part of an organization. Solution: Contact us to get added to a new organization or ask your organization manager to invite you.
I’ve implemented the initializer and changed the env from api_key to access_token. I’m still getting the same error. I even tried to just hardcode the api key into the code and it still is giving me a unauthorized error.
The library doesn’t seem to get from any env variable automatically.
Documentation reports using an an openai.rb initializer file with its more permanent setting.
You can find this in the link, and use OPENAI_API_KEY instead (like anything else would).
If you don’t know how to work with the library’s Ruby code and identify where it creates a request as a variable, to then log it, and are uncertain if you are even using this library right, perhaps the “community” that might know is some Ruby developer forum, or the “issues” on github for it. I could probably install Ruby, make it work or not, debug, but that is called “consulting”, not “fun times with forum pals useful to all”.
Maybe it is better to be a “fresh” Python or node.js programmer, as there you have official libraries that are maintained with examples.