# Analytics

> Usage over a date range grouped by team, person, model, provider, product, key or day. Owners and admins see the organization; members see their own usage and their teams'. by team, `depth` and `under` roll spend up the tree of teams.

## Usage

`GET /v1/analytics/usage`

Usage over a date range (UTC days, inclusive; at most 366): totals, groups with their share, and a daily series. Spend with no team is the Unassigned group. Owners and admins see the organization; members their own usage and their teams', with teammates as one row by person. An agent link sees only its person's own calls, as `person=me` does for anyone. with groupBy=team, `depth` and `under` roll spend up the tree: each group includes its teams below; spend on a team that has child teams, above the depth shown, is its own `(direct)` group. Members see rollups only from their own teams down. With groupBy=key, each key shows by its name and prefix, never its token. A revoked key keeps its name and says revoked. A person's Nexus UI sessions are one group. A member sees the keys of their own calls. All other calls in their teams are one Others row. A member's own call with no key is Unassigned. With groupBy=hour, each group is one UTC hour with calls (`YYYY-MM-DDTHH`), in order, under the same scope as by day; the series stays by day.

Permission: `spend.read_own` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `groupBy` | query | "team" \| "person" \| "model" \| "provider" \| "product" \| "key" \| "day" \| "hour" | no | How to group (default team) |
| `from` | query | string (date) | no | YYYY-MM-DD; default 29 days before to |
| `to` | query | string (date) | no | YYYY-MM-DD; default today |
| `team` | query | string | no | Only this team's usage and its child teams' (slug); members: their own teams and the teams under them |
| `depth` | query | integer | no | GroupBy=team: roll up to the teams at this depth (1 = top level; with `under`, counted below it) |
| `under` | query | string | no | GroupBy=team: roll up to the child teams of this team (slug) |
| `person` | query | "me" | no | `me`: only your own calls, under every groupBy, and `scope` is `own`. No other value is accepted (400). |

### Responses

- `200` OK (application/json, UsageReport)
  - `from` (string (date), required)
  - `to` (string (date), required)
  - `groupBy` ("team" | "person" | "model" | "provider" | "product" | "key" | "day", required)
  - `scope` ("org" | "member" | "own", required): `org`: the whole organization (owners and admins); `member`: your own usage and that of your teams and the teams under them; `own`: only your own calls (an agent link, or `person=me`).
  - `team` (object)
    - `id` (string)
    - `slug` (string)
    - `name` (string)
  - `totals` (object, required)
    - `spentUsd` (number): Deprecated: read `spentUsdDecimal`, the exact decimal string (root rule 9).
    - `spentUsdDecimal` (string | null): `spentUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `spentUsd`. `null` for a total, group or day with no call at all (root rule 9's empty day), where `spentUsd` is 0.
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `callsByStatus` (object): Calls by status, refused calls included. `calls` counts settled, failed and released calls only.
      - `settled` (integer, required)
      - `failed` (integer, required)
      - `refused` (integer, required)
      - `released` (integer, required)
    - `errorRate` (number | null): (failed + refused) / (settled + failed + refused), 0-1. Released calls count in neither part. `null` when there are no such calls.
    - `overspendPrevented` (object): The refused calls a spend limit stopped in the period, and what they asked to hold (`amountMicros` of the record's `overspendPrevented`, not what they would have cost), in all and by the level whose limit refused them. A refusal at a level other than these four counts nowhere. Zeros, not `null`, when no limit stopped a call. It equals the spend file's rows with an `overspendLevel` over the same days.
      - `calls` (integer, required)
      - `amountUsd` (number, required): Deprecated: read `amountUsdDecimal`, the exact decimal string (root rule 9).
      - `amountUsdDecimal` (string): `amountUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `amountUsd`.
      - `byLevel` (object, required)
        - `organization` (object, required)
          - `calls` (integer, required)
          - `amountUsd` (number, required): Deprecated: read `amountUsdDecimal`, the exact decimal string (root rule 9).
          - `amountUsdDecimal` (string): `amountUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `amountUsd`.
        - `team` (object, required)
          - `calls` (integer, required)
          - `amountUsd` (number, required): Deprecated: read `amountUsdDecimal`, the exact decimal string (root rule 9).
          - `amountUsdDecimal` (string): `amountUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `amountUsd`.
        - `person` (object, required)
          - `calls` (integer, required)
          - `amountUsd` (number, required): Deprecated: read `amountUsdDecimal`, the exact decimal string (root rule 9).
          - `amountUsdDecimal` (string): `amountUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `amountUsd`.
        - `product` (object, required): A product's monthly cap.
          - `calls` (integer, required)
          - `amountUsd` (number, required): Deprecated: read `amountUsdDecimal`, the exact decimal string (root rule 9).
          - `amountUsdDecimal` (string): `amountUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `amountUsd`.
  - `groups` (array of object, required)
    - `key` (string): Team id, user id, model, provider, product/capability, key id or day; `ui:<user id>` for a person's Nexus UI sessions; `unassigned` for no team (or person, or key); `others` for a member's teammates (or their keys).
    - `label` (string)
    - `share` (number)
    - `slug` (string)
    - `name` (string): Keys: the key's name, when it has one.
    - `prefix` (string): Keys: the first characters of the token, to recognise it. Never the token.
    - `deleted` (boolean): A team deleted since, or a key that no store holds. A key shows its id.
    - `revoked` (boolean): Keys: the key is revoked. It keeps its name and prefix, and its label ends with `, revoked`.
    - `spentUsd` (number): Deprecated: read `spentUsdDecimal`, the exact decimal string (root rule 9).
    - `spentUsdDecimal` (string | null): `spentUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `spentUsd`. `null` for a total, group or day with no call at all (root rule 9's empty day), where `spentUsd` is 0.
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `callsByStatus` (object): Calls by status, refused calls included. `calls` counts settled, failed and released calls only.
      - `settled` (integer, required)
      - `failed` (integer, required)
      - `refused` (integer, required)
      - `released` (integer, required)
    - `errorRate` (number | null): (failed + refused) / (settled + failed + refused), 0-1. Released calls count in neither part. `null` when there are no such calls.
    - `depth` (integer): Teams: how deep the team sits (1 = top level).
    - `level` (string)
    - `hasChildren` (boolean): Rollups: the team has child teams; drill in with `under=<slug>`.
    - `direct` (boolean): Rollups: spend attributed to the team itself, not to the teams under it (key `<teamId>:direct`).
    - `product` (string): By team, key `product:<product>/<capability>`: a module's own calls, with no team and no person (a review a GitHub event started). The module's product.
    - `capability` (string): By team, key `product:<product>/<capability>`: the module's capability.
  - `series` (array of object, required)
    - `day` (string (date))
    - `groups` (object): Spend per group key that day. Deprecated: read `groupsDecimal`, the same spend as exact decimal strings (root rule 9).
    - `groupsDecimal` (object): `groups` with each spend as an exact decimal string in US dollars with six decimals, from the micro-dollars. Prefer it to `groups`.
    - `spentUsd` (number): Deprecated: read `spentUsdDecimal`, the exact decimal string (root rule 9).
    - `spentUsdDecimal` (string | null): `spentUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `spentUsd`. `null` for a total, group or day with no call at all (root rule 9's empty day), where `spentUsd` is 0.
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `callsByStatus` (object): Calls by status, refused calls included. `calls` counts settled, failed and released calls only.
      - `settled` (integer, required)
      - `failed` (integer, required)
      - `refused` (integer, required)
      - `released` (integer, required)
    - `errorRate` (number | null): (failed + refused) / (settled + failed + refused), 0-1. Released calls count in neither part. `null` when there are no such calls.
  - `depth` (integer): Rollups: the depth shown, from the top level.
  - `under` (object)
    - `id` (string)
    - `slug` (string)
    - `name` (string)
    - `level` (string)
    - `path` (array of TeamLink)
      - `id` (string, required)
      - `slug` (string, required)
      - `name` (string, required)
      - `level` (string)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/analytics/usage" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.usage({ groupBy: "team", from: "2026-10-01", to: "2026-10-16", depth: "1" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fanalytics%2Fusage)

## Export usage CSV

`GET /v1/analytics/usage/export.csv`

The organization's usage, one row per day, team, person, model, provider and product, as CSV (owners and admins). At most 100,000 rows a file: past that the file stops, and its manifest says `complete: false` and gives `nextCursor`. Each export is an audit event (`observability.exported`) with the file's manifest, never its rows. An organization runs at most 60 exports an hour: the 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's). A bad filter is a 400 before any row.

Permission: `spend.export` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `from` | query | string (date) | no | The first UTC day, YYYY-MM-DD; default 29 days before `to` |
| `to` | query | string (date) | no | The last UTC day, YYYY-MM-DD, included; default today. A range covers at most 366 days |
| `team` | query | string | no | A team slug or id: that team and every team under it; `unassigned` for calls with no team |
| `person` | query | string | no | A person's user id |
| `model` | query | string | no | A model, as the rows name it; `-` for the calls with none (released calls), as Analytics groups them |
| `provider` | query | string | no | A provider, as the rows name it; `-` for the calls with none (refused and released calls), as Analytics groups them |
| `product` | query | string | no | A product (`agents`) or a product and capability (`intelligence/wiki`): Analytics' group key |
| `cursor` | query | string | no | A cut file's `manifest.nextCursor`: the next file of the same query. A manifest's `watermark` also works: it starts the same series again. It is bound to the organization, the caller and the query: anywhere else it is a 400 `invalid_cursor` |

### Responses

- `200` CSV with a header row: one column per field of `UsageRow`, in its order. (text/csv, string)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `export_rate_limited` | The 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's) |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/analytics/usage/export.csv" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.usageExport("csv", { team: "platform" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fanalytics%2Fusage%2Fexport.csv)

## Export usage JSON Lines

`GET /v1/analytics/usage/export.jsonl`

The organization's usage, one row per day, team, person, model, provider and product, as JSON Lines (owners and admins). At most 100,000 rows a file: past that the file stops, and its manifest says `complete: false` and gives `nextCursor`. Each export is an audit event (`observability.exported`) with the file's manifest, never its rows. An organization runs at most 60 exports an hour: the 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's). A bad filter is a 400 before any row.

Permission: `spend.export` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `from` | query | string (date) | no | The first UTC day, YYYY-MM-DD; default 29 days before `to` |
| `to` | query | string (date) | no | The last UTC day, YYYY-MM-DD, included; default today. A range covers at most 366 days |
| `team` | query | string | no | A team slug or id: that team and every team under it; `unassigned` for calls with no team |
| `person` | query | string | no | A person's user id |
| `model` | query | string | no | A model, as the rows name it; `-` for the calls with none (released calls), as Analytics groups them |
| `provider` | query | string | no | A provider, as the rows name it; `-` for the calls with none (refused and released calls), as Analytics groups them |
| `product` | query | string | no | A product (`agents`) or a product and capability (`intelligence/wiki`): Analytics' group key |
| `cursor` | query | string | no | A cut file's `manifest.nextCursor`: the next file of the same query. A manifest's `watermark` also works: it starts the same series again. It is bound to the organization, the caller and the query: anywhere else it is a 400 `invalid_cursor` |

### Responses

- `200` JSON Lines: one `UsageRow` per line, then one line `{"manifest": ExportManifest}`. (application/jsonl, string)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `export_rate_limited` | The 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's) |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/analytics/usage/export.jsonl" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.usageExport("jsonl", { team: "platform" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fanalytics%2Fusage%2Fexport.jsonl)

## Get agent adoption

`GET /v1/analytics/agents`

Agent adoption: for each UTC day of a range (inclusive; at most 366), the people whose agent calls (`nexus claude`, `nexus codex`) went through the agent gateway, with their email and how many calls. Refused calls are left out. Each day also lists the people with only `subscription` sessions that day. Each day also counts the active engineers by product: the people with at least one non-refused call that day, and for `agents` the people with only subscription sessions too. Owners and admins see the organization; members only themselves.

Permission: `spend.read_own` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `from` | query | string (date) | no | YYYY-MM-DD; default 29 days before to |
| `to` | query | string (date) | no | YYYY-MM-DD; default today |

### Responses

- `200` OK (application/json, AgentAdoption)
  - `from` (string (date), required)
  - `to` (string (date), required)
  - `scope` ("org" | "member", required)
  - `days` (array of object, required): Every day from `from` to `to`, oldest first; a day without agent calls has no people. Each day also counts its active engineers by product: the people with at least one non-refused call that day, and for `agents` the people with only subscription sessions too. A day with no such person has `engineers` 0 and no products.
    - `day` (string (date), required)
    - `people` (array of object, required)
      - `userId` (string, required)
      - `email` (string | null, required)
      - `calls` (integer, required) [min 1]
    - `subscription` (array of object, required): People with `subscription` sessions that day (their own Claude or ChatGPT plan) and no agent call through Gateway. A session counts when it reports its first model call. A person on both routes that day is in `people` only. Gateway keeps these counts for 367 days; days before Gateway counted them have none.
      - `userId` (string, required)
      - `email` (string | null, required)
      - `sessions` (integer, required) [min 1]
    - `engineers` (integer, required): Distinct active engineers that day over every product: a person with at least one non-refused call, or with a subscription session for agents. [min 0]
    - `products` (array of object, required): Active engineers by product slug (`core`, `agents`, `chat`), sorted by product, only products with someone. A person counts once per product, so these can add up to more than `engineers`. For `agents` the subscription-only people count too.
      - `product` (string, required)
      - `engineers` (integer, required) [min 1]
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/analytics/agents" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fanalytics%2Fagents)

## Get chat usage

`GET /v1/analytics/chat`

Chat sessions in numbers, never content or titles: sessions, messages, people and cost by mode and team (and person, for owners and admins). Members see their own.

Permission: `spend.read_own` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `days` | query | integer | no |  |

### Responses

- `200` OK (application/json, ChatUsage)
  - `scope` ("org" | "own")
  - `days` (integer)
  - `since` (string (date-time))
  - `retentionDays` (integer)
  - `totals` (object & object)
    - `sessions` (integer)
    - `messages` (integer)
    - `costUsd` (number): Deprecated: read `costUsdDecimal`, the exact decimal string (root rule 9).
    - `costUsdDecimal` (string): `costUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `costUsd`.
    - `people` (integer)
  - `byMode` (object)
    - `chat` (object)
      - `sessions` (integer)
      - `messages` (integer)
      - `costUsd` (number): Deprecated: read `costUsdDecimal`, the exact decimal string (root rule 9).
      - `costUsdDecimal` (string): `costUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `costUsd`.
    - `ask` (object)
      - `sessions` (integer)
      - `messages` (integer)
      - `costUsd` (number): Deprecated: read `costUsdDecimal`, the exact decimal string (root rule 9).
      - `costUsdDecimal` (string): `costUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `costUsd`.
  - `byTeam` (array of object & object)
    - `sessions` (integer)
    - `messages` (integer)
    - `costUsd` (number): Deprecated: read `costUsdDecimal`, the exact decimal string (root rule 9).
    - `costUsdDecimal` (string): `costUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `costUsd`.
    - `team` (string | null)
  - `byPerson` (array of object & object): Owners and admins
    - `sessions` (integer)
    - `messages` (integer)
    - `costUsd` (number): Deprecated: read `costUsdDecimal`, the exact decimal string (root rule 9).
    - `costUsdDecimal` (string): `costUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `costUsd`.
    - `userId` (string)
    - `email` (string)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/analytics/chat" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fanalytics%2Fchat)
