Cost API multiple issues (empty results and page token malformed, no line_item)

Early Start Date

Using an early start time breaks everything:

➜ git:(main) curl "https://api.openai.com/v1/organization/costs?start_time=1730419200&limit=1" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
-H "Content-Type: application/json"

{
  "object": "page",
  "has_more": true,
  "next_page": "page_AAAAAGg6Ki_Tpl6uAAAAAGcla4A=",
  "data": []
}
➜ git:(main) curl "https://api.openai.com/v1/organization/costs?start_time=1730419200&page=page_AAAAAGg6Ki_Tpl6uAAAAAGcla4A" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
-H "Content-Type: application/json"

{
  "error": {
    "message": "The page token is malformed.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_request_error"
  }
}

As you can see, Hasmore returns true with a page token that is later considered to be malformed, and there is no data.

This seems to be related to an issue where if the start_time is from before the account existed? I’m seeing a similar issue in the actual dashboard if I choose a date range that starts before the account existed, the UI doesn’t respond.
If I choose a start time that’s more recent, then it works as expected.

Line Items is null

When I do get results, line_item is always null. Is this a value that I should be populating on requests so that it is tracked for cost?

1 Like