Skip to main content

API Key Authentication

People Context API uses API keys to authenticate requests. Include your API key in the Authorization header as a Bearer token.
Keep your API key secure! Never commit it to version control or expose it in client-side code.

Making Authenticated Requests

Include your API key in the Authorization header:
import requests

headers = {
    "Authorization": "Bearer your_api_key_here",
    "Content-Type": "application/json"
}

response = requests.get(
    "https://api.peoplecontext.com/v1/webset/github/person",
    headers=headers,
    params={"github": "torvalds"}
)

Environment Variables

Store your API key in environment variables to keep it secure:
PEOPLE_CONTEXT_API_KEY=your_api_key_here

Error Responses

401 Unauthorized

Missing or invalid API key:
{
  "detail": "Invalid authentication credentials"
}

403 Forbidden

Valid key but insufficient permissions:
{
  "detail": "You do not have permission to access this resource"
}

429 Too Many Requests

Rate limit exceeded:
{
  "detail": "Rate limit exceeded. Please try again later.",
  "retry_after": 60
}

Rate Limits

API rate limits depend on your subscription plan:
PlanRequests per MinuteRequests per Day
Free101,000
Starter6010,000
Professional300100,000
EnterpriseCustomCustom
Monitor the X-RateLimit-Remaining and X-RateLimit-Reset response headers to track your usage.

Best Practices

  • Never hardcode API keys in your source code
  • Use environment variables or secret management systems
  • Rotate keys regularly
  • Use different keys for development and production
  • Implement exponential backoff for rate limit errors
  • Cache responses when possible
  • Monitor the rate limit headers
  • Always check response status codes
  • Implement retry logic for transient errors (500, 503)
  • Handle rate limits gracefully

Example: Complete Authentication Setup

Here’s a complete example with error handling and rate limiting:
Python
import os
import requests
import time
from dotenv import load_dotenv

load_dotenv()

class PeopleContextAPI:
    def __init__(self):
        self.api_key = os.getenv("PEOPLE_CONTEXT_API_KEY")
        self.base_url = "https://api.peoplecontext.com"
        self.headers = {
            "Authorization": f"Bearer {self.api_key}",
            "Content-Type": "application/json"
        }

    def make_request(self, endpoint, params=None, max_retries=3):
        url = f"{self.base_url}{endpoint}"

        for attempt in range(max_retries):
            try:
                response = requests.get(url, headers=self.headers, params=params)

                if response.status_code == 200:
                    return response.json()

                elif response.status_code == 429:
                    retry_after = int(response.headers.get('Retry-After', 60))
                    print(f"Rate limited. Waiting {retry_after} seconds...")
                    time.sleep(retry_after)
                    continue

                elif response.status_code == 401:
                    raise Exception("Invalid API key")

                else:
                    response.raise_for_status()

            except requests.exceptions.RequestException as e:
                if attempt == max_retries - 1:
                    raise
                time.sleep(2 ** attempt)

        return None

# Usage
api = PeopleContextAPI()
profile = api.make_request("/v1/webset/github/person", params={"github": "torvalds"})