PostHog has two types of API keys for different purposes. Here's how to find each one.
Types of PostHog API Keys
- Project API Key: For tracking events (client-side, safe to expose)
- Personal API Key: For reading data and managing PostHog (keep secret)
For most integrations, you'll need a Personal API Key.
Finding Your Personal API Key
- Log in to app.posthog.com (or your self-hosted instance)
- Click your profile icon in the bottom left
- Select Settings
- Click Personal API Keys in the left sidebar
- Click Create personal API key
- Give it a name (e.g., "My Integration")
- Select the scopes/permissions you need
- Click Create key
Important: Copy the key immediately. You won't be able to see it again.
Finding Your Project API Key
- Go to Project Settings (gear icon)
- Find the Project API Key section
- Copy the key (starts with
phc_)
This key is for event tracking only and is safe to use in client-side code.
What Can You Do with the PostHog API?
- Query events: Retrieve event data and analytics
- Manage feature flags: Create and update feature flags programmatically
- Export data: Pull analytics data for reporting
- Manage cohorts: Create and update user cohorts
Troubleshooting
"Invalid API key" error
- Make sure you're using a Personal API Key (not Project API Key) for data access
- Verify the key has the necessary scopes for your use case
- Check the key hasn't been revoked
"Permission denied" error
- Personal API keys inherit your user permissions
- Verify your account has access to the project you're querying
- Check the key's scopes include the endpoint you're accessing
Automate Your Analytics Workflows
Once you have your API key, you can connect PostHog to Miniloop to automate analytics queries, feature flag management, and data exports using natural language. Ask questions about your data, and Miniloop handles the rest.
Frequently Asked Questions
What's the difference between Project and Personal API keys?
Project API Keys are for sending events (client-side tracking) and are safe to expose. Personal API Keys are for reading data and managing PostHog, and must be kept secret.
What scopes should I select for my Personal API Key?
Select only the scopes you need. For querying data, you'll need read access to events, persons, and insights. For feature flag management, add feature flag scopes.
Can I use the same key for multiple projects?
Personal API keys can access all projects your user account has access to. You can restrict access by creating a key with limited scopes.
How do I revoke an API key?
Go to Settings > Personal API Keys and delete the key you want to revoke. This immediately invalidates the key.