k8sgpt icon indicating copy to clipboard operation
k8sgpt copied to clipboard

Error: failed while calling AI provider openai: error, status code: 401, message:

Open rohanmathias opened this issue 1 year ago • 12 comments

Checklist

  • [X] I've searched for similar issues and couldn't find anything matching
  • [X] I've included steps to reproduce the behavior

Affected Components

  • [X] K8sGPT (CLI)
  • [X] K8sGPT Operator

K8sGPT Version

0.3.6

Kubernetes Version

No response

Host OS and its Version

mac

Steps to reproduce

  1. k8sgpt analyse (works as expected)
  2. k8sgpt analyse --explain. (Doesn't works asking for key)

Expected behaviour

Expectect to show all the details of the cluster/pod issues

Actual behaviour

Error: failed while calling AI provider openai: error, status code: 401, 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.

Additional Information

Error: failed while calling AI provider openai: error, status code: 401, 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.

I have already add api key, where do I'm missing for header? I don't see any documentation around this

rohanmathias avatar Jun 26 '23 19:06 rohanmathias

Which command did you use to add the API key?

nitishfy avatar Jul 02 '23 12:07 nitishfy

I also have this problem. I properly created a new API key by running k8sgpt generated which took me to API keys page where I created and copied a new key. I then pasted that when prompted in the next command

❯ k8sgpt auth add openai Warning: backend input is empty, will use the default value: openai Warning: model input is empty, will use the default value: gpt-3.5-turbo Enter openai Key: openai added to the AI backend provider list

❯ k8sgpt analyze --explain 0% | | (0/2, 0 it/hr) [0s:0s] Error: failed while calling AI provider openai: error, status code: 401, message: Incorrect API key provided: sk-2jiZn*********************************************************************************************************************************************mV7h. You can find your API key at https://platform.openai.com/account/api-keys.

What is wrong. I can use GPT 4 already and have subscription.

radrad avatar Oct 11 '23 12:10 radrad

@radrad that's odd, do you see the api key in your k8sgpt config file ?

arbreezy avatar Oct 11 '23 18:10 arbreezy

@radrad that's odd, do you see the api key in your k8sgpt config file ?

where is this config file located? I am using windows 10. I added this folder to system path env variable "j:\Tools\k8sgpt" I cannot see any config file being created in that folder as well as %userprofile% (C:\Users<username>) Where is this openai key persisted?

radrad avatar Oct 12 '23 08:10 radrad

Good question, I haven't used Windows in a while but we write the configuration in your XDG_CONFIG_HOME directory

I think it should be under your LocalAppData folder

arbreezy avatar Oct 12 '23 18:10 arbreezy

I have the same issue on my mac. Where is the config file located ?

justynroberts avatar Nov 23 '23 07:11 justynroberts

I have the same issue on my mac. Where is the config file located ? I found mine on windows: C:\Users<user>\AppData\Local\k8sgpt

I noticee multiple provider entries with the same name and strange 3X concatenated API key in the first provider. I think there is a bug in duplicating provider names. Regarding first provider with 3X concatenation you can ignore it. It could be that in one case I was pressing Ctrl+V 3 times (not used to empty feedback when pasting something in cmd window. My configuration with sensitive info reduced: ai: providers: - name: openai model: "" password: <sk-something...H1ax2nZ6ZssVmm><sk-something...H1ax2nZ6ZssVmm><sk-something...H1ax2nZ6ZssVmm> temperature: 0.7 - name: openai model: "" password: sk-....Something 2 temperature: 0.7 - name: openai model: "" password: '"<sk-something...H1ax2nZ6ZssVmm>"' temperature: 0.7 - name: openai model: "" password: <sk-something...H1ax2nZ6ZssVmm> temperature: 0.7 - name: openai model: "" password: <sk-something...H1ax2nZ6ZssVld> temperature: 0.7 defaultprovider: "" kubeconfig: "" kubecontext: ""

I asked GTP chat-4: what is equivalent on mac and linux for this windows locaton: The equivalent path on a Mac would be /Users//Library/Application Support/k8sgpt. On a Linux system, it would be /home//.local/share/k8sgpt.

I removed all but the first entry and here is my settings. It works now: ai: providers: - name: openai model: "gpt-4-1106-preview" password: "sk-......" temperature: 0.7 defaultprovider: "openai" kubeconfig: "" kubecontext: ""

radrad avatar Nov 23 '23 11:11 radrad

I had the same issue in Ubunto with WSL, I re-tried with multiple keys , eventually moved azureOpenai which worked well from the start.

image

pavneeta avatar Dec 29 '23 04:12 pavneeta

Anyone know this fix to this error: Error: failed while calling AI provider openai: Post "https://api.openai.com/v1/chat/completions": net/http: invalid header field value for "Authorization"

dbdiky avatar Apr 12 '24 17:04 dbdiky

Installed g8sgpt on my wsl and connected with openai backend $k8sgpt generate Opening: https://beta.openai.com/account/api-keys to generate a key for openai

Please copy the generated key and run k8sgpt auth to add it to your config file $k8sgpt auth add --backend openai --model gpt-3.5-turbo Enter openai Key: openai added to the AI backend provider list

Now When I am running below command getting cert issue.. $k8sgpt analyse --explain 0% | | (0/1, 0 it/hr) [0s:0s] Error: failed while calling AI provider openai: Post "https://api.openai.com/v1/chat/completions": tls: failed to verify certificate: x509: certificate signed by unknown authority

Any help would be appreciated....

kamleshjec avatar May 10 '24 10:05 kamleshjec

@kamleshjec which k8sgpt version are you using?

JuHyung-Son avatar May 13 '24 14:05 JuHyung-Son

Thanks a lot for your response, Its working for me now, I am using azureopenai instead openai as there was some issue with default auth ai backend I mean when I was running k8sgpt generate cmd it was redirecting for openai key which was having some issue.

kamleshjec avatar Jun 13 '24 10:06 kamleshjec