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

UsageCostsResponse admin().organization().usage().costs(params, requestOptions = RequestOptions.none())
GET
/organization/costs

Get costs details for the organization.

Parameters
UsageCostsParams params
long startTime

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

Optional<List<String>> apiKeyIds

Return only costs for these API keys.

Optional<BucketWidth> bucketWidth

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

Optional<Long> endTime

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

Optional<List<GroupBy>> groupBy

Group the costs by the specified fields. Supported fields include project_id, user_id, line_item, api_key_id, and api_source. Support for combining user_id with project_id grouping or the project_ids filter depends on the organization and requested time range. Unsupported combinations return HTTP 400. When grouped by api_source, results use agents_api for attributed Agents API activity and unlabeled for all other activity. Without source grouping, api_source is null.

Optional<Long> limit

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

Optional<List<String>> lineItems

Return only costs for these exact line item names. Each value must match the complete line_item value, for example gpt-6-astra, input_tokens.

Optional<String> page

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

Optional<List<String>> projectIds

Return only costs for these projects.

Returns
class UsageCostsResponse:
List<Data> data
boolean hasMore
Optional<String> nextPage
JsonValue; object_
constant
constant

Costs

package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.admin.organization.usage.UsageCostsParams;
import com.openai.models.admin.organization.usage.UsageCostsResponse;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        UsageCostsParams params = UsageCostsParams.builder()
            .startTime(0L)
            .build();
        UsageCostsResponse response = client.admin().organization().usage().costs(params);
    }
}
{
    "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,
                    "quantity_unit": 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,
                    "quantity_unit": null
                }
            ]
        }
    ],
    "has_more": false,
    "next_page": null
}