Is there a problem upserting with Python from a gcp-starter account?

I’m trying a very simple excercise, create an index, check availability and upsert, still; I’m receiving 403 errors due to a “Wrong API key” (It isn’t!! It belongs to the project in working in).

Here is my code:

load_dotenv('.env', override=True)
pinecone_api_key = os.getenv("PINECONE_API_KEY")
pc = Pinecone(api_key=pinecone_api_key, environment='gcp-starter')
print(pc.list_indexes()) # Check availability
index_name = "project-chunks-2"
if index_name not in pc.list_indexes().names():
    pc.create_index(
        name=index_name,
        dimension=1536,
        metric="cosine",
        spec=PodSpec(
            environment="gcp-starter",
            pod_type="starter",
            pods=1
            )
        )

print(pc.list_indexes()) # Check availability

index = pinecone.Index(index_name, host="host_shown_in_print(pc.list_indexes())")

# Load and chunk it up
loader = TextLoader('masterwallet_doc.txt')
documents = loader.load()
context = " ".join([doc.page_content for doc in documents])
text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=50)
chunks = text_splitter.split_text(context)

embeddings = OpenAIEmbeddings(model="text-embedding-ada-002")
chunk_embeddings = [embeddings.embed_query(chunk) for chunk in chunks]
my_vectors = [(str(i), chunk_embeddings[i]) for i in range(len(chunk_embeddings))]
index.upsert(vectors=my_vectors) # Error happens here!!

Here’s the error I’m currently getting:

Reason: Forbidden
HTTP response headers: HTTPHeaderDict({‘x-pinecone-auth-rejected-reason’: ‘Wrong API key’, ‘www-authenticate’: ‘Wrong API key’, ‘Content-Length’: ‘9’, ‘content-type’: ‘text/plain’, ‘date’: ‘Wed, 22 May 2024 16:53:14 GMT’, ‘server’: ‘envoy’, ‘Via’: ‘1.1 google’, ‘Alt-Svc’: ‘h3=“:443”; ma=2592000,h3-29=“:443”; ma=2592000’, ‘Connection’: ‘close’})
HTTP response body: Forbidden

Hi @diego.barba1991, which line in your code is triggering the error message?

Hello! It happens in:

index.upsert(vectors=my_vectors) # Error happens here!!

Thanks. What version of the Pinecone Python client are you using? If you are using v3.0.0 or newer, you must initialize your client as follows:

pc = Pinecone(api_key="YOUR_API_KEY")

For reference, the latest version of the Python client is v4.1.0.

Also, I see that you initialize your client calling:

pc = Pinecone(api_key=pinecone_api_key, environment='gcp-starter')

Yet, when you connect to your index, you call pinecone.Index. I don’t see anywhere where you define pinecone, nor should you need to be operating with multiple active clients. Do you have a previously defined client named pinecone that you might be inadvertently calling?