Get Daily Cost with the REST APIBeta
Get the LLM cost per day for your organization or a workspace, for example to use it in your own reports.
About This Task
To use daily cost data outside the Cost Management page, call the Get Token Usage Cost Over Time endpoint, also called the cost-over-time endpoint. It returns the cost per UTC day in US dollars:
GET /api/v2/cost/organizations/{organization_id}/stats/cost-over-time
Users with the Costs permission must pass a workspace_id. Only Organization Admins can leave it out to get organization-wide data.
Prerequisites
- You need an API key. For details, see Generate API Keys.
- You need your organization ID. For details, see Organization ID.
- To get the data of one workspace, you need its workspace ID. For details, see Workspace ID.
Get the Cost per Day
Without extra parameters, the response contains one point per day. To split each day, add these optional query parameters:
group_by: The dimension to split by:model,workspace,pipeline,deployment,provider, orapi_key.deploymentis called a service in the UI.group_limit: How many of the groups with the highest cost keep their own points. The default is 5 and the maximum is 20.
This request splits each day by provider and keeps the five providers with the highest cost. Replace <ORGANIZATION_ID> with your organization ID and <YOUR_API_KEY> with your Haystack Platform API key:
curl --request GET \
"https://api.cloud.deepset.ai/api/v2/cost/organizations/<ORGANIZATION_ID>/stats/cost-over-time?group_by=provider&group_limit=5" \
--header "Authorization: Bearer <YOUR_API_KEY>"
Read the Response
With group_by, the response contains:
group_by: The dimension you chose.groups: Every group the points refer to, in stack order. Each group has akey, alabel, and akind. Thekindisgroupfor a group with high cost,otherfor the merged remaining groups, orunattributedfor usage with no value for the dimension.data: One point per day and group. Each point has agroupfield with one of the keys ingroups. A day's points add up to the day's total.
Without group_by, group_by and groups are null.
Get Totals and Breakdowns
The API also has endpoints for totals, breakdown, and cost flow. The breakdown endpoint returns one page of groups at a time. Use sort_by, sort_order, limit, and page_number to sort the groups and page through them, and check has_more to see whether more pages follow.
Related Information
Was this page helpful?