Workspaces

Get Ai Usage

AI credits over the last `days` UTC days, or by month with `period` (RO-321, RO-383), from every LLM call: totals, by feature (assistant, writing, research, replies, knowledge, calls), by model, by person (background work has no person) and per day. `credits = round((input + output tokens) × the model's weight ÷ 1000)` on each group's summed tokens. Admins see the whole workspace; a member sees only their own usage (`scope: self`).

API key access

Needs the admin scope with an API key (ro_pat_...). A signed-in session uses the caller's role.
GET/api/v1/workspaces/current/ai-usage
AuthorizationBearer <token>

Access token from /api/v1/auth/login, or an API key (ro_pat_..., RO-176) from /api/v1/workspaces/current/api-keys: the key implies its workspace and needs the route's scope. MCP connectors (/api/v1/mcp only) may use an OAuth access token (ro_oat_..., RO-284).

In: header

Query Parameters

days?integer

Default 30.

Formatint64
Range1 <= value <= 90
period?string

current (this UTC month so far) or previous (the whole previous month); overrides days.

Header Parameters

X-Workspace-Id?string | null

Id of the workspace to act on (must be a member).

Response Body

curl -X GET "http://localhost:8000/api/v1/workspaces/current/ai-usage?days=1&period=string" \  -H "X-Workspace-Id: string"
{
  "from": "2019-08-24",
  "to": "2019-08-24",
  "days": 0,
  "total": {
    "calls": 0,
    "errors": 0,
    "input_tokens": 0,
    "output_tokens": 0,
    "credits": 0
  },
  "by_feature": [
    {
      "feature": "string",
      "label": "string",
      "calls": 0,
      "errors": 0,
      "input_tokens": 0,
      "output_tokens": 0,
      "credits": 0
    }
  ],
  "by_model": [
    {
      "model": "string",
      "label": "string",
      "provider": "string",
      "credits_weight": 0.1,
      "calls": 0,
      "errors": 0,
      "input_tokens": 0,
      "output_tokens": 0,
      "credits": 0
    }
  ],
  "by_user": [
    {
      "user_id": "a169451c-8525-4352-b8ca-070dd449a1a5",
      "name": "string",
      "email": "string",
      "calls": 0,
      "errors": 0,
      "input_tokens": 0,
      "output_tokens": 0,
      "credits": 0
    }
  ],
  "daily": [
    {
      "day": "2019-08-24",
      "credits": 0,
      "by_feature": {
        "property1": 0,
        "property2": 0
      }
    }
  ],
  "formula": {
    "tokens_per_unit": 0.1,
    "default_weight": 0.1,
    "text": "string"
  },
  "monthly_credits": 0,
  "period": "string",
  "scope": "string"
}
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}