Hi OpenAI Support Team,
My name is Rambabu Rachamalla, and I am a Data Engineer at Fivetran. We are integrating the OpenAI source as part of our connector services, and during this implementation I encountered an issue with the Costs API pagination (endpoint: /v1/organization/costs).
When querying usage costs with pagination, I am receiving a next_page token even when the current page contains no data. The response also returns "has_more": true. However, when I attempt to use the provided next_page token, the API returns a 400 Bad Request with the message:
{
"error": {
"message": "The page token is invalid, have you modified the query parameters?",
"type": "invalid_request_error",
"code": "invalid_request_error"
}
}
Here is an example of one such response:
{
"object": "page",
"has_more": true,
"next_page": "page_AAAAAGk9P4XXKcmpAAAAAGWDgAA=",
"data": [
{
"object": "bucket",
"start_time": 1702944000,
"end_time": 1703030400,
"results": []
},
{
"object": "bucket",
"start_time": 1703030400,
"end_time": 1703116800,
"results": []
}
]
}
And here is the request I used:
curl --location 'https://api.openai.com/v1/organization/costs?start_time=1702562400&end_time=1703648800&group_by=project_id%2Cline_item&limit=7' \
--header 'Authorization: Bearer <TOKEN>' \
--header 'accept: application/json'
Even after handling pagination correctly (checking has_more, validating the data array, etc.), the issue persists. It appears the API is returning an unusable pagination token.
Could you please investigate this issue?
If you need more details, I am happy to provide request/response logs.
Thanks
Rambabu Rachamalla