Skip to main content

Configuration

Set up and configure the PostHog provider for product analytics
2 min read

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#

2. Environment Variables#

3. Provider Block#

Getting API Credentials#

Create Personal API Key#

  1. Log in to your PostHog instance at app.posthog.com (or your self-hosted URL)
  2. Navigate to Settings → User → Personal API Keys
  3. Click Create Personal API Key
  4. 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#

PropertyTypeRequiredDefaultDescription
apiKeystringYes-PostHog Personal API Key (starts with phx_)
hoststringNohttps://us.posthog.comPostHog instance URL

Best Practices#

Security#

Multi-Environment Setup#

Multi-Project Setup#

Troubleshooting#

Authentication Errors#

Error: 401 Unauthorized

Solution:

  1. Verify your API key is correct and starts with phx_
  2. Check that the API key hasn't expired
  3. 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.com or https://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

Additional Resources#