Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Costs

admin.organization.usage.costs(UsageCostsParams**kwargs) -> UsageCostsResponse
GET/organization/costs

Get costs details for the organization.

ParametersExpand Collapse
start_time: int

Start time (Unix seconds) of the query time range, inclusive.

api_key_ids: Optional[Sequence[str]]

Return only costs for these API keys.

bucket_width: Optional[Literal["1d"]]

Width of each time bucket in response. Currently only 1d is supported, default to 1d.

end_time: Optional[int]

End time (Unix seconds) of the query time range, exclusive.

group_by: Optional[List[Literal["project_id", "line_item", "api_key_id"]]]

Group the costs by the specified fields. Support fields include project_id, line_item, api_key_id and any combination of them.

limit: Optional[int]

A limit on the number of buckets to be returned. Limit can range between 1 and 180, and the default is 7.

page: Optional[str]

A cursor for use in pagination. Corresponding to the next_page field from the previous response.

project_ids: Optional[Sequence[str]]

Return only costs for these projects.

ReturnsExpand Collapse
class UsageCostsResponse: …
data: List[Data]
has_more: bool
next_page: Optional[str]
object: Literal["page"]

Costs

import os
from openai import OpenAI

client = OpenAI(
    admin_api_key=os.environ.get("OPENAI_ADMIN_KEY"),  # This is the default and can be omitted
)
response = client.admin.organization.usage.costs(
    start_time=0,
)
print(response.data)
{
    "object": "page",
    "data": [
        {
            "object": "bucket",
            "start_time": 1730419200,
            "end_time": 1730505600,
            "results": [
                {
                    "object": "organization.costs.result",
                    "amount": {
                        "value": 0.06,
                        "currency": "usd"
                    },
                    "line_item": null,
                    "project_id": null,
                    "api_key_id": null,
                    "quantity": null
                }
            ]
        }
    ],
    "has_more": false,
    "next_page": null
}
Returns Examples
{
    "object": "page",
    "data": [
        {
            "object": "bucket",
            "start_time": 1730419200,
            "end_time": 1730505600,
            "results": [
                {
                    "object": "organization.costs.result",
                    "amount": {
                        "value": 0.06,
                        "currency": "usd"
                    },
                    "line_item": null,
                    "project_id": null,
                    "api_key_id": null,
                    "quantity": null
                }
            ]
        }
    ],
    "has_more": false,
    "next_page": null
}