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

# Export usage and spend

> Read monthly cost and token usage by user, team, playbook, or billing group with the Consumption API.

This guide shows you how to read your organization's cost and token usage with the Consumption API. After you connect a script or a scheduled job, you can feed the same numbers shown in the [Consumption view](https://dev.writer.com/home/usage-and-spend.md) into chargeback, cost-center reporting, or your own analytics tools.

The API returns one month at a time. Breakdown endpoints list cost and tokens per user, team, playbook, or billing group. Daily endpoints return one row per day for the organization, a whole scope, or a single entity.

> [!NOTE]
>
> The Consumption API is available for cloud deployments only. Breakdown rows include each entity's ID and display name. A user's display name is their first and last name, or their email address when the profile has no name.

## Prepare your API key

Every request needs a Writer API key for the organization you query. See the [API keys guide](https://dev.writer.com/api-reference/api-keys.md) to create one.

* **Organization key** (**All teams**): reads every scope that's enabled for your organization. Use this for new integrations.
* **Team key** (legacy): reads only the team the key belongs to, in the `team`, `user`, and `playbook` scopes. See [Read usage with a team key](#read-usage-with-a-team-key).
* **User key** (**Specific user**): can't read consumption data. Requests return `403 Forbidden`.

## Call the daily endpoint

Request the daily cost and token usage for the whole organization for one month.

**URL:** `GET https://api.writer.com/api/billing/v1/organization/{organizationId}/consumption/daily`

```bash cURL theme={null}
curl --get --location \
  "https://api.writer.com/api/billing/v1/organization/<ORGANIZATION_ID>/consumption/daily" \
  --header "Authorization: Bearer $WRITER_API_KEY" \
  --data-urlencode "month=2026-10"
```

```python Python theme={null}
import os

import requests

organization_id = "<ORGANIZATION_ID>"
api_key = os.environ["WRITER_API_KEY"]

response = requests.get(
    "https://api.writer.com/api/billing/v1/organization/"
    f"{organization_id}/consumption/daily",
    headers={"Authorization": f"Bearer {api_key}"},
    params={"month": "2026-10"},
    timeout=60,
)
response.raise_for_status()

for day in response.json()["days"]:
    print(day["date"], day["cost_in_cents"], day["total_tokens"])
```

```javascript JavaScript theme={null}
const organizationId = "<ORGANIZATION_ID>";
const apiKey = process.env.WRITER_API_KEY;

const params = new URLSearchParams({ month: "2026-10" });

const response = await fetch(
  `https://api.writer.com/api/billing/v1/organization/${organizationId}/consumption/daily?${params}`,
  { headers: { Authorization: `Bearer ${apiKey}` } },
);

if (!response.ok) {
  throw new Error(`Consumption request failed with status ${response.status}`);
}

const body = await response.json();
for (const day of body.days) {
  console.log(day.date, day.cost_in_cents, day.total_tokens);
}
```

## Choose an endpoint

All endpoints share the prefix `https://api.writer.com/api/billing/v1/organization/{organizationId}/consumption`. The `organizationId` in the path must be the organization the API key belongs to.

| Method | Path | Returns |
| - | - | - |
| `GET` | `/breakdown/{scope}` | One row per entity in the scope, paginated |
| `GET` | `/breakdown/{scope}/{scopeId}` | One row for that entity |
| `GET` | `/daily` | One row per day for the organization |
| `GET` | `/daily/{scope}` | One row per day, summed across every entity in the scope |
| `GET` | `/daily/{scope}/{scopeId}` | One row per day for that entity |

`{scope}` is one of `user`, `team`, `playbook`, or `billing_group`. `{scopeId}` is the ID of one entity in that scope. User, team, and billing group IDs are integers. Playbook IDs are strings.

The scopes you can query match the scopes shown in the Consumption view for your organization. A scope that isn't enabled returns `403 Forbidden`. `/daily` without a scope requires the organization view.

See the [Consumption API reference](https://dev.writer.com/api-reference/consumption-api/list-consumption-breakdown.md) for every parameter and response field, and to try each endpoint.

## Set query parameters

These parameters select the month, page through breakdown rows, and limit users or playbooks to one team. `/daily` without a scope accepts only `month`.

| Parameter | Values | Default | Description |
| - | - | - | - |
| `month` | `YYYY-MM` | Required | Calendar month to read, in UTC. A missing or malformed month returns `400`. |
| `limit` | Integer from 1 to 100 | `50` | Rows per page. `/breakdown/{scope}` only. |
| `offset` | Integer ≥ 0 | `0` | Number of rows to skip. `/breakdown/{scope}` only. |
| `team_id` | Integer ≥ 1 | None | Counts only usage in one team. `user` and `playbook` scopes only. See [Filter users or playbooks by team](#filter-users-or-playbooks-by-team). |

## List cost by scope

Request a breakdown to see which users, teams, playbooks, or billing groups spent the most in a month. This example lists the first page of users.

```bash cURL theme={null}
curl --get --location \
  "https://api.writer.com/api/billing/v1/organization/<ORGANIZATION_ID>/consumption/breakdown/user" \
  --header "Authorization: Bearer $WRITER_API_KEY" \
  --data-urlencode "month=2026-10" \
  --data-urlencode "limit=100"
```

```python Python theme={null}
import os

import requests

organization_id = "<ORGANIZATION_ID>"
api_key = os.environ["WRITER_API_KEY"]

response = requests.get(
    "https://api.writer.com/api/billing/v1/organization/"
    f"{organization_id}/consumption/breakdown/user",
    headers={"Authorization": f"Bearer {api_key}"},
    params={"month": "2026-10", "limit": 100},
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

```javascript JavaScript theme={null}
const organizationId = "<ORGANIZATION_ID>";
const apiKey = process.env.WRITER_API_KEY;

const params = new URLSearchParams({ month: "2026-10", limit: "100" });

const response = await fetch(
  `https://api.writer.com/api/billing/v1/organization/${organizationId}/consumption/breakdown/user?${params}`,
  { headers: { Authorization: `Bearer ${apiKey}` } },
);

if (!response.ok) {
  throw new Error(`Consumption request failed with status ${response.status}`);
}

console.log(await response.json());
```

### Read a breakdown response

A breakdown response lists one row per entity, ordered by cost from highest to lowest, then by `scope_id`. This is the same order as the Consumption view.

```json theme={null}
{
  "scope": "user",
  "currency": "USD",
  "data": [
    { "scope_id": "42", "scope_name": "Ada Lovelace", "cost_in_cents": 1250, "total_tokens": 480000 },
    { "scope_id": "17", "scope_name": "grace.hopper@example.com", "cost_in_cents": 120, "total_tokens": 4500 }
  ],
  "pagination": { "limit": 100, "offset": 0, "total": 2 }
}
```

| Field | Type | Description |
| - | - | - |
| `scope` | string | The scope from the path. |
| `currency` | string | Currency of `cost_in_cents`. Always `USD`. |
| `data[].scope_id` | string | Entity ID. User, team, and billing group IDs are integers sent as strings. |
| `data[].scope_name` | string | Display name of the entity. For a user, the first and last name, or the email address when the user has no name. |
| `data[].cost_in_cents` | integer | Cost for the month, rounded to the nearest cent. |
| `data[].total_tokens` | integer | Tokens used in the month. |
| `pagination.limit` | integer | Page size used for this response. |
| `pagination.offset` | integer | Rows skipped before this page. |
| `pagination.total` | integer | Total rows across all pages. |

To read every row, increase `offset` by `limit` until `offset` reaches `pagination.total`. `/breakdown/{scope}/{scopeId}` returns the same shape with a single row. An entity with no usage in that month returns one row with zero cost and zero tokens, unless a [team filter](#filter-users-or-playbooks-by-team) applies.

## Read a daily series

Daily endpoints return one row for every day in the month, including days with no usage. Use `/daily/{scope}` for a whole scope summed into one series, or `/daily/{scope}/{scopeId}` for one entity.

```json theme={null}
{
  "currency": "USD",
  "generated_at": "2026-10-20T12:00:00Z",
  "days": [
    { "date": "2026-10-01", "cost_in_cents": 120, "total_tokens": 4500 },
    { "date": "2026-10-02", "cost_in_cents": 0, "total_tokens": 0 }
  ]
}
```

| Field | Type | Description |
| - | - | - |
| `currency` | string | Currency of `cost_in_cents`. Always `USD`. |
| `generated_at` | string | ISO 8601 time the cost series was calculated. Token counts are read at request time. |
| `days[].date` | string | Day in `YYYY-MM-DD` format. |
| `days[].cost_in_cents` | integer | Cost for that day. |
| `days[].total_tokens` | integer | Tokens used that day. |

The organization series and a scope series can differ. Usage with no ID for a scope, such as usage that isn't linked to a billing group, counts in `/daily` only.

## Filter users or playbooks by team

Add `team_id` to a `user` or `playbook` request to count only usage in one team. This is how you split a team's cost by person or by playbook for chargeback. This example lists October's cost per user in one team.

```bash cURL theme={null}
curl --get --location \
  "https://api.writer.com/api/billing/v1/organization/<ORGANIZATION_ID>/consumption/breakdown/user" \
  --header "Authorization: Bearer $WRITER_API_KEY" \
  --data-urlencode "month=2026-10" \
  --data-urlencode "team_id=<TEAM_ID>"
```

```python Python theme={null}
import os

import requests

organization_id = "<ORGANIZATION_ID>"
team_id = "<TEAM_ID>"
api_key = os.environ["WRITER_API_KEY"]

response = requests.get(
    "https://api.writer.com/api/billing/v1/organization/"
    f"{organization_id}/consumption/breakdown/user",
    headers={"Authorization": f"Bearer {api_key}"},
    params={"month": "2026-10", "team_id": team_id},
    timeout=60,
)
response.raise_for_status()

for row in response.json()["data"]:
    print(row["scope_name"], row["cost_in_cents"], row["total_tokens"])
```

```javascript JavaScript theme={null}
const organizationId = "<ORGANIZATION_ID>";
const teamId = "<TEAM_ID>";
const apiKey = process.env.WRITER_API_KEY;

const params = new URLSearchParams({ month: "2026-10", team_id: teamId });

const response = await fetch(
  `https://api.writer.com/api/billing/v1/organization/${organizationId}/consumption/breakdown/user?${params}`,
  { headers: { Authorization: `Bearer ${apiKey}` } },
);

if (!response.ok) {
  throw new Error(`Consumption request failed with status ${response.status}`);
}

const body = await response.json();
for (const row of body.data) {
  console.log(row.scope_name, row.cost_in_cents, row.total_tokens);
}
```

You should see one row per user with usage in that team. A user who works in several teams shows only their usage in this one.

`team_id` works the same way on `/breakdown/{scope}/{scopeId}`, `/daily/{scope}`, and `/daily/{scope}/{scopeId}`, with these differences:

* `/breakdown/user/{scopeId}` or `/breakdown/playbook/{scopeId}` for a user or playbook with no usage in the team returns an empty `data` array and a `pagination.total` of `0`, not a row with zero cost. That includes a user or playbook that isn't in the team.
* `/daily/user/{scopeId}` or `/daily/playbook/{scopeId}` for a user or playbook with no usage in the team returns zero for every day.
* `team_id` with any other scope returns `400`. To report on a whole team, use `/breakdown/team/{scopeId}` or `/daily/team/{scopeId}` with the team's ID.

## Read usage with a team key

Team keys are legacy keys. The API keys page can't create or edit them, so use an organization key for new integrations. To report on one team with an organization key, request `/breakdown/team/{scopeId}` or `/daily/team/{scopeId}` with that team's ID, or add [`team_id`](#filter-users-or-playbooks-by-team) to a `user` or `playbook` request.

An existing team key reads only its own team's usage, in the `team`, `user`, and `playbook` scopes. This example reads the daily usage of every playbook in the key's team.

```bash cURL theme={null}
curl --get --location \
  "https://api.writer.com/api/billing/v1/organization/<ORGANIZATION_ID>/consumption/daily/playbook" \
  --header "Authorization: Bearer $WRITER_TEAM_API_KEY" \
  --data-urlencode "month=2026-10"
```

```python Python theme={null}
import os

import requests

organization_id = "<ORGANIZATION_ID>"
api_key = os.environ["WRITER_TEAM_API_KEY"]

response = requests.get(
    "https://api.writer.com/api/billing/v1/organization/"
    f"{organization_id}/consumption/daily/playbook",
    headers={"Authorization": f"Bearer {api_key}"},
    params={"month": "2026-10"},
    timeout=60,
)
response.raise_for_status()

for day in response.json()["days"]:
    print(day["date"], day["cost_in_cents"], day["total_tokens"])
```

```javascript JavaScript theme={null}
const organizationId = "<ORGANIZATION_ID>";
const apiKey = process.env.WRITER_TEAM_API_KEY;

const params = new URLSearchParams({ month: "2026-10" });

const response = await fetch(
  `https://api.writer.com/api/billing/v1/organization/${organizationId}/consumption/daily/playbook?${params}`,
  { headers: { Authorization: `Bearer ${apiKey}` } },
);

if (!response.ok) {
  throw new Error(`Consumption request failed with status ${response.status}`);
}

const body = await response.json();
for (const day of body.days) {
  console.log(day.date, day.cost_in_cents, day.total_tokens);
}
```

Each scope returns only the key's team:

* `/breakdown/team` and `/daily/team` return only the key's team. The breakdown includes the team's row even when the team has no usage that month. `/breakdown/team/{scopeId}` and `/daily/team/{scopeId}` work when `scopeId` is the key's team.
* `/breakdown/user`, `/breakdown/playbook`, `/daily/user`, and `/daily/playbook` count only usage in the key's team, as if you passed the key's team as `team_id`. A user or playbook entity request follows the [team filter rules](#filter-users-or-playbooks-by-team).
* `team_id`, if you pass it, must be the key's own team.

The `billing_group` scope, another team's ID, or `/daily` without a scope returns `403 Forbidden`.

## Handle errors

Check the HTTP status on every response. Gateway authentication errors and service errors can use different response bodies. Service errors return JSON with an `errors` array, and each entry has a `description` that explains the problem, such as `limit must be from 1 to 100`.

| Status | When |
| - | - |
| `400` | `month` is missing, malformed, or earlier than the first month with consumption data (`Consumption data before YYYY-MM is unavailable`). `{scope}` is unknown. `{scopeId}` is malformed, for example a non-numeric user, team, or billing group ID. `limit` or `offset` is out of range. `team_id` isn't a positive integer, or is sent with a scope other than `user` or `playbook`. |
| `401` | The API key is missing or invalid. |
| `403` | The key belongs to a different organization, is a user key, or can't read the requested scope or team, such as a team key that passes another team's `team_id`. The scope isn't enabled for your organization. The service can't read your organization's Consumption view settings at the moment; retry the request later. |

## Next steps

Combine consumption data with request-level logs, or review usage in Control Center.

* [Usage and spend](https://dev.writer.com/home/usage-and-spend.md): View cost and token usage in the Consumption view
* [Export logs](https://dev.writer.com/home/logs-export.md): Poll LLM-call and agent-run records for your data warehouse
* [Consumption API reference](https://dev.writer.com/api-reference/consumption-api/list-consumption-breakdown.md): Review every endpoint, parameter, and response field
* [API keys](https://dev.writer.com/api-reference/api-keys.md): Create and manage the keys that call this API
