PostHog API Skill
Interact with PostHog via its REST API. Two types of endpoints:
- Public (POST-only, project API key): capture events, evaluate flags — no rate limits
- Private (personal API key): query, CRUD for all resources — rate limited
Setup
- Get personal API key: https://us.posthog.com/settings/user-api-keys
- Get project ID: https://us.posthog.com/settings/project#variables
- Set env vars:
export POSTHOG_API_KEY="phx_..."
export POSTHOG_PROJECT_ID="12345"
export POSTHOG_PROJECT_API_KEY="phc_..." # optional, for capture/flags
# For EU Cloud:
# export POSTHOG_HOST="https://eu.posthog.com"
# export POSTHOG_INGEST_HOST="https://eu.i.posthog.com"
- Verify:
bash scripts/posthog.sh whoami
Helper Script
scripts/posthog.sh wraps common operations. Run bash scripts/posthog.sh help for full usage.
Examples
# Capture an event
bash scripts/posthog.sh capture "signup" "user_123" '{"plan":"pro"}'
# Evaluate feature flags
bash scripts/posthog.sh evaluate-flags "user_123"
# HogQL query — top events last 7 days
bash scripts/posthog.sh query "SELECT event, count() FROM events WHERE timestamp >= now() - INTERVAL 7 DAY GROUP BY event ORDER BY count() DESC LIMIT 20"
# List persons
bash scripts/posthog.sh list-persons 10 | jq '.results[] | {name, distinct_ids}'
# List feature flags
bash scripts/posthog.sh list-flags | jq '.results[] | {id, key, active}'
# Create a feature flag
echo '{"key":"new-dashboard","name":"New Dashboard","active":true,"filters":{"groups":[{"rollout_percentage":50}]}}' | \
bash scripts/posthog.sh create-flag
# List dashboards
bash scripts/posthog.sh list-dashboards | jq '.results[] | {id, name}'
Key Concepts
Two API types
- Public endpoints (
/i/v0/e/, /batch/, /flags): Use project API key in body. No auth header. No rate limits.
- Private endpoints (
/api/projects/:project_id/...): Use personal API key via Authorization: Bearer. Rate limited.
HogQL Queries
The query endpoint (POST /api/projects/:project_id/query/) is the most powerful way to extract data. Uses SQL-like HogQL syntax against tables: events, persons, sessions, groups, plus data warehouse tables.
Always include time ranges and LIMIT. Use timestamp-based pagination for large exports.
Rate Limits (private endpoints)
| Type |
Limit |
| Analytics (insights, persons, recordings) |
240/min, 1200/hr |
| Query endpoint |
2400/hr |
| Feature flag local evaluation |
600/min |
| Other CRUD |
480/min, 4800/hr |
Limits apply per organization. On 429: back off and retry.
Domains
| Cloud |
Public |
Private |
| US |
us.i.posthog.com |
us.posthog.com |
| EU |
eu.i.posthog.com |
eu.posthog.com |
Events API (deprecated)
The /api/projects/:project_id/events/ endpoint is deprecated. Use HogQL queries or batch exports instead.
Direct curl
# Private endpoint
curl -H "Authorization: Bearer $POSTHOG_API_KEY" \
"$POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/feature_flags/"
# HogQL query
curl -H "Authorization: Bearer $POSTHOG_API_KEY" \
-H "Content-Type: application/json" \
-X POST -d '{"query":{"kind":"HogQLQuery","query":"SELECT count() FROM events WHERE timestamp >= now() - INTERVAL 1 DAY"}}' \
"$POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/query/"
# Capture event (public)
curl -H "Content-Type: application/json" \
-X POST -d '{"api_key":"'$POSTHOG_PROJECT_API_KEY'","event":"test","distinct_id":"u1"}' \
"$POSTHOG_INGEST_HOST/i/v0/e/"
Full API Reference
See references/api-endpoints.md for complete endpoint listing with parameters, body schemas, scopes, and response formats.
Sections: Public Endpoints (Capture, Batch, Flags), Private Endpoints (Persons, Feature Flags, Insights, Dashboards, Annotations, Cohorts, Experiments, Surveys, Actions, Session Recordings, Users, Definitions), Query API (HogQL).
1---
2name: posthog
3description: >
4 Interact with PostHog analytics via its REST API. Capture events, evaluate feature flags,
5 query data with HogQL, manage persons, insights, dashboards, experiments, surveys, cohorts,
6 annotations, and session recordings. Use when the user mentions "PostHog", "PostHog API",
7 "PostHog events", "PostHog feature flags", "PostHog insights", "PostHog query", "HogQL",
8 "PostHog persons", "PostHog dashboards", "PostHog experiments", "PostHog surveys",
9 "PostHog cohorts", "PostHog recordings", "capture events PostHog", or "PostHog analytics".
10metadata:
11 source: https://skillmd.com/skills/modbender/posthog
12 env:
13 - POSTHOG_API_KEY (required): "Personal API key — create at https://us.posthog.com/settings/user-api-keys"
14 - POSTHOG_PROJECT_ID (required): "Project ID — find at https://us.posthog.com/settings/project#variables"
15 - POSTHOG_PROJECT_API_KEY: "Project API key (for public capture/flags endpoints)"
16 - POSTHOG_HOST: "API host (default: https://us.posthog.com)"
17 - POSTHOG_INGEST_HOST: "Ingest host (default: https://us.i.posthog.com)"
18---
19
20# PostHog API Skill
21
22Interact with PostHog via its REST API. Two types of endpoints:
23- **Public** (POST-only, project API key): capture events, evaluate flags — no rate limits
24- **Private** (personal API key): query, CRUD for all resources — rate limited
25
26## Setup
27
281. Get personal API key: https://us.posthog.com/settings/user-api-keys
292. Get project ID: https://us.posthog.com/settings/project#variables
303. Set env vars:
31 ```bash
32 export POSTHOG_API_KEY="phx_..."
33 export POSTHOG_PROJECT_ID="12345"
34 export POSTHOG_PROJECT_API_KEY="phc_..." # optional, for capture/flags
35 # For EU Cloud:
36 # export POSTHOG_HOST="https://eu.posthog.com"
37 # export POSTHOG_INGEST_HOST="https://eu.i.posthog.com"
38 ```
394. Verify: `bash scripts/posthog.sh whoami`
40
41## Helper Script
42
43`scripts/posthog.sh` wraps common operations. Run `bash scripts/posthog.sh help` for full usage.
44
45### Examples
46
47```bash
48# Capture an event
49bash scripts/posthog.sh capture "signup" "user_123" '{"plan":"pro"}'
50
51# Evaluate feature flags
52bash scripts/posthog.sh evaluate-flags "user_123"
53
54# HogQL query — top events last 7 days
55bash scripts/posthog.sh query "SELECT event, count() FROM events WHERE timestamp >= now() - INTERVAL 7 DAY GROUP BY event ORDER BY count() DESC LIMIT 20"
56
57# List persons
58bash scripts/posthog.sh list-persons 10 | jq '.results[] | {name, distinct_ids}'
59
60# List feature flags
61bash scripts/posthog.sh list-flags | jq '.results[] | {id, key, active}'
62
63# Create a feature flag
64echo '{"key":"new-dashboard","name":"New Dashboard","active":true,"filters":{"groups":[{"rollout_percentage":50}]}}' | \
65 bash scripts/posthog.sh create-flag
66
67# List dashboards
68bash scripts/posthog.sh list-dashboards | jq '.results[] | {id, name}'
69```
70
71## Key Concepts
72
73### Two API types
74- **Public endpoints** (`/i/v0/e/`, `/batch/`, `/flags`): Use project API key in body. No auth header. No rate limits.
75- **Private endpoints** (`/api/projects/:project_id/...`): Use personal API key via `Authorization: Bearer`. Rate limited.
76
77### HogQL Queries
78The query endpoint (`POST /api/projects/:project_id/query/`) is the most powerful way to extract data. Uses SQL-like HogQL syntax against tables: `events`, `persons`, `sessions`, `groups`, plus data warehouse tables.
79
80Always include time ranges and LIMIT. Use timestamp-based pagination for large exports.
81
82### Rate Limits (private endpoints)
83| Type | Limit |
84|------|-------|
85| Analytics (insights, persons, recordings) | 240/min, 1200/hr |
86| Query endpoint | 2400/hr |
87| Feature flag local evaluation | 600/min |
88| Other CRUD | 480/min, 4800/hr |
89
90Limits apply per organization. On 429: back off and retry.
91
92### Domains
93| Cloud | Public | Private |
94|-------|--------|---------|
95| US | `us.i.posthog.com` | `us.posthog.com` |
96| EU | `eu.i.posthog.com` | `eu.posthog.com` |
97
98### Events API (deprecated)
99The `/api/projects/:project_id/events/` endpoint is deprecated. Use HogQL queries or batch exports instead.
100
101## Direct curl
102
103```bash
104# Private endpoint
105curl -H "Authorization: Bearer $POSTHOG_API_KEY" \
106 "$POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/feature_flags/"
107
108# HogQL query
109curl -H "Authorization: Bearer $POSTHOG_API_KEY" \
110 -H "Content-Type: application/json" \
111 -X POST -d '{"query":{"kind":"HogQLQuery","query":"SELECT count() FROM events WHERE timestamp >= now() - INTERVAL 1 DAY"}}' \
112 "$POSTHOG_HOST/api/projects/$POSTHOG_PROJECT_ID/query/"
113
114# Capture event (public)
115curl -H "Content-Type: application/json" \
116 -X POST -d '{"api_key":"'$POSTHOG_PROJECT_API_KEY'","event":"test","distinct_id":"u1"}' \
117 "$POSTHOG_INGEST_HOST/i/v0/e/"
118```
119
120## Full API Reference
121
122See [references/api-endpoints.md](references/api-endpoints.md) for complete endpoint listing with parameters, body schemas, scopes, and response formats.
123
124Sections: Public Endpoints (Capture, Batch, Flags), Private Endpoints (Persons, Feature Flags, Insights, Dashboards, Annotations, Cohorts, Experiments, Surveys, Actions, Session Recordings, Users, Definitions), Query API (HogQL).