> ## Documentation Index
> Fetch the complete documentation index at: https://opensre.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PostHog

> Connect PostHog REST credentials so OpenSRE can verify access to your project

OpenSRE stores **your** PostHog project credentials for REST API access (project metadata and future REST features). Configure with `opensre integrations setup posthog` or `POSTHOG_*` environment variables.

<Info>
  Looking for agent tools during investigations (analytics, feature flags, HogQL)? Use [PostHog (MCP)](/posthog-mcp) with `opensre integrations setup posthog_mcp`.
</Info>

## PostHog in OpenSRE — quick guide

| What you want                                   | Use this                      | How to set it up                                                |
| ----------------------------------------------- | ----------------------------- | --------------------------------------------------------------- |
| Store PostHog REST credentials for your project | **PostHog** — this page       | `opensre integrations setup posthog` or env vars (below)        |
| Let the agent explore PostHog during incidents  | [PostHog (MCP)](/posthog-mcp) | `opensre integrations setup posthog_mcp` or onboarding wizard   |
| OpenSRE's own usage telemetry                   | Built-in product analytics    | Controlled by `OPENSRE_NO_TELEMETRY` — not your PostHog project |

## Prerequisites

* A PostHog account (US, EU, or self-hosted)
* Your PostHog **project ID**
* A **personal API key** with read access to that project — see [PostHog's personal API keys docs](https://posthog.com/docs/api/personal-api-keys)

## Setup

### Option 1: Interactive CLI

```bash theme={null}
opensre integrations setup posthog
```

Or run the onboarding wizard and select **PostHog** under Observability.

You will be prompted for:

* **Project ID** — from PostHog project settings
* **Personal API key** (`phx_...`) — [Personal API keys](https://posthog.com/docs/api/personal-api-keys) with read access
* **API base URL** — defaults to US SaaS (`https://us.i.posthog.com`); use `https://eu.i.posthog.com` for EU

On success, credentials are saved to your integration store and synced to `.env`.

### Option 2: Environment variables

Add credentials directly to your `.env` file:

```bash theme={null}
POSTHOG_PROJECT_ID=your_project_id
POSTHOG_PERSONAL_API_KEY=phx_your_personal_api_key
POSTHOG_BASE_URL=https://us.i.posthog.com           # optional — US SaaS default
POSTHOG_TIMEOUT_SECONDS=15.0                        # optional
```

| Variable                   | Default                    | Description                                                                  |
| -------------------------- | -------------------------- | ---------------------------------------------------------------------------- |
| `POSTHOG_PROJECT_ID`       | —                          | **Required.** Your PostHog project ID                                        |
| `POSTHOG_PERSONAL_API_KEY` | —                          | **Required.** Personal API key for the project                               |
| `POSTHOG_BASE_URL`         | `https://us.i.posthog.com` | API base URL (`https://eu.i.posthog.com` for EU, or your self-hosted origin) |
| `POSTHOG_TIMEOUT_SECONDS`  | `15.0`                     | HTTP timeout in seconds                                                      |

## Verify

After saving your `.env`, confirm OpenSRE can reach your PostHog project:

```bash theme={null}
opensre integrations verify posthog
```

A successful check prints `PostHog validated.`

For the MCP integration, use `opensre integrations verify posthog_mcp` instead.

## Troubleshooting

| Symptom                         | Fix                                                                     |
| ------------------------------- | ----------------------------------------------------------------------- |
| **Authentication failed (401)** | Check `POSTHOG_PERSONAL_API_KEY` is valid and has read access           |
| **Project not found (404)**     | Confirm `POSTHOG_PROJECT_ID` matches the instance in `POSTHOG_BASE_URL` |
| **Verify says not configured**  | Both `POSTHOG_PROJECT_ID` and `POSTHOG_PERSONAL_API_KEY` must be set    |

## Security

* Use a dedicated personal API key with the minimum read permissions needed
* Store credentials in environment variables or a secret manager — not in source code
* Rotate keys periodically
