# List log patterns

List the patterns of a source's logs in a time range, most frequent first. Returns every pattern in one page. A source with no logs in the time range returns an empty list.

[endpoint]
method = "GET"
base_url = "https://telemetry.betterstack.com"
path = "/api/v4/sources/{source_id}/log-patterns"

[[path_param]]
name = "source_id"
required = true
type = "string"
description = "Source whose logs are grouped. Get its ID via [List sources](/docs/logs/api/list-all-existing-sources/)."

[[query_param]]
name = "start_time"
type = "string"
description = "Start of the time range. Accepts an ISO 8601 timestamp, in UTC when it has no time zone, a relative time like `now-1h` or `now-2h45m`, or a Unix timestamp in seconds, milliseconds, microseconds or nanoseconds. Defaults to `now-1h`."

[[query_param]]
name = "end_time"
type = "string"
description = "End of the time range, in the same forms as `start_time`. Must be after `start_time`. Defaults to `now`."

[[query_param]]
name = "limit"
default = "30"
type = "integer"
description = "How many patterns to return, from 1 to 100."

[[query_param]]
name = "step"
type = "string"
description = "Length of each step to count each pattern in, returned as `samples`. Accepts a duration such as `30s`, `5m`, `1h` or `1d`. A number alone is seconds. The time range can hold at most 1000 steps."

[[query_param]]
name = "level"
default = "all"
type = "string"
description = "Only logs of this level, read from the log's `level` field and ignoring letter case.<br/>Valid values:<br/>`error`: Matches logs whose level is `error` or `err`.<br/>`warn`: Matches logs whose level is `warn` or `warning`.<br/>`info`: Matches logs whose level is `info`.<br/>`debug`: Matches logs whose level is `debug`.<br/>`all`: Matches logs of every level."

[[query_param]]
name = "service"
type = "string"
description = "Only logs of this service, by its `name` from [List services](/docs/logs/api/services/list/)."

[[query_param]]
name = "team_id"
type = "string"
description = "Team to use, such as `t123`. Get the ID via [List teams](/docs/uptime/api/teams/list/). Required when you can access more than one team."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"
[/endpoint]

[responses]
[[response]]
status = 200
description = "Returns the list of log patterns."
body = '''
{
  "data": [
    {
      "id": "cb97bef4cd1cbd14afe4a7b9aa7b74a2",
      "type": "log_pattern",
      "attributes": {
        "message": "Timeout after 500ms while calling payments",
        "occurrences": 3588,
        "first_seen_at": "2026-11-22T16:04:00Z",
        "last_seen_at": "2026-11-22T17:03:56Z",
        "samples": [
          {
            "time": "2026-11-22T16:00:00Z",
            "count": 1204
          },
          {
            "time": "2026-11-22T16:05:00Z",
            "count": 1187
          }
        ],
        "logs": [
          {
            "dt": "2026-11-22T17:03:56Z",
            "level": "error",
            "message": "Timeout after 500ms while calling payments"
          }
        ]
      }
    }
  ]
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "errors": "Invalid Team API token. How to find your Team API token: https://betterstack.com/docs/logs/api/getting-started/#obtaining-a-logtail-api-token"
}
'''

[[response]]
status = 403
description = "With an OAuth token, the user's role doesn't grant Live tail in the source's team, or the API token's scopes don't include this product."
body = '''
{
  "errors": "You don't have permission to view live tail in this team. Your Better Stack role restricts this action. Ask an organization admin to update your role's permissions."
}
'''

[[response]]
status = 404
description = "The `source_id` value isn't one of your sources. Find your sources via [List sources](/docs/logs/api/list-all-existing-sources/)."
body = '''
{
  "errors": "Resource with the provided ID was not found"
}
'''

[[response]]
status = 422
description = "A parameter is unknown, or a value is refused and `invalid_values` names it. `level` isn't one of the allowed values, `limit` isn't from 1 to 100, `step` isn't a duration or gives more than 1000 steps, `start_time` or `end_time` is invalid, `end_time` isn't after `start_time`, the source doesn't hold logs, or `service` is set on a source that has no service fields. Set up service fields in the source's settings under **Extract services**."
body = '''
{
  "errors": "Sorry, some values are incorrect",
  "invalid_values": {
    "level": "level must be one of error, warn, info, debug, all."
  }
}
'''

[[response]]
status = 422
description = "The time range holds too many logs to read. `errors` says why, and `refusal` lists time windows that each fit, the same way [Run a query](/docs/logs/api/query/) does. Ask for each window with its `start_time` and `end_time`, or for a shorter time range."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The ID of the log pattern, such as `cb97bef4cd1cbd14afe4a7b9aa7b74a2`."

[[param]]
name = "type"
type = "string"
description = "Always `log_pattern`."

[[param]]
name = "message"
type = "string or null"
description = "The message of the pattern's latest log in the time range, cut to 1000 characters. `null` when its logs have no `message` field."

[[param]]
name = "occurrences"
type = "integer"
description = "Number of logs with this pattern in the time range."

[[param]]
name = "first_seen_at"
type = "datetime"
description = "When the pattern's first log in the time range was received. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "last_seen_at"
type = "datetime"
description = "When the pattern's latest log in the time range was received. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "samples"
type = "array of objects"
description = "The pattern's count per `step`, oldest first, for each step that has logs. Returned only when `step` is set."

[[param]]
name = "samples[].time"
type = "datetime"
description = "When the step starts. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "samples[].count"
type = "integer"
description = "Number of logs with this pattern in the step."

[[param]]
name = "logs"
type = "array of objects"
description = "The pattern's 10 newest logs in the time range, newest first. Returned by get only."

[[param]]
name = "logs[].dt"
type = "datetime"
description = "When the log was received. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "logs[].level"
type = "string or null"
description = "The log's level, from the first of its `level`, `severity`, `severity_text`, `message.level`, `log.level`, `vercel.level` and `outcome` fields it has. `null` when it has none of them."

[[param]]
name = "logs[].message"
type = "string or null"
description = "The log's message, cut to 1000 characters. `null` when the log has no `message` field."
[/params]

#### Example cURL

[code-tabs]
```shell
[label Errors of one service]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/sources/123456/log-patterns?start_time=now-6h&level=error&service=checkout" \
  --header "Authorization: Bearer $TOKEN"
```
```shell
[label Errors over time]
curl --request GET \
  --url "https://telemetry.betterstack.com/api/v4/sources/123456/log-patterns?start_time=now-6h&level=error&step=15m" \
  --header "Authorization: Bearer $TOKEN"
```
[/code-tabs]
