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