logs

Get API request metrics

Changed on

Count the requests that the Unkey API served for your workspace per time bucket, split by status class.

The filters have the same shape as in logs.listApiRequests, without requestId. In one field, values under is, contains, startsWith, and endsWith are combined with OR. Values under isNot and notContains, and the range operators gt, gte, lt, and lte, are combined with AND. Different fields are combined with AND. Every text match is exact and case-sensitive.

filters.time sets the window. A missing lower bound is the start of your log retention, and a missing upper bound is now. Unkey picks the bucket width from the window. It is the distance between the time of two points. The first bucket starts at or before the window start and counts its whole width. Windows reach back at most 100 days, and requests outside the log retention of your workspace are not counted.

Required Permissions

Your root key must have the following permission:

  • unkey:v1:<workspace_id>:logs/apiRequests#read
post/v2/logs.getApiRequestMetrics

Request

  • Base URL
    https://api.unkey.com
  • URL
    https://api.unkey.com/v2/logs.getApiRequestMetrics
  • Auth
    HTTP bearer

Request body

Example request

{
  "filters": {
    "time": {
      "gte": 1791936000000,
      "lt": 1792022400000
    },
    "path": {
      "startsWith": [
        "/v2/keys."
      ],
      "notContains": [
        "verifyKey"
      ]
    },
    "method": {
      "is": [
        "POST",
        "PUT"
      ]
    },
    "status": {
      "gte": 400,
      "lt": 600,
      "isNot": [
        429
      ]
    }
  }
}

Response

One point per bucket, oldest first, with zero counts for buckets without requests.

Example response

{
  "meta": {
    "requestId": "req_123"
  },
  "data": [
    {
      "time": 1792020600000,
      "success": 1200,
      "clientError": 31,
      "serverError": 2,
      "total": 1233
    }
  ]
}

Changes