Logs-3

For instructions on how to authenticate to use this endpoint, see API overview.

Endpoints

PATCH
DELETE
POST
POST
POST
POST
GET
POST
GET
POST

Update environments logs sampling rules

Required API key scopes

logs:write

Path parameters

  • id
    string

Request parameters

  • name
    string
  • enabled
    boolean
    Default: false
  • priority
    integernull
  • rule_type
  • scope_service
    stringnull
  • scope_path_pattern
    stringnull
  • scope_attribute_filters
    array
  • config

Response


Example request

PATCH /api/environments/:environment_id/logs/sampling_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/:id/\
-d name="string"

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"rule_type": "severity_sampling",
"scope_service": "string",
"scope_path_pattern": "string",
"scope_attribute_filters": [
{}
],
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Update environments logs sampling rules

Required API key scopes

logs:write

Path parameters

  • id
    string

Request parameters

  • name
    string
  • enabled
    boolean
    Default: false
  • priority
    integernull
  • rule_type
  • scope_service
    stringnull
  • scope_path_pattern
    stringnull
  • scope_attribute_filters
    array
  • config

Response


Example request

PATCH /api/environments/:environment_id/logs/sampling_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/:id/\
-d name="string"

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"rule_type": "severity_sampling",
"scope_service": "string",
"scope_path_pattern": "string",
"scope_attribute_filters": [
{}
],
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Delete environments logs sampling rules

Required API key scopes

logs:write

Path parameters

  • id
    string

Example request

DELETE /api/environments/:environment_id/logs/sampling_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X DELETE \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/:id/

Example response

Status 204 No response body

Delete environments logs sampling rules

Required API key scopes

logs:write

Path parameters

  • id
    string

Example request

DELETE /api/environments/:environment_id/logs/sampling_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X DELETE \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/:id/

Example response

Status 204 No response body

Create environments logs sampling rules simulate

Dry-run estimate for how much volume this rule would remove (placeholder response until CH-backed simulation is wired).

Path parameters

  • id
    string

Response


Example request

POST /api/environments/:environment_id/logs/sampling_rules/:id/simulate
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/:id/simulate/

Example response

Status 200
RESPONSE
{
"estimated_reduction_pct": 0.1,
"notes": "string"
}

Create environments logs sampling rules simulate

Dry-run estimate for how much volume this rule would remove (placeholder response until CH-backed simulation is wired).

Path parameters

  • id
    string

Response


Example request

POST /api/environments/:environment_id/logs/sampling_rules/:id/simulate
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/:id/simulate/

Example response

Status 200
RESPONSE
{
"estimated_reduction_pct": 0.1,
"notes": "string"
}

Create environments logs sampling rules reorder

Atomically reassign priorities so the given ID order maps to ascending priorities (0..n-1).

Query parameters

  • limit
    integer
  • offset
    integer

Request parameters

  • ordered_ids
    array

Response


Example request

POST /api/environments/:environment_id/logs/sampling_rules/reorder
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/reorder/\
-d ordered_ids="array"

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"rule_type": "severity_sampling",
"scope_service": "string",
"scope_path_pattern": "string",
"scope_attribute_filters": [
{}
],
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}

Create environments logs sampling rules reorder

Atomically reassign priorities so the given ID order maps to ascending priorities (0..n-1).

Query parameters

  • limit
    integer
  • offset
    integer

Request parameters

  • ordered_ids
    array

Response


Example request

POST /api/environments/:environment_id/logs/sampling_rules/reorder
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sampling_rules/reorder/\
-d ordered_ids="array"

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"rule_type": "severity_sampling",
"scope_service": "string",
"scope_path_pattern": "string",
"scope_attribute_filters": [
{}
],
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}

Create environments logs services

Also available via the PostHog MCP server:

  • logs-services-createList services with stats

Required API key scopes

logs:read

Request parameters

  • query

Response


Example request

POST /api/environments/:environment_id/logs/services
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/services/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"services": [
{
"service_name": "string",
"log_count": 0,
"error_count": 0,
"error_rate": 0.1,
"volume_share_pct": 0.1,
"severity_breakdown": {
"debug": 0,
"info": 0,
"warn": 0,
"error": 0
},
"active_rules": [
{
"rule_id": "728c1541-d6d1-4290-9a53-cdf01dd32d60",
"rule_name": "string",
"summary_string": "string"
}
]
}
],
"sparkline": [
{
"time": "string",
"service_name": "string",
"count": 0
}
],
"summary": {
"top_services_count": 0,
"top_services_volume_share_pct": 0.1
}
}

Create environments logs services

Also available via the PostHog MCP server:

  • logs-services-createList services with stats

Required API key scopes

logs:read

Request parameters

  • query

Response


Example request

POST /api/environments/:environment_id/logs/services
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/services/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"services": [
{
"service_name": "string",
"log_count": 0,
"error_count": 0,
"error_rate": 0.1,
"volume_share_pct": 0.1,
"severity_breakdown": {
"debug": 0,
"info": 0,
"warn": 0,
"error": 0
},
"active_rules": [
{
"rule_id": "728c1541-d6d1-4290-9a53-cdf01dd32d60",
"rule_name": "string",
"summary_string": "string"
}
]
}
],
"sparkline": [
{
"time": "string",
"service_name": "string",
"count": 0
}
],
"summary": {
"top_services_count": 0,
"top_services_volume_share_pct": 0.1
}
}

Create environments logs sparkline

Required API key scopes

logs:read

Request parameters

  • query

Response


Example request

POST /api/environments/:environment_id/logs/sparkline
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sparkline/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"results": [
{
"time": "string",
"severity": "string",
"service": "string",
"count": 0,
"bytes_uncompressed": 0
}
]
}

Create environments logs sparkline

Required API key scopes

logs:read

Request parameters

  • query

Response


Example request

POST /api/environments/:environment_id/logs/sparkline
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/sparkline/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"results": [
{
"time": "string",
"severity": "string",
"service": "string",
"count": 0,
"bytes_uncompressed": 0
}
]
}

Retrieve environments logs values

Required API key scopes

logs:read

Query parameters

  • attribute_type
    string
    One of: "log""resource"
  • dateRange
  • filterGroup
    Click to open
    array
    Default:
  • key
    string
  • serviceNames
    array
    Default:
  • value
    string

Response


Example request

GET /api/environments/:environment_id/logs/values
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/values/

Example response

Status 200
RESPONSE
{
"results": [
{
"id": "string",
"name": "string"
}
],
"refreshing": true
}

Retrieve environments logs values

Required API key scopes

logs:read

Query parameters

  • attribute_type
    string
    One of: "log""resource"
  • dateRange
  • filterGroup
    Click to open
    array
    Default:
  • key
    string
  • serviceNames
    array
    Default:
  • value
    string

Response


Example request

GET /api/environments/:environment_id/logs/values
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:environment_id/logs/values/

Example response

Status 200
RESPONSE
{
"results": [
{
"id": "string",
"name": "string"
}
],
"refreshing": true
}

Create logs explainlogwithai

Explain a log entry using AI.

POST /api/environments/:id/logs/explainLogWithAI/

Required API key scopes

logs:write

Request parameters

  • uuid
    string
  • timestamp
    string
  • force_refresh
    boolean
    Default: false

Response


Example request

POST /api/environments/:project_id/logs/explainLogWithAI
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:project_id/logs/explainLogWithAI/\
-d uuid="string",\
-d timestamp="string"

Example response

Status 201
RESPONSE
{
"uuid": "string",
"timestamp": "2019-08-24T14:15:22Z",
"force_refresh": false
}

List all logs views

Required API key scopes

logs:read

Query parameters

  • limit
    integer
  • offset
    integer

Response


Example request

GET /api/environments/:project_id/logs/views
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:project_id/logs/views/

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"short_id": "string",
"name": "string",
"filters": {},
"pinned": true,
"created_at": "2019-08-24T14:15:22Z",
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"updated_at": "2019-08-24T14:15:22Z"
}
]
}

List all logs views

Required API key scopes

logs:read

Query parameters

  • limit
    integer
  • offset
    integer

Response


Example request

GET /api/environments/:project_id/logs/views
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:project_id/logs/views/

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"short_id": "string",
"name": "string",
"filters": {},
"pinned": true,
"created_at": "2019-08-24T14:15:22Z",
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"updated_at": "2019-08-24T14:15:22Z"
}
]
}

Create logs views

Required API key scopes

logs:write

Request parameters

  • name
    string
  • filters
    object
  • pinned
    boolean

Response


Example request

POST /api/environments/:project_id/logs/views
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/environments/:project_id/logs/views/\
-d name="string"

Example response

Status 201
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"short_id": "string",
"name": "string",
"filters": {},
"pinned": true,
"created_at": "2019-08-24T14:15:22Z",
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"updated_at": "2019-08-24T14:15:22Z"
}

Community questions

Questions about this page? or post a community question.