Getting [ERROR] UnauthorizedException: (401)

I’ve been using Pinecone with no errors up until yesterday, when in the lambda logs in AWS showed the following message: [ERROR] UnauthorizedException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({‘x-pinecone-api-version’: ‘2025-01’, ‘x-cloud-trace-context’: ‘2bea49a855844d1906e2f895811a5b19’, ‘date’: ‘Fri, 04 Apr 2025 15:09:08 GMT’, ‘content-type’: ‘text/html’, ‘server’: ‘Google Frontend’, ‘Content-Length’: ‘15’, ‘Via’: ‘1.1 google’, ‘Alt-Svc’: ‘h3=“:443”; ma=2592000,h3-29=“:443”; ma=2592000’})
HTTP response body: Invalid API Key

I’ve verified that my API key is correct, I also made another API key to test it out but both keys were returning the same error.

I am facing the same error. Right until a few minutes it worked but getting the same 401 error.

I am also facing the same issue, the API key is working properly in the local system but when I am trying to deploy my project on Streamlit cloud it is showing the error.

Failed to setup Pinecone: (401) Reason: Unauthorized HTTP response headers: HTTPHeaderDict({‘x-pinecone-api-version’: ‘2025-04’, ‘x-cloud-trace-context’: ‘fbd842201fb002436130ae761da02524’, ‘date’: ‘Thu, 24 Jul 2025 20:12:44 GMT’, ‘content-type’: ‘text/html’, ‘server’: ‘Google Frontend’, ‘Content-Length’: ‘15’, ‘Via’: ‘1.1 google’, ‘Alt-Svc’: ‘h3=“:443”; ma=2592000,h3-29=“:443”; ma=2592000’}) HTTP response body: Invalid API Key

Please check out my Github Repo,

Hi @shibsankardas721 - Thanks for posting on the Pinecone forums!

If your app and API key are working locally, it sounds like this might be an issue with your Streamlit setup. A few questions for you:

  1. Maybe the API key is not getting picked up correctly?
  2. Have you verified that your other API keys for other services are working properly?
  3. How are you setting up these API keys in Streamlit Cloud?

It looks like you’re managing the secrets locally using dotenv and .env. I’m not sure exactly how that translates into Streamlit Cloud, but it might make more sense to use their suggested approach with secrets.toml here as that does support their cloud environment out of the box: Secrets management for your Community Cloud app - Streamlit Docs

@jenna Thank you, ma’am. I have used the .env file locally for API keys, and in the time of deployment I I was converting the API keys into TOML format and pasting them into the secrets of the Streamlit cloud, which is why it was giving the error in the time of deployment.

But when I switched .env with secrets.toml and made some necessary changes for using the API keys from this file, it ran properly locally as well as in in the cloud.

So thank you, ma’am, for guiding me. And it was beneficial in completing my project.

1 Like