Endpoint
Authentication
Use a Personal API Key in theAuthorization header:
Request Parameters
The ID of your PostHog project. Found in your project settings.
Request Body
The query object defining what data to retrieve. The structure depends on the query type.Supported query types:
HogQLQuery- SQL-like queries using HogQLEventsQuery- Structured event queriesTrendsQuery- Time-series analysisFunnelsQuery- Funnel analysisRetentionQuery- Retention analysisPathsQuery- User path analysis
Controls query execution and caching behavior:
blocking- Wait for fresh results, use cache if freshasync- Return cached results immediately, refresh in backgroundforce_blocking- Always calculate fresh resultsforce_async- Always return cached results, refresh in backgroundlazy_async- Use cache, only calculate if cache is missing
Optional identifier to track this specific query. Used for monitoring and cancellation.
Dashboard filters to apply to the query. Used when executing queries in a dashboard context.
Variable values to override in the query. Allows parameterized queries.
Response
The response structure varies based on the query type.Query results. Structure depends on the query type.
Column names for the query results.
Data types for each column.
Examples
HogQL Query Language
HogQL is PostHog’s SQL-like query language that provides powerful event analysis capabilities.Basic Syntax
Available Tables
events- All captured eventspersons- Person recordsperson_distinct_ids- Mapping of distinct IDs to personssessions- Session datacohorts- User cohorts
Common Functions
count()- Count rowscountDistinct(column)- Count unique valuesavg(column)- Average valuesum(column)- Sum valuesmin(column),max(column)- Min/max valuestoDate(timestamp)- Convert to datedateDiff('day', date1, date2)- Date difference
Event Properties
Access event properties using dot notation:Query Status
For async queries, check the query status using:Canceling Queries
Cancel a running query:Rate Limits
Query endpoint rate limits:- Burst: 20 requests per 10 seconds
- Sustained: 100 requests per hour
- HogQL specific: Additional limits based on query complexity
Rate limits are higher for teams with paid plans. Contact support for enterprise limits.
Best Practices
- Use time filters: Always filter by timestamp to limit data scanned
- Limit results: Use
LIMITto avoid retrieving excessive data - Use async for large queries: Set
refresh: "async"for queries that may take time - Cache when possible: Use
refresh: "blocking"to benefit from query caching - Monitor query performance: Use
client_query_idto track query execution - Aggregate at query time: Use
GROUP BYand aggregations to reduce data transfer
Error Handling
Common error scenarios:- 400 Bad Request: Invalid query syntax or parameters
- 401 Unauthorized: Invalid or missing API key
- 403 Forbidden: Insufficient permissions
- 429 Too Many Requests: Rate limit exceeded
- 500 Internal Server Error: Query execution error