Skip to main content
The log query API returns the same records as the Logs page in the console: the model, API key, token counts, and charge for every call. Use it for daily reconciliation, per-key usage reports, or loading charges into your own billing system.
An invalid token still returns HTTP 200.
  • The body is {"success": false, "message": "...access token is invalid."} with no data.
  • Check success in your script. Relying on the status code alone makes an auth failure look like an empty log.

Query parameters

The page size is fixed; page_size and size are ignored. The response has no total count, so keep requesting the next page until one returns fewer than 10 records.

Send a request

Store the AccessToken in an environment variable:
Fetch the last hour of gpt-5.4-mini usage:
Send the AccessToken as is in Authorization; a Bearer prefix also works.

Response fields

other holds the multipliers, cache hits, and tool charges. For web search requests, web_search_billing lists the number of searches and their cost. If you only need the total charge, read quota. Responses can contain other fields as well; ignore the ones you don’t use.

Export a day of usage and total it by model

This script walks every page and totals the charge per model. It needs Python 3.9 or later and requests (python -m pip install requests).
A busy account can have thousands of pages per day. Fetch shorter time windows, or narrow the query with model_name or token_name.

Errors