> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.lakera.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.lakera.ai/_mcp/server.

# Get analytics

POST https://platform.lakera.ai/api/v1-beta/analytics
Content-Type: application/json

Retrieve aggregated Guard request analytics bucketed by time and project.

The response groups buckets by project. Each bucket covers one `resolution` interval and contains request and detection counts for that interval.

**Authentication.** Use a Platform API key from the AI Guardrails Dashboard — not the Guard API key used for inference requests at `api.lakera.ai`.

**Timestamps.** Both `start_time` and `end_time` must be UTC (use the `Z` or `+00:00` suffix). Sub-minute seconds are silently floored to the nearest minute. After flooring, `start_time` must remain strictly before `end_time`.

**Resolution.** An ISO 8601 duration string: `PT{n}M`, `PT{n}H`, or `P{n}D` where `n` is a positive integer (e.g. `PT15M`, `PT6H`, `P7D`). The time range after flooring must divide evenly by the resolution. The maximum range is 180 days.

**Access.** This endpoint is available to select organizations. Contact your Check Point representative to request access. Community users may also reach out to [support@lakera.ai](mailto:support@lakera.ai).

Reference: https://docs.lakera.ai/api-reference/platform-api/analytics/get-analytics

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication using API key. Generate an API key from the AI Guardrails Dashboard. Example: Bearer sk_123... Keys carry one of two access scopes, chosen when the key is created: - **Read and write** — may call every endpoint. This is the default, and the scope of every key created before scopes were introduced. - **Read only** — may call read endpoints such as `/v1-beta/logs`, `/v1-beta/analytics` and the `GET` endpoints. Write endpoints return `403`. Issue a read-only key to anything that only needs to retrieve data, such as a log-shipping job or a dashboard, so that it cannot modify your policies or projects.

## Request

### Body (application/json)

This endpoint expects a GetAnalyticsRequest.

- `start_time` (string, required) — Start of the time range (inclusive). Must be a UTC timestamp — use the `Z` or `+00:00` suffix. Sub-minute seconds are silently floored.
- `end_time` (string, required) — End of the time range (exclusive). Must be a UTC timestamp. After flooring, must be strictly after `start_time`. The range may not exceed 180 days.
- `project_ids` (list of string, optional, default: []) — Filter to specific projects. Omit or pass an empty array to return analytics across all projects in your organization.
- `resolution` (string, optional, default: P1D) — Bucket size as an ISO 8601 duration: `PT{n}M`, `PT{n}H`, or `P{n}D` where `n` is a positive integer (e.g. `PT15M`, `PT6H`, `P7D`). The time range after flooring must divide evenly by the resolution.

## Response

### 200

Aggregated analytics bucketed by time and project

- `effective_start_time` (string, required) — The start of the time range after flooring sub-minute seconds, in UTC.
- `effective_end_time` (string, required) — The end of the time range after flooring sub-minute seconds, in UTC.
- `resolution` (string, required) — The bucket size used for this response, echoed from the request.
- `projects` (list of ProjectAnalytics, required) — Per-project time series

## Errors

### 400 Bad Request Error

Bad request

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

### 403 Forbidden Error

Access denied. Either the feature is not enabled for your organization, or the query exceeded ClickHouse resource limits — try narrowing the time range.

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

### 404 Not Found Error

A requested project ID does not belong to your organization. Requests sent without a project are logged under `project-lakera-default` (or `project-lakera-audio-default` for audio), which are always accepted. Archived projects count as found.

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

### 421 Misdirected Request Error

Your organization's data is stored in a different region than the one that received the request. `https://platform.lakera.ai` serves organizations stored in `eu-west-1`. Send the request to the regional host named in the message, for example `https://us-east-1.platform.lakera.ai`.

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

### 422 Unprocessable Entity Error

Bad request

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

## Types

### ProjectAnalytics

Time-series analytics for a single project

- `project_id` (string, optional, nullable) — The project ID. For requests made without an explicit project, this is the ID of the default project.
- `time_series` (list of AnalyticsBucket, optional) — Ordered list of time buckets for this project

### AnalyticsBucket

Aggregated Guard request counts for a single time bucket

- `timestamp` (string, required) — Start of this bucket, in UTC
- `num_requests` (integer, required) — Total number of Guard requests in this bucket
- `total_flagged` (integer, required) — Number of requests where at least one detector flagged
- `prompt_attack_flagged` (integer, required) — Requests flagged by the `prompt_attack` detector
- `moderation_flagged` (integer, required) — Requests flagged by any `moderated_content/*` detector
- `pii_flagged` (integer, required) — Requests flagged by any `pii/*` detector
- `unknown_links_flagged` (integer, required) — Requests flagged by the `unknown_links` detector
- `override_deny_flagged` (integer, required) — Requests flagged by the `override_deny` detector

## Examples

**Request**

```json
{
  "start_time": "2025-01-01T00:00:00Z",
  "end_time": "2025-02-01T00:00:00Z",
  "resolution": "P1D"
}
```

**Response**

```json
{
  "effective_start_time": "2025-01-01T00:00:00Z",
  "effective_end_time": "2025-02-01T00:00:00Z",
  "resolution": "P1D",
  "projects": [
    {
      "project_id": "string",
      "time_series": [
        {
          "timestamp": "2024-01-15T09:30:00Z",
          "num_requests": 1,
          "total_flagged": 1,
          "prompt_attack_flagged": 1,
          "moderation_flagged": 1,
          "pii_flagged": 1,
          "unknown_links_flagged": 1,
          "override_deny_flagged": 1
        }
      ]
    }
  ]
}
```

**SDK Code**

```python Analytics_getAnalytics_example
import requests

url = "https://platform.lakera.ai/api/v1-beta/analytics"

payload = {
    "start_time": "2025-01-01T00:00:00Z",
    "end_time": "2025-02-01T00:00:00Z",
    "resolution": "P1D"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Analytics_getAnalytics_example
const url = 'https://platform.lakera.ai/api/v1-beta/analytics';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"start_time":"2025-01-01T00:00:00Z","end_time":"2025-02-01T00:00:00Z","resolution":"P1D"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Analytics_getAnalytics_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://platform.lakera.ai/api/v1-beta/analytics"

	payload := strings.NewReader("{\n  \"start_time\": \"2025-01-01T00:00:00Z\",\n  \"end_time\": \"2025-02-01T00:00:00Z\",\n  \"resolution\": \"P1D\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Analytics_getAnalytics_example
require 'uri'
require 'net/http'

url = URI("https://platform.lakera.ai/api/v1-beta/analytics")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"start_time\": \"2025-01-01T00:00:00Z\",\n  \"end_time\": \"2025-02-01T00:00:00Z\",\n  \"resolution\": \"P1D\"\n}"

response = http.request(request)
puts response.read_body
```

```java Analytics_getAnalytics_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://platform.lakera.ai/api/v1-beta/analytics")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"start_time\": \"2025-01-01T00:00:00Z\",\n  \"end_time\": \"2025-02-01T00:00:00Z\",\n  \"resolution\": \"P1D\"\n}")
  .asString();
```

```php Analytics_getAnalytics_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://platform.lakera.ai/api/v1-beta/analytics', [
  'body' => '{
  "start_time": "2025-01-01T00:00:00Z",
  "end_time": "2025-02-01T00:00:00Z",
  "resolution": "P1D"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Analytics_getAnalytics_example
using RestSharp;

var client = new RestClient("https://platform.lakera.ai/api/v1-beta/analytics");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"start_time\": \"2025-01-01T00:00:00Z\",\n  \"end_time\": \"2025-02-01T00:00:00Z\",\n  \"resolution\": \"P1D\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Analytics_getAnalytics_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "start_time": "2025-01-01T00:00:00Z",
  "end_time": "2025-02-01T00:00:00Z",
  "resolution": "P1D"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://platform.lakera.ai/api/v1-beta/analytics")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```