Authentication

This guide explains how to authenticate API calls to your Pinecone project.

Overview

All API calls to your Pinecone index authenticate with an API key for the project containing the target index. If you are using a client, like the Python or Node.js clients, you can initialize a client object, which allows you to provide your API key in one place and use it multiple times. If you are making HTTP requests with a tool like cURL, the HTTP request must include a header that specifies the API key. This topic describes each method.

Finding your Pinecone API key

To find your API key, open the Pinecone console, select your project, and click API Keys.

Initialize your connection

Using your API key, initialize your client connection to Pinecone:

from pinecone import Pinecone
pc = Pinecone(api_key='YOUR_API_KEY')
import { Pinecone } from '@pinecone-database/pinecone';

const pc = new Pinecone({
    apiKey: 'YOUR_API_KEY' 
});

Function calls with this client use the authentication information provided at initialization. For example:

# Creates an index using the API key stored in the client 'pinecone'.
pc.create_index(
    name="auth-guide",
    dimension=8,
    metric="euclidean",
    spec=ServerlessSpec(
        cloud='aws', 
        region='us-west-2'
    ) 
) 
// Creates an index using the API key stored in the client 'pinecone'.
await pc.createIndex({
    name: 'auth-guide',
    dimension: 8,
    metric: 'euclidean',
    spec: { 
        serverless: { 
            cloud: 'aws', 
            region: 'us-west-2' 
        }
    } 
}) 

Add a header to an HTTP request

When issuing an HTTP request to Pinecone, each request must contain an Api-Key header that specifies a valid API key.

curl -s -X POST "https://api.pinecone.io/indexes" \
   -H "Content-Type: application/json" \
   -H "Api-Key: YOUR_API_KEY" \
   -d '{
         "name":  "auth-guide",
         "dimension": 8,
         "metric": "euclidean",
         "spec": {
            "serverless": {
               "cloud":"aws",
               "region": "us-west-2"
            }
         }
      }'

Next steps