Sample - OpenAI API
GET/organization/costs

List organization costs

Lists cost data for the organization over a specified Unix-time range. Use start_time and end_time to define the range, then apply project, API key, line item, grouping, and pagination filters as needed.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

9 parameters
start_timeintegerrequired
Start of the query time range as a Unix timestamp in seconds, inclusive.
end_timeintegeroptional
End of the query time range as a Unix timestamp in seconds, exclusive.
bucket_widthstringoptional
Width of each cost time bucket. Must be `1d`; defaults to `1d` when omitted.
Allowed:1dDefault:1d
project_idsarray<string>optional
Filter results to costs associated with the specified project identifiers.
api_key_idsarray<string>optional
Filter results to costs associated with the specified API key identifiers.
line_itemsarray<string>optional
Filter results to exact line item names, such as `gpt-6-astra, input_tokens`.
group_byarray<string>optional
Group costs by one or more of `project_id`, `line_item`, and `api_key_id`.
limitintegeroptional
Maximum number of cost buckets to return. Must range from 1 to 180; defaults to 7 when omitted.
Default:7
pagestringoptional
Cursor from the previous response's `next_page` field for retrieving the next page of results.

2 status codes
200Returns a paginated costs response containing cost buckets, grouping results, a `has_more` indicator, and a `next_page` cursor.
objectstringrequired
Allowed:page
dataarray<object>required
has_morebooleanrequired
next_pagestringrequired
429Returned when the request was rejected because a rate limit was exceeded.
errorobjectrequired

Error handling

start_time must be provided as a Unix timestamp in seconds, and bucket_width only accepts 1d. limit must range from 1 to 180, while group_by values must be project_id, line_item, or api_key_id; a 429 is returned when the rate limit is exceeded.