# ai_usage.summary

Gasto de IA da conta. Soma de chamadas, tokens e custo em USD das chamadas de IA da conta atual no período, agrupada por pessoa, modelo, recurso ou dia (fuso de São Paulo).

- Endpoint: `POST https://app.atomiks.com.br/api/v1/ai_usage.summary` (corpo JSON)
- Quem pode chamar: administrador da conta
- Escopo da chave: `activity:read`
- Grava dados: não
- Pela chave de API: sim
- Ferramenta MCP: `ai_usage_summary`
- Ficha em JSON: `https://app.atomiks.com.br/api/v1/openapi.json` (operationId `ai_usage.summary`)

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `from` | string (date-time) | sim |  |
| `to` | string (date-time) | sim |  |
| `groupBy` | "account" \| "user" \| "model" \| "feature" \| "day" | sim |  |

<details><summary>JSON Schema</summary>

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "from": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "to": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "groupBy": {
      "type": "string",
      "enum": [
        "account",
        "user",
        "model",
        "feature",
        "day"
      ]
    }
  },
  "required": [
    "from",
    "to",
    "groupBy"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/ai_usage.summary \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"from":"2026-10-01T00:00:00-03:00","to":"2026-11-01T00:00:00-03:00","groupBy":"user"}'
```

CLI:

```bash
node cli/atomiks.mjs ai_usage.summary --json '{"from":"2026-10-01T00:00:00-03:00","to":"2026-11-01T00:00:00-03:00","groupBy":"user"}'
```

MCP: ferramenta `ai_usage_summary` com a mesma entrada.

## Saída

Sucesso: `{"data": ...}` com o formato abaixo.

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "totals": {
      "type": "object",
      "properties": {
        "calls": {
          "type": "number"
        },
        "inputTokens": {
          "type": "number"
        },
        "outputTokens": {
          "type": "number"
        },
        "costUsd": {
          "type": "number"
        }
      },
      "required": [
        "calls",
        "inputTokens",
        "outputTokens",
        "costUsd"
      ],
      "additionalProperties": false
    },
    "rows": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "calls": {
            "type": "number"
          },
          "inputTokens": {
            "type": "number"
          },
          "outputTokens": {
            "type": "number"
          },
          "cacheReadTokens": {
            "type": "number"
          },
          "audioSeconds": {
            "type": "number"
          },
          "costUsd": {
            "type": "number"
          }
        },
        "required": [
          "key",
          "label",
          "calls",
          "inputTokens",
          "outputTokens",
          "cacheReadTokens",
          "audioSeconds",
          "costUsd"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "totals",
    "rows"
  ],
  "additionalProperties": false
}
```

## Erros

`{"error": {"code", "message", "requestId"}}`. Códigos: `invalid_input` (400), `unauthorized` (401), `forbidden` / `account_pending` / `scope_missing` (403), `not_found` (404), `limit_reached` (409), `internal` (500).
