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.