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

# PostHog

> Product analytics platform API for querying events, managing feature flags, running experiments, and accessing session replays.

Product analytics platform API for querying events, managing feature flags, running experiments, and accessing session replays. Best for workflows that need to read analytics data, toggle feature flags programmatically, or automate experiment management. Unlike Mixpanel or Amplitude, PostHog is open-source with a self-hostable option.

9 example endpoints available through Lava's AI Gateway. See the [PostHog API docs](https://posthog.com/docs/api) for full documentation.

<Warning>This provider requires your own credentials — connect your API key or OAuth account before use.</Warning>

<Info>This is a **catch-all provider** — any valid URL under `https://us.posthog.com` is supported. Any PostHog API endpoint. Construct URL as [https://us.posthog.com/api/\&#123;path\&#125](https://us.posthog.com/api/\&#123;path\&#125);. See [https://posthog.com/docs/api](https://posthog.com/docs/api) for full reference. The endpoints below are curated examples.</Info>

## Endpoints

### Run an analytics query (HogQL, trends, funnels)

**POST** `https://us.posthog.com/api/environments/{env_id}/query/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/environments/{env_id}/query/', {
      body: {
    "query": {
      "kind": "HogQLQuery",
      "query": "SELECT count() FROM events"
    }
    },
    });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X POST "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fenvironments%2F%7Benv_id%7D%2Fquery%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY" \
      -H "Content-Type: application/json" \
      -d '{"query":{"kind":"HogQLQuery","query":"SELECT count() FROM events"}}'
    ```
  </Tab>
</Tabs>

### List feature flags

**GET** `https://us.posthog.com/api/projects/{project_id}/feature_flags/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/feature_flags/', { method: 'GET' });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Ffeature_flags%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY"
    ```
  </Tab>
</Tabs>

### Query events

**GET** `https://us.posthog.com/api/projects/{project_id}/events/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/events/', { method: 'GET' });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Fevents%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY"
    ```
  </Tab>
</Tabs>

### List persons (users)

**GET** `https://us.posthog.com/api/projects/{project_id}/persons/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/persons/', { method: 'GET' });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Fpersons%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY"
    ```
  </Tab>
</Tabs>

### List saved insights

**GET** `https://us.posthog.com/api/projects/{project_id}/insights/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/insights/', { method: 'GET' });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Finsights%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY"
    ```
  </Tab>
</Tabs>

### List dashboards

**GET** `https://us.posthog.com/api/projects/{project_id}/dashboards/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/dashboards/', { method: 'GET' });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Fdashboards%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY"
    ```
  </Tab>
</Tabs>

### Replace a feature flag

**PUT** `https://us.posthog.com/api/projects/{project_id}/feature_flags/{flag_id}/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/feature_flags/{flag_id}/', { method: 'PUT', body: {"name":"my-flag","key":"my-flag","active":true} });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X PUT "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Ffeature_flags%2F%7Bflag_id%7D%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY" \
      -H "Content-Type: application/json" \
      -d '{"name":"my-flag","key":"my-flag","active":true}'
    ```
  </Tab>
</Tabs>

### Update a feature flag

**PATCH** `https://us.posthog.com/api/projects/{project_id}/feature_flags/{flag_id}/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/feature_flags/{flag_id}/', { method: 'PATCH', body: {"active":true} });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X PATCH "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Ffeature_flags%2F%7Bflag_id%7D%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY" \
      -H "Content-Type: application/json" \
      -d '{"active":true}'
    ```
  </Tab>
</Tabs>

### Delete an annotation

**DELETE** `https://us.posthog.com/api/projects/{project_id}/annotations/{annotation_id}/` — Free

<Tabs>
  <Tab title="SDK">
    ```typescript theme={null}
    const data = await lava.gateway('https://us.posthog.com/api/projects/{project_id}/annotations/{annotation_id}/', { method: 'DELETE' });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -X DELETE "https://api.lava.so/v1/forward?u=https%3A%2F%2Fus.posthog.com%2Fapi%2Fprojects%2F%7Bproject_id%7D%2Fannotations%2F%7Bannotation_id%7D%2F" \
      -H "Authorization: Bearer $LAVA_SECRET_KEY" \
      -H "Content-Type: application/json"
    ```
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={2}>
  <Card title="All Providers" icon="grid" href="/gateway/supported-providers">
    Browse all supported AI providers
  </Card>

  <Card title="Forward Proxy" icon="route" href="/gateway/forward-proxy">
    Learn how to construct proxy URLs and authenticate requests
  </Card>
</CardGroup>
