# PostHog

> PostHog product analytics - read insights, persons, events, feature flags, cohorts, and annotations.

Lets an agent explore your PostHog product analytics - read insights, persons, events, cohorts, and feature flags, run HogQL/SQL event queries, and create feature flags, cohorts, and annotations.

## What it can do

| Method | What it does |
| --- | --- |
| `posthog_get_me` | Get the authenticated PostHog user account (email, name, default org/project). |
| `posthog_list_projects` | List all projects accessible to this user. |
| `posthog_list_insights` | List insights (saved analytics queries/dashboards); filter by search, paginate. |
| `posthog_get_insight` | Get one insight including its definition, filters, and cached result data. |
| `posthog_list_persons` | List persons (user profiles); search by distinct_id or properties, paginate. |
| `posthog_get_person` | Get one person by numeric ID or distinct_id, with all properties and events. |
| `posthog_list_events` | List events; filter by event name and person_id, paginate. |
| `posthog_query_events` | Run a HogQL or SQL query over events and return the results. |
| `posthog_list_feature_flags` | List feature flags; filter by search, paginate. |
| `posthog_get_feature_flag` | Get one feature flag by ID or key with its variants and targeting. |
| `posthog_create_feature_flag` | Create a feature flag (key, name, optional active/filters/rollout). |
| `posthog_update_feature_flag` | Update a feature flag (name, active, filters, rollout percentage). |
| `posthog_list_cohorts` | List cohorts (user segments); filter by search, paginate. |
| `posthog_get_cohort` | Get one cohort with its definition, membership count, and filters. |
| `posthog_create_cohort` | Create a cohort (name and membership filters, optional description). |
| `posthog_list_annotations` | List annotations (markers on insight graphs); filter by insight_id, paginate. |
| `posthog_create_annotation` | Create an annotation (content and date marker, optional insight to attach). |

## How to get credentials

1. Open [posthog.com/settings/account-api-keys](https://posthog.com/settings/account-api-keys).
2. Click **Create personal API key**, name it (e.g. *FlyMyAI Agent*), and pick the scopes the agent needs (read for analytics, write for feature flags/cohorts/annotations).
3. Copy the key - it is shown only once.
4. Find your **project ID**: open Project settings, or read it from any PostHog URL of the form `/project/<ID>/` (it is numeric).

## Fields to fill in FlyMyAI

| FlyMyAI field | Where it comes from |
| --- | --- |
| `POSTHOG_API_KEY` | PostHog - Settings - Personal API keys |
| `POSTHOG_PROJECT_ID` | Numeric project ID (Project settings, or in URLs `/project/<ID>/`) |
| `POSTHOG_HOST` *(optional)* | `https://us.posthog.com` (default) or `https://eu.posthog.com` |
