This guide covers how to configure the PostHog provider for Pulumi.
Overview#
The PostHog provider enables management of product analytics, feature flags, and event tracking resources. It requires an API key for authentication and supports both PostHog Cloud and self-hosted instances.
Provider Configuration#
Basic Setup#
Configuration Methods#
1. Pulumi Configuration (Recommended)#
2. Environment Variables#
3. Provider Block#
Getting API Credentials#
Create Personal API Key#
- Log in to your PostHog instance at app.posthog.com (or your self-hosted URL)
- Navigate to Settings → User → Personal API Keys
- Click Create Personal API Key
- Copy the generated API key (starts with
phx_)
Required Permissions#
The API key should have access to:
- Feature flags (read/write)
- Insights (read/write)
- Dashboards (read/write)
- Alerts (read/write)
- Hog functions (read/write)
Self-Hosted PostHog#
If you're using a self-hosted PostHog instance, configure the custom host URL:
Or using environment variables:
Example with Self-Hosted Instance#
Configuration Options#
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | Yes | - | PostHog Personal API Key (starts with phx_) |
host | string | No | https://us.posthog.com | PostHog instance URL |
Best Practices#
Security#
Multi-Environment Setup#
Multi-Project Setup#
Troubleshooting#
Authentication Errors#
Error: 401 Unauthorized
Solution:
- Verify your API key is correct and starts with
phx_ - Check that the API key hasn't expired
- Ensure the API key has necessary permissions
Invalid Host Configuration#
Error: Connection refused
Solution:
- Ensure your host URL is correct and includes the protocol (https://)
- For PostHog Cloud, use
https://us.posthog.comorhttps://eu.posthog.com - For self-hosted, use your instance URL
Permission Denied#
Error: 403 Forbidden
Solution:
- Ensure your API key has appropriate project access
- Personal API keys need appropriate permissions
- Check that you're accessing resources in the correct project