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

client.Admin.Organization.Usage.Costs(ctx, query) (*AdminOrganizationUsageCostsResponse, error)
GET/organization/costs

Get costs details for the organization.

ParametersExpand Collapse
query AdminOrganizationUsageCostsParams
StartTime param.Field[int64]

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

APIKeyIDs param.Field[[]string]Optional

Return only costs for these API keys.

BucketWidth param.Field[AdminOrganizationUsageCostsParamsBucketWidth]Optional

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

EndTime param.Field[int64]Optional

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

GroupBy param.Field[[]string]Optional

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

Limit param.Field[int64]Optional

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

LineItems param.Field[[]string]Optional

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.

Page param.Field[string]Optional

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

ProjectIDs param.Field[[]string]Optional

Return only costs for these projects.

ReturnsExpand Collapse
type AdminOrganizationUsageCostsResponse struct{…}
Data []AdminOrganizationUsageCostsResponseData
HasMore bool
NextPage string
Object Page

Costs

package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAdminAPIKey("My Admin API Key"),
  )
  response, err := client.Admin.Organization.Usage.Costs(context.TODO(), openai.AdminOrganizationUsageCostsParams{
    StartTime: 0,
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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,
                    "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
}