Skip to main content
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 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.
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 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.
  • 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

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. {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 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.

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.

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.
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 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.
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.
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 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.
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.
  • 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.

Next steps

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