Closed ChrisKlingler closed 1 year ago
Hi @ChrisKlingler, WebGL app will not be able to reach the key through your local files. Alternatively, you can provide the API key to your OpenAiAPI ctor as a parameter to make it work. I made a video for ht here https://www.youtube.com/watch?v=DjX8mjBCMcg
Thanks for sharing @srcnalt - I don't know if this helps me as I am just trying to do ChatCompletions on WebGL and am already passing the API Key as a parameter like so:
openai = new OpenAIApi(currentEnvironment.MyApiKey);
I've made sure the environment variables are coming down and being passed successfully to the OpenAIApi Configuration, but somehow the headers must be getting wiped out on WebGL builds with ChatCompletion. Right now trying to run the ChatGPT Sample by injecting the API Key in the ChatGPT.cs script is having the same behavior.
Ah, this is interesting, it is a direct server error. I wonder if this could be related to firewalls etc. Could you tell me which version of Unity are you using so I can try to replicate it, this never happened to me before.
Sure. I was using the latest version of Unity until I ran into an issue with other libraries I need to function for this project. They recommend I use 2020 to get those issues to work. Currently, I am running 2020.3.47f1 Personal
So if I understand correctly, this works in 2020 but not in 2022?
I have not checked in 2022. So far only in 2020
It may be helpful to know that this also appears to be a problem when running locally with a built and run WebGL build on 2020
Building from Unity 2020.3.0f1 It works all right for me. I suspect it might be a network/firewall-related issue.
Got it. I'll take another look at it tomorrow. Thanks
Is this solved? I run into the same issue. For test purposes the API key is hardcoded and everything works in the editor. But the WebGL build has the authentication error. I've tried 2020.3.0f1, 2021.3.22f1, and 2022.2.19f1.
Within the editor things communicate fine with OpenAI but when building and running a WebGL build I get the following response:
{ "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 } }
Why is it the apiKey headers are not being passed on WebGL builds?