# Admin API: analytics

### Reading your traffic back

Everything the dashboard's monitoring pages show is available as JSON under the [admin API](/docs/admin-api.html), with the same base URL and bearer authentication:

```
https://dashboard.aiproxy.com/api/v1
```

Use these to answer the questions you ask during a launch or an incident, from a script or an agent: who are the heaviest users and are they abusive, which clients are burning tokens, is latency or the error rate moving, what did a particular device log. The [agent operations guide](/docs/agent-ops.html) strings them together with the configuration endpoints.

| Question | Endpoint |
| --- | --- |
| How much traffic, how much rejected, how many tokens? | [summary](#summary) |
| Which clients are hammering requests or tokens? | [top\_clients](#top-clients) |
| Token usage by client, model, service, hour, or day | [tokens](#tokens) |
| A time series for a chart | [series](#series) |
| Time to first token and end-to-end latency | [latency](#latency) |
| What is failing and why | [errors](#errors) |
| Where traffic comes from | [top\_countries](#top-countries) |
| Individual requests, with provider and AIProxy status | [requests](#requests) |
| What the app logged | [logs](#logs) |
| WebSocket sessions (realtime APIs) | [websocket\_sessions](#websocket-sessions) |

### Time windows and filters

Every analytics endpoint takes the same time range parameters:

| Param | Description |
| --- | --- |
| `window` | A duration ending now: a number followed by `m`, `h`, `d`, or `w`, such as `15m`, `1h`, `1d`, `7d`, `4w`. Default `1d`, maximum 90 days. |
| `from`, `until` | Unix seconds. An explicit range instead of `window`. `until` defaults to now. |
| `service` | A service `api_uuid` to scope the answer to one service. Unknown values return `404`. |
| `client_id` | Where noted, scope to one client ID (the `aiproxy-client-id` the app sends, shown in the dashboard's request log). |

Responses echo the resolved range as `from` and `until` (unix seconds) and the `window` you passed, or `null` when you gave an explicit range. Counts and token totals are integers. Per-request analytics are kept for 90 days; logs for 30.

##### Records and aggregates

These endpoints read two kinds of data, and it helps to know which you are asking for:

- Records are individual items: one request in [request history](#requests), one log line in [logs](#logs), one WebSocket session. They carry everything about that item (headers, error bodies, timings, attributes) and are what you read to see exactly what happened to one device or one call. Request history keeps the full record for as long as the dashboard's Request History page does; logs are kept 30 days.
- Aggregates are sums, counts, and percentiles over every request in a window: [summary](#summary), [top clients](#top-clients), [tokens](#tokens), [series](#series), [latency](#latency), [errors](#errors), [top countries](#top-countries). They are computed from a compact per-request row (client, path, model, statuses, token counts, timings, country) kept for 90 days, and they answer in milliseconds over millions of requests, which is what makes "who used the most tokens this hour" a single call instead of a scan.

Use aggregates to find the question and records to answer it: top clients tells you which device to look at, request history and logs show what it did. The two are written by the proxy at the same moment, so they agree, though counts at the very edge of a window can differ by a few requests still being written.

Requests are measured by the proxy itself, so a request that AIProxy rejected (rate limited, banned, failed attestation) is counted with its `aiproxy_error_type`, and a request the provider answered carries the provider's status and, for OpenAI, Anthropic, Gemini, and the OpenAI-compatible hosts, the token counts from the provider's usage block. Foundation Models router requests carry the destination's usage.

### Summary

GET/projects/:uuid/analytics/summary

Params: `window` or `from`/`until`, `service`.

```
curl -s "$API/projects/4f865a6d/analytics/summary?window=1d" -H "$AUTH"
```

```
{
  "window": "1d", "from": 1788896000, "until": 1788982400,
  "requests": 184223,
  "unique_clients": 4211,
  "unique_ips": 3980,
  "provider_errors": 128,
  "rejected": 356,
  "rate_limited": 312,
  "banned": 41,
  "attestation_failed": 3,
  "tokens": {"input": 51200311, "cached_input": 20014400, "output": 8811020, "reasoning": 1200400, "total": 60011331},
  "rejections_by_type": {"rate_limited": 312, "client_banned": 40, "ip_banned": 1, "app_attest_failed": 3},
  "provider_status_counts": {"200": 184095, "429": 61, "500": 12, "529": 55}
}
```

- `provider_errors`: requests the provider answered with a status of 300 or above.
- `rejected`: requests AIProxy answered itself with an error, of which `rate_limited`, `banned` (`client_banned` + `ip_banned`), and `attestation_failed` (DeviceCheck and App Attest failures) are the common causes. `rejections_by_type` has every type.

### Top clients

GET/projects/:uuid/analytics/top\_clients

The heaviest client IDs in the window. Params: `window`, `service`, `by` = `requests` (default), `tokens`, or `errors`, `limit` (default 50, max 500).

```
curl -s "$API/projects/4f865a6d/analytics/top_clients?window=1h&by=tokens&limit=5" -H "$AUTH"
```

```
{
  "window": "1h", "from": 1788978800, "until": 1788982400, "by": "tokens",
  "clients": [
    {
      "client_id": "8C43A0F1-…",
      "requests": 912,
      "input_tokens": 4100200, "output_tokens": 310400, "total_tokens": 4410600,
      "provider_errors": 2, "rejected": 0,
      "first_seen": 1788979212, "last_seen": 1788982798,
      "ips": ["203.0.113.9"],
      "banned": false
    }
  ]
}
```

This is the dashboard's Top Client Usage leaderboard as data, with tokens added: sort `by=tokens` to find the client whose usage is out of proportion to its request count, then decide with [request history](#requests) and ban it through [the bans endpoint](/docs/admin-api.html). `banned` reflects the app's current client ID bans; `ips` lists the client's most frequent IPs in the window, for an IP ban when the client ID keeps changing.

### Token usage

GET/projects/:uuid/analytics/tokens

Params: `window`, `service`, `client_id`, `group_by` = `client` (default), `service`, `model`, `provider`, `hour`, or `day`, `limit` (default 100, max 1000).

```
curl -s "$API/projects/4f865a6d/analytics/tokens?window=7d&group_by=model" -H "$AUTH"
```

```
{
  "window": "7d", "from": 1788377600, "until": 1788982400, "group_by": "model",
  "rows": [
    {"key": "claude-sonnet-5", "requests": 40211, "input_tokens": 30100200, "cached_input_tokens": 12000000, "output_tokens": 5100400, "reasoning_tokens": 800100, "total_tokens": 36000700},
    {"key": "gpt-5-mini", "requests": 9020, "input_tokens": 2100200, "cached_input_tokens": 0, "output_tokens": 410400, "reasoning_tokens": 0, "total_tokens": 2510600}
  ]
}
```

Rows are sorted by `total_tokens` descending, except `hour` and `day`, which are sorted by time with `key` as the bucket's unix start. `total_tokens` is input plus output; cached input and reasoning tokens are already inside those and are broken out for cost estimates. `model` is the model named in the request (or the router's destination model); it is empty for requests without one.

### Time series

GET/projects/:uuid/analytics/series

The data behind the dashboard's charts. Params: `metric` = `requests`, `provider_errors`, `rejected`, `rate_limited`, `input_tokens`, `output_tokens`, `total_tokens`, `unique_clients`, or a latency percentile per bucket: `ttft_p50`, `ttft_p95`, `ttft_p99`, `e2e_p50`, `e2e_p95`, `e2e_p99` (milliseconds, `null` for a bucket in which no request reached a provider); `window` or `from`/`until`; `bucket` in seconds (optional, chosen from the range when omitted); `service`; `client_id`.

```
curl -s "$API/projects/4f865a6d/analytics/series?metric=requests&window=1h&bucket=60" -H "$AUTH"
```

```
{
  "metric": "requests", "from": 1788978800, "until": 1788982400, "bucket": 60,
  "points": [[1788978800, 41], [1788978860, 38], [1788978920, 0], …]
}
```

Every bucket in the range is present; empty buckets are `0`.

### Latency

GET/projects/:uuid/analytics/latency

Params: `window`, `service`, `metric` = `ttft` (default; time from the request reaching AIProxy to the provider's first byte) or `e2e` (the provider's full response, streaming included).

```
{
  "window": "1h", "from": 1788978800, "until": 1788982400,
  "metric": "ttft", "unit": "ms",
  "p50": 412, "p95": 1730, "p99": 4106,
  "sample_count": 9210
}
```

### Errors

GET/projects/:uuid/analytics/errors

Params: `window`, `service`. Provider statuses of 300 and above, and AIProxy's own rejections by type.

```
{
  "window": "1d", "from": 1788896000, "until": 1788982400,
  "provider": {"429": 61, "500": 12, "529": 55},
  "aiproxy": {"rate_limited": 312, "client_banned": 40, "device_check_failed": 3}
}
```

AIProxy error types are the `type` field of the JSON error the app received, for example `rate_limited`, `client_banned`, `ip_banned`, `quota_reached`, `device_check_failed`, `app_attest_failed`, `request_denied_bad_key`, `provider_timeout`.

### Top countries

GET/projects/:uuid/analytics/top\_countries

Params: `window`, `service`, `limit`. Country is the ISO 3166-1 alpha-2 code of the request's origin as seen at the edge; requests without one are omitted.

```
{
  "window": "1d", "from": 1788896000, "until": 1788982400,
  "countries": [{"country": "US", "requests": 88210}, {"country": "DE", "requests": 21044}]
}
```

### Request history

GET/projects/:uuid/requests

Individual requests, newest first, the same records as the dashboard's Request History page. Params: `status=failed` to list only requests that failed (a provider status outside 2xx, or a response that did not complete); `service`; `client_id`; `limit` (default and maximum 100); `before`, the `ms_since_epoch` of the last record you have, for the next page.

```
curl -s "$API/projects/4f865a6d/requests?client_id=8C43A0F1-…&limit=2" -H "$AUTH"
```

```
[
  {
    "time": "2026-09-09T19:39:58.412Z",
    "ms_since_epoch": 1788982798412,
    "client_id": "8C43A0F1-…",
    "service_uuid": "e88e2881",
    "path": "/v1/chat/completions",
    "rewritten_path": null,
    "method": "POST",
    "ip_address": "203.0.113.9",
    "provider_status": 200,
    "provider_error": null,
    "aiproxy_status": null,
    "aiproxy_error": null,
    "tokens": {"input": 1200, "cached_input": 0, "output": 340, "reasoning": null},
    "audio": null,
    "request_details": {"time-for-provider-first-byte-in-ms": 412, "time-for-provider-full-response-in-ms": 2210, "body-bytes-received-from-client": 3120, "body-bytes-returned-to-client": 9800},
    "request_headers": {"aiproxy-metadata": "v4|com.example.app|1.4|…", "user-agent": "…", "cloudfront-viewer-country-name": "United States"}
  }
]
```

Combining `status=failed` with `client_id` filters the client's page in memory, so a page can be shorter than `limit` while more pages remain; keep paging with `before` until an empty array comes back. `provider_error` is the provider's response body when its status was not 2xx. `aiproxy_status` and `aiproxy_error` are set when AIProxy answered the request itself (a rejection). `request_details` carries the proxy's timings and byte counts for that request.

### Logs

GET/projects/:uuid/services/:api\_uuid/logs

The OpenTelemetry log records an app sent to a service of type `otel_log_ingest`, newest first, kept for 30 days. Params: `limit` (default 100, max 500); `client_id`; `min_severity`, an OpenTelemetry severity number (`9` INFO, `13` WARN, `17` ERROR); `q`, a case-insensitive substring of the message; `event`, an exact event name; `attr`, repeatable, `key:value` for an exact attribute match (up to five, all must match); `before`, the `ts_ns` of the last record you have, for the next page.

```
curl -s "$API/projects/4f865a6d/services/d632dce0/logs?q=run-123&min_severity=9" -H "$AUTH"
```

```
[
  {
    "time": "2026-09-09T19:32:34.107133952Z",
    "ts_ns": 1788982354107133952,
    "received_at": "2026-09-09T19:32:34Z",
    "severity_number": 9, "severity_text": "INFO", "severity": "INFO",
    "event_name": "",
    "body": "run=run-123 [AIProxy] Reply in 2.08s: …",
    "attributes": {"code.file.path": "App/ContentView.swift", "code.function.name": "append(_:)", "code.line.number": "180"},
    "resource_attributes": {"service.name": "com.example.app", "service.version": "1.0", "app.build": "1", "os.name": "iOS", "os.version": "27.0.0", "device.model.identifier": "iPhone18,1"},
    "scope": {"name": "LogAt", "version": ""},
    "client_id": "D5EC1C56-…",
    "trace_id": "", "span_id": ""
  }
]
```

Apps send logs with the `AIProxyLogs` package (every `#logAt` line) or any OpenTelemetry SDK whose OTLP/HTTP endpoint is the plain service URL (the SDK appends `/v1/logs`). Log outcomes as events with attributes rather than prose, for example event `paywall.result` with `variant` and `outcome` attributes, then count them with `event=paywall.result&attr=variant:annual_first&attr=outcome:purchased`. A run id in the message or an attribute still works for one launch's records.

```
curl -s "$API/projects/4f865a6d/services/d632dce0/logs?event=paywall.result&attr=variant:annual_first&limit=500" -H "$AUTH"
```

### WebSocket sessions

GET/projects/:uuid/services/:api\_uuid/websocket\_sessions

Sessions proxied to a realtime API, newest first. Params: `limit` (default and maximum 100); `before`, the `ms_since_epoch` of the last record, for the next page.

```
[
  {
    "time": "2026-09-09T19:20:01.000Z",
    "ms_since_epoch": 1788981601000,
    "client_id": "8C43A0F1-…",
    "path": "/v1/realtime",
    "ip_address": "203.0.113.9",
    "session_duration_ms": 184210,
    "bytes_from_client": 921004,
    "bytes_from_provider": 3311020,
    "request_headers": {"user-agent": "…"}
  }
]
```


