> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routerlink.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage API

> Query your organization's usage, per-key spend and call details with an API key.

The Usage API lets an **organization admin** read the organization's usage with an API key, the same numbers the console shows on **Usage** and **Logs**: usage per member, per key, per tag, per model and per day, call-by-call details with a cost breakdown, and the CSV export.

> [!NOTE]
>
> The Usage API is enabled per organization. To turn it on for yours, contact [support](https://routerlink.ai/support) with your organization name.

## Authentication

Send an API key in the `Authorization` header, exactly as for model calls:

```bash theme={null}
-H "Authorization: Bearer <ROUTERLINK_API_KEY>"
```

| Endpoint | Which key |
| - | - |
| `GET /key` | Any key of an enabled organization (returns that key's own data) |
| `GET /org/usage`, `GET /org/requests`, `GET /org/requests/export` | An **organization key** whose owner is currently an **admin** of the organization |

Base URL: `https://router-link.world3.ai/api/v1`

Keys keep their own restrictions here too: a disabled or expired key, or a call from outside the key's IP allowlist, is rejected as it would be for a model call.

## Time ranges

* `start` and `end` are ISO 8601 instants, for example `2026-11-01T00:00:00Z`. Without a time zone they are read as UTC.
* The range is `[start, end)`. `end` defaults to now and `start` to 24 hours before `end`. The longest range is **31 days**.
* Day and week buckets (`group_by=day|week`) use **Beijing time (UTC+8)**, like the console charts. Weeks start on Monday.

## Get the calling key

**GET /key** `endpoint`

Settings, budget and recent usage of the key you call with.

```bash theme={null}
curl https://router-link.world3.ai/api/v1/key \
  -H "Authorization: Bearer <ROUTERLINK_API_KEY>"
```

```json theme={null}
{
  "api_key_id": "7f0c…",
  "key_name": "prod",
  "key_masked": "sk-or-v1-abc***xyz",
  "scope": "team",
  "org_id": "3c3f…",
  "is_active": true,
  "created_at": "2026-10-01T08:00:00+00:00",
  "expires_at": null,
  "model_allowlist": null,
  "budget_usd": 100.0,
  "budget_used_usd": 12.5,
  "budget_remaining_usd": 87.5,
  "budget_reset": "monthly",
  "resets_at": "2026-12-01T00:00:00+00:00",
  "usage": {
    "today":    { "requests": 3, "total_tokens": 4100, "cost_usd": 0.012, "cost_credits": 12.0, "cache_read_tokens": 0, "cache_write_tokens": 0, "cache_read_credits": 0.0, "cache_write_credits": 0.0 },
    "month":    { "…": "same fields" },
    "last_30d": { "…": "same fields" }
  }
}
```

* `budget_*` are `null` when the key has no budget. `resets_at` is the end of the current budget period.
* `today` and `month` start at the UTC day and UTC calendar month; `last_30d` is the last 30 days up to now.

## Organization usage

**GET /org/usage** `endpoint`

Usage of the whole organization, grouped and filtered. Organization admin keys only.

| Parameter | Description |
| - | - |
| `start`, `end` | Time range (see above) |
| `group_by` | `member` (default), `key`, `tag`, `model`, `day` or `week` |
| `member` | Only keys owned by this member (user id) |
| `api_key_id` | Only this key |
| `tag` | Only keys with this tag |
| `model` | Only this model (display name or model id, any case) |

Filters can be combined. With `group_by=member` only `member` and `model` filters are accepted.

> [tab] Spend per key
>
> ```bash theme={null}
> curl "https://router-link.world3.ai/api/v1/org/usage?group_by=key&start=2026-11-01T00:00:00Z&end=2026-11-24T00:00:00Z" \
>   -H "Authorization: Bearer <ROUTERLINK_API_KEY>"
> ```

> [tab] One member, per day
>
> ```bash theme={null}
> curl "https://router-link.world3.ai/api/v1/org/usage?group_by=day&member=<USER_ID>&start=2026-11-17T00:00:00Z" \
>   -H "Authorization: Bearer <ROUTERLINK_API_KEY>"
> ```

> [tab] Python
>
> ```python theme={null}
> import httpx
>
> r = httpx.get(
>     "https://router-link.world3.ai/api/v1/org/usage",
>     headers={"Authorization": "Bearer <ROUTERLINK_API_KEY>"},
>     params={"group_by": "member", "start": "2026-11-01T00:00:00Z"},
>     timeout=60,
> )
> r.raise_for_status()
> for row in r.json()["rows"]:
>     print(row["user_email"], row["requests"], row["cost_usd"])
> ```

```json theme={null}
{
  "org_id": "3c3f…",
  "start": "2026-11-01T00:00:00+00:00",
  "end": "2026-11-24T00:00:00+00:00",
  "group_by": "key",
  "timezone": "Asia/Shanghai",
  "totals": { "requests": 120, "total_tokens": 98000, "cost_usd": 1.23 },
  "rows": [
    {
      "api_key_id": "7f0c…", "key_name": "prod", "key_masked": "sk-or-v1-abc***xyz", "status": "active",
      "user_id": "u_…", "user_email": "a@example.com", "role": "admin", "last_used": "2026-11-23T09:12:00+00:00",
      "requests": 100, "total_tokens": 90000, "cost_usd": 1.0,
      "cache_read_tokens": 0, "cache_write_tokens": 0, "cache_read_credits": 0.0, "cache_write_credits": 0.0
    }
  ]
}
```

Rows per `group_by`:

| `group_by` | One row per | Main fields |
| - | - | - |
| `member` | Member (a member who left and rejoined has one row per membership) | `user_id`, `user_email`, `role`, `status` (`Active` / `Removed`), `keys` |
| `key` | Key that has not been deleted (disabled keys show `status: "revoked"`) | `api_key_id`, `key_name`, `key_masked`, `status`, owner fields, `last_used` |
| `tag` | Tag (`null` = untagged) | `tag`, `keys` |
| `model` | Model | `model`, `display_name` |
| `day` / `week` | Day or week in the range, including empty ones | `date`, `start`, `end`, `partial` |

Every row also has `requests`, `total_tokens` and `cost_usd`; member, key and tag rows add the cache token and cache cost fields.

> [!NOTE]
>
> `totals` covers every key of the organization, including deleted keys. Rows of `key` and `tag` list only keys that still exist, and a key with several tags is counted under each tag, so the rows do not always add up to `totals`.

## Call details

**GET /org/requests** `endpoint`

The organization's calls, newest first, with cursor paging. Organization admin keys only.

| Parameter | Description |
| - | - |
| `start`, `end` | Time range (see above) |
| `member`, `api_key_id`, `tag`, `model` | Filters, as for `/org/usage` |
| `status` | `success` (HTTP \< 400), `error` (HTTP ≥ 400) or a status code such as `429` |
| `limit` | Page size, 1–100, default 50 |
| `cursor` | `next_cursor` from the previous page |

```bash theme={null}
curl "https://router-link.world3.ai/api/v1/org/requests?api_key_id=<KEY_ID>&status=error&limit=100" \
  -H "Authorization: Bearer <ROUTERLINK_API_KEY>"
```

```json theme={null}
{
  "org_id": "3c3f…",
  "start": "2026-11-23T10:00:00+00:00",
  "end": "2026-11-24T10:00:00+00:00",
  "items": [
    {
      "request_id": "d4339886-78b6-…",
      "created_at": "2026-11-24T01:02:03",
      "model": "Claude Sonnet 4.5",
      "endpoint": "/v1/chat/completions",
      "status_code": 200,
      "duration_ms": 812,
      "input_tokens": 1000, "output_tokens": 200, "total_tokens": 1200,
      "cache_read_tokens": 0, "cache_write_tokens": 0,
      "cost_usd": 0.0042, "cost_credits": 4.2,
      "cost_breakdown": { "…": "see below" },
      "api_key_id": "7f0c…", "api_key_name": "prod",
      "user_id": "u_…", "user_email": "a@example.com"
    }
  ],
  "next_cursor": "MjAyNi0xMS0yNFQwMTowMjowM3w0Mg"
}
```

> [!WARNING]
>
> **Paging:** pass the same filters **and the `start` / `end` returned by the first page** on every following page, together with `cursor`. If you leave `start` / `end` out, the default window moves with the clock while you page, and a long walk ends with `400 invalid_cursor` or misses calls. `next_cursor: null` means the last page.

* `created_at` on call rows is **UTC without a time zone suffix** (for example `2026-11-24T01:02:03`). Do not parse it as local time.
* Rows include calls of deleted keys and of members who have left; `api_key_name` is `null` for a deleted key.

### Cost breakdown

`cost_breakdown` splits the call's cost by billing item. It is `null` for calls billed before breakdowns were recorded and for a few restricted channels.

```json theme={null}
{
  "v": 1,
  "items": {
    "input":       { "unit": "token", "quantity": 21,   "unit_price_usd": "8.0000000000",  "price_source": "org", "list_credits": "0.1680000000",  "cost_credits": "0.1680000000" },
    "output":      { "unit": "token", "quantity": 97,   "unit_price_usd": "40.0000000000", "price_source": "org", "list_credits": "3.8800000000",  "cost_credits": "3.8800000000" },
    "cache_read":  { "unit": "token", "quantity": 5054, "unit_price_usd": "0.2000000000",  "price_source": "org", "list_credits": "1.0108000000",  "cost_credits": "1.0108000000" },
    "cache_write": { "unit": "token", "quantity": 4010, "unit_price_usd": "10.0000000000", "price_source": "org", "list_credits": "40.1000000000", "cost_credits": "40.1000000000" }
  },
  "totals": { "list_credits": "45.1588000000", "discount_credits": "0.0000000000" },
  "time_window": null,
  "credits_per_usd": "1000.00"
}
```

| Field | Meaning |
| - | - |
| `items` | One entry per billing item (`input`, `output`, `cache_read`, `cache_write`, web search requests, video seconds, …) |
| `unit` | `token`, `request` or `second` |
| `quantity` | How many units were billed |
| `unit_price_usd` | Unit price before any time-of-day discount: per **1M tokens** for tokens, per request or per second otherwise |
| `price_source` | `list` (public price) or `org` (your organization's price) |
| `list_credits` / `cost_credits` | Credits before and after the time-of-day discount |
| `totals.discount_credits` | Total discount on this call |
| `time_window` | The off-peak window applied (`id`, `multiplier`), or `null` |
| `credits_per_usd` | Credits per US dollar used for this call |

The item `cost_credits` add up exactly to the row's `cost_credits`. Amounts are decimal **strings** to keep full precision.

## Export as CSV

**GET /org/requests/export** `endpoint`

The same CSV as **Export** on the console's organization logs page (one line per billing item). Organization admin keys only.

| Parameter | Description |
| - | - |
| `start`, `end` | Beijing-time dates `YYYY-MM-DD`; `end` is inclusive |
| `member`, `api_key_id`, `tag` | Filters |

```bash theme={null}
curl -o usage.csv "https://router-link.world3.ai/api/v1/org/requests/export?start=2026-11-01&end=2026-11-23" \
  -H "Authorization: Bearer <ROUTERLINK_API_KEY>"
```

## Amounts

* `cost_usd` is converted from credits at 1,000 credits = 1 USD, as in the console.
* On a call row, `cost_usd` is the price estimate shown in the console. If it ever differs from the credits, the credits are authoritative.

## Errors

Errors from the key check use the same format as model calls. Other errors return `{"detail": {"code": "…", "message": "…"}}`.

| Status | `code` | Meaning |
| - | - | - |
| 400 | `invalid_range` | `start` / `end` not ISO 8601, `start` ≥ `end`, or longer than 31 days; bad export dates |
| 400 | `invalid_group_by` | Unknown `group_by` |
| 400 | `invalid_filter` | Bad `status`, empty `tag`, or a filter that `group_by=member` does not accept |
| 400 | `invalid_cursor` | The cursor is not from this endpoint or is outside `[start, end)` |
| 401 | `api_key_expired` | The key has expired |
| 403 | `usage_api_not_enabled` | The Usage API is not enabled for this organization |
| 403 | `org_key_required` | The key is a personal key; use an organization key |
| 403 | `org_admin_required` | The key's owner is not an admin of the organization |
| 403 | `ip_not_allowed` | The call comes from outside the key's IP allowlist |
| 404 | `not_found` | `api_key_id` or `member` is not part of this organization |
| 429 | `rate_limited` | Too many calls; wait for `Retry-After` |
| 503 | `usage_timeout` / `busy` | The query took too long or the organization's queries are queued; retry after `Retry-After` |

## Limits

* Each endpoint allows **20 calls per minute** per user and organization (shared with the console's usage pages).
* `/org/usage` results are cached for 45 seconds when you pass an explicit `end`; call details are never cached.
* Large organizations: prefer shorter ranges and the CSV export for bulk downloads. Filtering by `status` reads more data and can be slower.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.