Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth Error on WebGL #45

Closed
ChrisKlingler opened this issue Apr 23, 2023 · 10 comments
Closed

Auth Error on WebGL #45

ChrisKlingler opened this issue Apr 23, 2023 · 10 comments

Comments

@ChrisKlingler
Copy link

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?

@srcnalt
Copy link
Owner

srcnalt commented Apr 23, 2023

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

@ChrisKlingler
Copy link
Author

ChrisKlingler commented Apr 24, 2023

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.

Screen Shot 2023-04-24 at 8 01 42 AM

Screen Shot 2023-04-24 at 8 02 10 AM

@srcnalt
Copy link
Owner

srcnalt commented Apr 24, 2023

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.

@ChrisKlingler
Copy link
Author

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

@srcnalt
Copy link
Owner

srcnalt commented Apr 24, 2023

So if I understand correctly, this works in 2020 but not in 2022?

@ChrisKlingler
Copy link
Author

I have not checked in 2022. So far only in 2020

@ChrisKlingler
Copy link
Author

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
Screen Shot 2023-04-24 at 11 17 28 AM

@srcnalt
Copy link
Owner

srcnalt commented Apr 24, 2023

Building from Unity 2020.3.0f1 It works all right for me. I suspect it might be a network/firewall-related issue.

image

@ChrisKlingler
Copy link
Author

Got it. I'll take another look at it tomorrow. Thanks

@MaximilianCroissant
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants