Query logs with LogQL

PostHog exposes a Loki-compatible query API over your logs. Tools that speak LogQL, such as Grafana's Loki data source or logcli, can query PostHog logs without a Loki server.

The LogQL API is in private alpha

The LogQL API is available only to organizations in the private alpha. If your organization does not have access, every request returns 403 Forbidden, even with a valid logs:read key. To get access, reach out to us via in-app support.

Endpoint

Point your Loki client at the logs API of your project:

text
https://us.posthog.com/api/projects/:project_id/logs

Use eu.posthog.com for EU Cloud. The client appends the standard Loki paths, so a range query goes to:

text
GET|POST /api/projects/:project_id/logs/loki/api/v1/query_range

Supported paths:

PathPurpose
loki/api/v1/queryInstant query
loki/api/v1/query_rangeRange query
loki/api/v1/labelsList label names
loki/api/v1/label/:name/valuesList values for one label
loki/api/v1/seriesList log streams
loki/api/v1/index/statsStream statistics for a selector
loki/api/v1/status/buildinfoBuild information

The API is read-only. push is not exposed. Send logs with the OpenTelemetry exporter instead.

Authentication

Authenticate with a personal API key that has the logs:read scope. Send it as a bearer token:

Terminal
curl --header "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
--get "https://us.posthog.com/api/projects/$PROJECT_ID/logs/loki/api/v1/query_range" \
--data-urlencode 'query={service_name="api"} |= "error"' \
--data-urlencode 'start=2026-09-01T00:00:00Z' \
--data-urlencode 'end=2026-09-01T01:00:00Z' \
--data-urlencode 'limit=100'

The query only sees logs of the project in the URL. A team_id parameter in the query is ignored.

Grafana

  1. Add a Loki data source.
  2. Set the URL to https://us.posthog.com/api/projects/<project_id>/logs.
  3. Under HTTP headers, add Authorization with the value Bearer <personal API key>.
  4. Save and test.

Query errors keep the Loki error format, so Grafana shows them inline.

Rate limits

The endpoint uses the project's ClickHouse read-byte budget. Snuffle reports the bytes that ClickHouse read after each query, and that amount is taken from a Redis token bucket. The bucket refills continuously and has a capped balance.

When the budget is empty, the next request returns 429 with Retry-After. Grafana dashboards with many panels can use different amounts because each panel is charged for its actual ClickHouse read volume, not one request.

Self-hosted

The endpoint proxies to Snuffle, which runs next to the logs ClickHouse cluster. Configure it with these environment variables on the web pods:

VariablePurpose
SNUFFLE_APM_URLBase URL of Snuffle. Empty turns the endpoint off and it answers 501.
SNUFFLE_APM_USER / SNUFFLE_APM_PASSWORDClickHouse credential that Snuffle uses. Defaults to the logs cluster user. Prefer a read-only user.
SNUFFLE_APM_TIMEOUT_SECONDSUpstream request timeout. Default 60.

Still have questions?

Was this page useful?