API Key Error (401)

I’m looking to work through James’ Haystack Tutorial Notebook: examples/haystack_lfqa.ipynb at master · pinecone-io/examples · GitHub

But I can’t get through the first step given the following error:

UnauthorizedException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({‘www-authenticate’: ‘API key is missing or invalid for the environment “us-west1-gcp”. Check that the correct environment is specified.’, ‘content-length’: ‘114’, ‘date’: ‘Tue, 31 Jan 2023 12:37:56 GMT’, ‘server’: ‘envoy’})
HTTP response body: API key is missing or invalid for the environment “us-west1-gcp”. Check that the correct environment is specified.

For the following code block:

document_store = PineconeDocumentStore(
api_key=‘my api key’,
index=‘haystack-extractive-qa’,
similarity=“cosine”,
embedding_dim=384
)

I’ve used my API key in other projects without an issue, and to my understanding have all the other proper packages installed.

I’ve tried this with multiple API keys (>12 hours apart), and even created a new account to try a fresh API key. Does anyone know what the issue can be?

1 Like

I figured it out:

The PineconeDocumentStore() function was missing: environment=“<<my_enviornment>>”

1 Like

Thanks Evan I was facing the same error and your solution saved me going through the documentation.

1 Like

Sorry, new here. Is this in Pinecone? Or VSC? I am getting the error " FAILED TO CONNECT TO PINECONE (‘401 Client Error: Unauthorized for url: https://controller.asia-northeast1-gcp.pinecone.io/actions/whoami’, ‘API key is missing or invalid for the environment “asia-northeast1-gcp”. Check that the correct environment is specified.’)"

I am not located in Asia, could that be the problem?

Hey @Gettinitdone
I am also facing the same problem.

API key is missing or invalid for the environment “asia-northeast1-gcp”. Check that the correct environment is specified.’) "

Same Location. asia-northeast1-gcp

I think it maybe due high demand. Not sure just random guess.

3 Likes

I have the same problem. Environment is auto set at asia-northeast1-gcp when I create my key yet I get the following error:

UnauthorizedException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({‘www-authenticate’: ‘API key is missing or invalid for the environment “asia-northeast1-gcp”. Check that the correct environment is specified.’, ‘content-length’: ‘121’, ‘date’: ‘Sun, 23 Apr 2023 05:29:37 GMT’, ‘server’: ‘envoy’})
HTTP response body: API key is missing or invalid for the environment “asia-northeast1-gcp”. Check that the correct environment is specified.

this is the code Im using:

# install initialize and store vectors in Pinecone


import pinecone
index_name = 'nameofmyindex'
pinecone.init(
    api_key="<<my key here>>",
    environment = "asia-northeast1-gcp"
)

if index_name not in pinecone.list_indexes():
    pinecone.create_index(index_name, dimension=len(embeds[0]))
# connect to index
index = pinecone.Index(index_name)

any help would be appreciated

1 Like

I have the same error (401)
I am sure the PINECONE_API_KEY and PINECONE_API_ENV is right.

pinecone.init(
    api_key=PINECONE_API_KEY,
    environment=PINECONE_API_ENV
)

Is this a error of cloud service ? or there is something wrong with my local env ?

Indeed always does not work on asia-northeast1-gcp.

1 Like

I can’t find the way to change my env when I generate a API_KEY.
If I just write another env in ’ pinecone.init ', It’s not work.
What can I do ? :joy:

Hi all,

We’re having a problem with API keys in asia-northeast1-gcp. For the time being, please create a new project in a different region to set up your index.

Are there any instructions for creating a new project in a different region?

Hi Alex, I found how to do it. Go to Organization > projects > create project. Also, I have removed the default project to do not have issues with asia-northeast1-gcp project.

That fixed the issue. Now, everything is working find.

This did not work for me. I am still getting 401 errors.

unfortunately am getting error Error: Request failed with status code 401 error on us server moved to central based server still its not working

I went to delete my index in asia-northeast1-gcp, and now I have just spinning circle… I can’t create new project because default project exist, and I can’t delete project because index “exists”, and I can’t delete index because the UI is broken :smiley:

2 Likes

Solved by using API to delete the index again

I resolved this error by creating a new project in us-west1-gcp.

This worked for me. But when I started to run Auto GPT it says “Using memory of type: LocalCache” is this correct? Or should it say Pinecone? I changed the Memory Backend to Pinecone in my VSC .env section

Having same problem with very simple code

import pinecone

api_key = “my API Key”

env =“us-west4-gcp”
pinecone.init(api_key=api_key, enviroment=env)
pinecone.whoami()

pinecone.init() apparently works. no error message.

whoami() fails with

(‘401 Client Error: Unauthorized for url: https://controller.us-west1-gcp.pinecone.io/actions/whoami’, ‘API key is missing or invalid for the environment “us-west1-gcp”. Check that the correct environment is specified.’)

Note that the environment actually is us-west4-gcp despite the error msg saying us-west1-gcp, This is a free account and I can create an index in it with the pinecone browser console.