[Bug]: Error failed to send message HTTP 401, invalid_api_key #725
-
Contact DetailsWhat happened?I am trying to get OpenAI to work inside a Docker container on my Raspberry Pi. My Google PaLM works fine and OpenAI works fine from my mac.. For some reason I am getting the error below. I have verified the .env file has the correct API key inside the container. Other relevant details; On mac when I run it I get gear icons when changing models to look at some settings or import a .json for google PaLM. On Raspberry Pi I do not get that option on any of the models including google, but google does work with the .json key in the /api/data folder. I have Pi hole running outside of docker , so that is on port :80 not sure if that is causing an issue here. I also have homebridge running outside of docker. NOTE: I removed the API Key fully with *'s in the output log below, but it does show the correct beginning and end of my key on my end. Steps to Reproduce
What browsers are you seeing the problem on?Safari Relevant log outputError: Failed to send message. HTTP 401 - {
2023-07-27T20:04:34.654086535Z "error": {
2023-07-27T20:04:34.654106183Z "message": "Incorrect API key provided: \"sk-uvOH********************************************\". You can find your API key at https://platform.openai.com/account/api-keys.",
2023-07-27T20:04:34.654123183Z "type": "invalid_request_error",
2023-07-27T20:04:34.654138738Z "param": null,
2023-07-27T20:04:34.654153572Z "code": "invalid_api_key"
2023-07-27T20:04:34.654168238Z }
2023-07-27T20:04:34.654182627Z }
2023-07-27T20:04:34.654198238Z
2023-07-27T20:04:34.654212812Z at onopen (/app/api/app/clients/ChatGPTClient.js:211:25)
2023-07-27T20:04:34.654227608Z at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2023-07-27T20:04:34.654249737Z at async create (/app/node_modules/@waylaidwanderer/fetch-event-source/lib/cjs/fetch.cjs:56:17) {
2023-07-27T20:04:34.654264996Z status: 401,
2023-07-27T20:04:34.654279700Z json: {
2023-07-27T20:04:34.654294052Z error: {
2023-07-27T20:04:34.654308515Z message: 'Incorrect API key provided: "sk-uvOH********************************************". You can find your API key at https://platform.openai.com/account/api-keys.',
2023-07-27T20:04:34.654324237Z type: 'invalid_request_error',
2023-07-27T20:04:34.654338551Z param: null,
2023-07-27T20:04:34.654352903Z code: 'invalid_api_key'
2023-07-27T20:04:34.654367255Z }
2023-07-27T20:04:34.654381736Z }
2023-07-27T20:04:34.654395903Z }
2023-07-27T20:04:34.661260893Z Error: Failed to send message. HTTP 401 - {
2023-07-27T20:04:34.661379299Z "error": {
2023-07-27T20:04:34.661401391Z "message": "Incorrect API key provided: \"sk-uvOH********************************************\". You can find your API key at https://platform.openai.com/account/api-keys.",
2023-07-27T20:04:34.661419372Z "type": "invalid_request_error",
2023-07-27T20:04:34.661435335Z "param": null,
2023-07-27T20:04:34.661472557Z "code": "invalid_api_key"
2023-07-27T20:04:34.661511612Z }
2023-07-27T20:04:34.661530427Z }
2023-07-27T20:04:34.661545019Z
2023-07-27T20:04:34.661559408Z at onopen (/app/api/app/clients/ChatGPTClient.js:211:25)
2023-07-27T20:04:34.661597926Z at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2023-07-27T20:04:34.661614389Z at async create (/app/node_modules/@waylaidwanderer/fetch-event-source/lib/cjs/fetch.cjs:56:17) {
2023-07-27T20:04:34.662468862Z status: 401,
2023-07-27T20:04:34.662546195Z json: {
2023-07-27T20:04:34.662563880Z error: {
2023-07-27T20:04:34.662644861Z message: 'Incorrect API key provided: "sk-uvOH********************************************". You can find your API key at https://platform.openai.com/account/api-keys.',
2023-07-27T20:04:34.662673157Z type: 'invalid_request_error',
2023-07-27T20:04:34.662690231Z param: null,
2023-07-27T20:04:34.662705656Z code: 'invalid_api_key'
2023-07-27T20:04:34.662720823Z }
2023-07-27T20:04:34.662785896Z }
2023-07-27T20:04:34.662804878Z } ScreenshotsNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Do you have billing enabled for OpenAI API usage? It looks like the network request is successful but is being deemed invalid |
Beta Was this translation helpful? Give feedback.
-
other relevant notes would be how you're running docker on the Pi, frontend screenshots before/after you send a message, that is, when are you getting the error? |
Beta Was this translation helpful? Give feedback.
-
I double checked, I am setup for billing on OpenAPI. I can run LibreChat fine from my M1 Mac with the API Keys. I just checked and the API does work doing a curl Authorization API test from the container. So, the API itself does not appear to be the issue, but transmitting it to openai must be the problem. my docker-compose settings under api are: I changed 3080 to 3080:3080 so I can access LibreChat on the Raspberry Pi otherwise I could not access it.
|
Beta Was this translation helpful? Give feedback.
-
Hi @bozzy01 Thanks again for trying out the project and sorry you're having trouble. I moved this to troubleshooting since I'm convinced this is a configuration error as I only get the API response you're experiencing when I actually input a wrong API key. After careful review, it looks like your api key is including quotation marks in the API call message: 'Incorrect API key provided: "sk-uvOH********************************************" <--- before "sk" and here
...
"message": "Incorrect API key provided: \"sk-uvOH********************************************\" <--- before "sk" and here Notice my response when I deliberately put the wrong key {
"error": {
"message": "Incorrect API key provided: sk-***********************************************. You can find your API key at https://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
} Where are you inputting the API key? by .env file? frontend? in the env file, here's an example of mine: OPENAI_API_KEY=sk-my-key In environment files, strings are typically formatted without quotation marks. This is because the shell treats everything after the equals sign (=) as the value of the variable, up until the end of the line or the next whitespace character. Note if you configure your api key like this, you can provide it from the web app, with the same idea (without quotations) OPENAI_API_KEY=user_provided |
Beta Was this translation helpful? Give feedback.
Hi @bozzy01 Thanks again for trying out the project and sorry you're having trouble.
I moved this to troubleshooting since I'm convinced this is a configuration error as I only get the API response you're experiencing when I actually input a wrong API key.
After careful review, it looks like your api key is including quotation marks in the API call
Notice my response when I deliberately put the wrong key