danny-avila / LibreChat

Enhanced ChatGPT Clone: Features Anthropic, OpenAI, Assistants API, Azure, Groq, GPT-4o, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, langchain, DALL-E-3, ChatGPT Plugins, OpenAI Functions, Secure Multi-User System, Presets, completely open-source for self-hosting. Actively in public development.
https://librechat.ai/
MIT License
17.2k stars 2.87k forks source link

[Bug]: Error failed to send message HTTP 401, invalid_api_key #714

Closed bozzy01 closed 1 year ago

bozzy01 commented 1 year ago

Contact Details

dancab@hey.com

What 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

  1. create a container with mongodb 4.4.18 on raspberry pi
  2. edit the .env and add your key
  3. run the container and try to use the openai model.

What browsers are you seeing the problem on?

Safari

Relevant log output

Error: 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 }

Screenshots

No response

Code of Conduct

danny-avila commented 1 year ago

Do you have billing enabled for OpenAI API usage? It looks like the network request is successful but is being deemed invalid

danny-avila commented 1 year ago

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?

bozzy01 commented 1 year ago

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.

` api: container_name: LibreChat ports: