# get_site_ai_stats

Source: https://modulify.ai/docs/api/ai/get-site-ai-stats

Counts the AI requests, tokens and credits of a site over a period, per hour, day or month and per model, the way the Insights tab shows them.

- Title: Count the AI usage of a site over time
- Scope: `config:read`
- Access: Read only
- Endpoint: `POST /v1/get_site_ai_stats`

The answer is `stats`. `totals` covers the whole window with `requests`, `errors`, `inputTokens`, `outputTokens` and `credits`. `series` holds one entry per hour, day or month, as `granularity` says, with the bucket in `date` as `YYYY-MM-DDTHH:00`, `YYYY-MM-DD` or `YYYY-MM` in UTC and the same five counts. A bucket without a request comes back as zeros, so the list always covers the full window. `day` and `24h` come by the hour, `12mo` and `all` by the month and the other periods by the day, and a custom range by the hour, day or month depending on how long it is.

`models` splits the counts of the window per model the site asked for, with each model's `averageLatencyMs`, most credits first. `errors` counts the requests that failed, which cost nothing. `credits` is what the requests cost, rounded to two decimals, which is not the same as the usage the site bought from the workspace: `get_site_ai_settings` carries this month's purchases as `creditsBought`.

These are the numbers the **Insights** tab of the **AI** tab draws, and `list_site_ai_requests` lists the requests behind them one by one. Only these counts are kept: what your visitors asked and what the AI answered is never stored. See [Insights and history](https://modulify.ai/docs/built-in/ai#insights-and-history).

## Request

Call it with a `POST` to `https://api.modulify.ai/v1/get_site_ai_stats`, sending the inputs below as a JSON object. The token needs the `config:read` scope.

It only reads and changes nothing, so retrying it is safe.

```bash
curl -X POST https://api.modulify.ai/v1/get_site_ai_stats \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"projectId":"PROJECT_ID"}'
```

Over MCP, the same method is the [get_site_ai_stats tool](https://modulify.ai/docs/mcp/ai/get-site-ai-stats).

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `projectId` | string | Yes | The site id. |
| `period` | string | No | One of `day`, `24h`, `7d`, `30d`, `90d`, `12mo` or `all`. `day` is today so far, from midnight UTC, `24h` is the current hour and the 23 before it, `7d`, `30d` and `90d` are the last 7, 30 and 90 days counting today, `12mo` is this month and the 11 before it, and `all` reaches back to the first request. Defaults to the last 30 days, and is left out when you send `from` and `to`. |
| `from` | string | No | The first day of a custom range as `YYYY-MM-DD` in UTC, sent together with `to`. |
| `to` | string | No | The last day of a custom range as `YYYY-MM-DD` in UTC, included in the range and sent together with `from`. |

## Response

Every call answers with the [JSON envelope](https://modulify.ai/docs/api/requests-and-responses#the-response) of `success`, `message`, `data`, `code` and `version`. `data` holds the result described above, and on a method that returns a total, `count` carries it. The [response headers](https://modulify.ai/docs/api/requests-and-responses#headers-on-every-method-call) carry the call's `X-Request-Id` and what is left of your per-minute budget in `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. [Errors](https://modulify.ai/docs/api/errors) explains every status code a call can answer with.