Thanks, teddybear.
However, when we call this URL using CURL on the command line, we receive a more informative error message, such as "API key is not valid," which is understandable.
Additionally, when we use the
HttpJob object, everything works perfectly fine. The issue only arises when we use
OkHttpRequest.
Here's an example cURL command. You can copy and paste this piece of code into the command line (cmd) and execute it, it should work:
(
Source)
curl https://api.openai.com/v1/models -H "Authorization: Bearer OPENAI_API_KEY_OPTIONAL"
Regarding the attached project mentioned in the first post, I believe the issue resides in this specific portion of the code. Below is another simple example along with the URL that we should send to either
HttpJob or
OkHttpRequest:
Dim url As String = "https://api.openai.com/v1/models"
Private hc As OkHttpClient 'It should be in Process_Global
Dim req As OkHttpRequest
req.InitializePatch2(url, "TEST".ToString.GetBytes("UTF8"))
req.SetHeader("Authorization", "Bearer " & GetEnvironmentVariable("OPENAI_API_KEY", ""))
req.SetHeader("OpenAI-Organization", "")
req.SetContentType("application/json")
req.SetContentEncoding("UTF8")
req.Timeout = 90000
hc.Execute(req, 0)
I'm not sure where my foolish mistake lies, but I have been struggling with this particular issue for more than two weeks now. It has been quite frustrating and challenging to resolve.