srcnalt/OpenAI-Unity

WebGL Authentication

Opened this issue · 2 comments

Basically I have the same issue as this: #45
and this: #47

These are markes as resolved but I didn't find any solution (and looks like the authors didn't either?)
This is the error message:
{
"error": {
"message": "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://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}

It happens ONLY in WebGL builds, not in the editor. No problem with the API key, as I pass it directly into the constructor. Tested in 2020.3.0f1, 2021.3.22f1, and 2022.2.19f1 so not a Unity version error.

There's something going on and I need a workaround to get a testable WEBGL build.

I may just have found a dirty work around.
So essentially, what you would want to do is to remove this project as a package. and instead add the project straight into your project copy paste style.
From then, you can freely edit the Configuration.cs code and paste your secret key there, along with the org.

Doing so will make them being able to work on Webgl

This is not the best, but this is what can come up quick

@MaximilianCroissant

Hi @MaximilianCroissant,

Could you test with the latest release? NewtonSoft.Json and code stripping related issues must be gone with the latest changes.