Skip to content
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.

const AdminOrganizationUsageCostsParamsBucketWidth1d AdminOrganizationUsageCostsParamsBucketWidth = "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.

const AdminOrganizationUsageCostsParamsGroupByProjectID AdminOrganizationUsageCostsParamsGroupBy = "project_id"
const AdminOrganizationUsageCostsParamsGroupByLineItem AdminOrganizationUsageCostsParamsGroupBy = "line_item"
const AdminOrganizationUsageCostsParamsGroupByAPIKeyID AdminOrganizationUsageCostsParamsGroupBy = "api_key_id"
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.

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
EndTime int64
Object Bucket
Results []AdminOrganizationUsageCostsResponseDataResultUnion
One of the following:
type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageCompletionsResult struct{…}

The aggregated completions usage details of the specific time bucket.

InputTokens int64

The aggregated number of text input tokens used, including cached tokens. For customers subscribe to scale tier, this includes scale tier tokens.

NumModelRequests int64

The count of requests made to the model.

Object OrganizationUsageCompletionsResult
OutputTokens int64

The aggregated number of text output tokens used. For customers subscribe to scale tier, this includes scale tier tokens.

APIKeyID stringOptional

When group_by=api_key_id, this field provides the API key ID of the grouped usage result.

Batch boolOptional

When group_by=batch, this field tells whether the grouped usage result is batch or not.

InputAudioTokens int64Optional

The aggregated number of audio input tokens used, including cached tokens.

InputCachedTokens int64Optional

The aggregated number of text input tokens that has been cached from previous requests. For customers subscribe to scale tier, this includes scale tier tokens.

Model stringOptional

When group_by=model, this field provides the model name of the grouped usage result.

OutputAudioTokens int64Optional

The aggregated number of audio output tokens used.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

ServiceTier stringOptional

When group_by=service_tier, this field provides the service tier of the grouped usage result.

UserID stringOptional

When group_by=user_id, this field provides the user ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageEmbeddingsResult struct{…}

The aggregated embeddings usage details of the specific time bucket.

InputTokens int64

The aggregated number of input tokens used.

NumModelRequests int64

The count of requests made to the model.

Object OrganizationUsageEmbeddingsResult
APIKeyID stringOptional

When group_by=api_key_id, this field provides the API key ID of the grouped usage result.

Model stringOptional

When group_by=model, this field provides the model name of the grouped usage result.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

UserID stringOptional

When group_by=user_id, this field provides the user ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageModerationsResult struct{…}

The aggregated moderations usage details of the specific time bucket.

InputTokens int64

The aggregated number of input tokens used.

NumModelRequests int64

The count of requests made to the model.

Object OrganizationUsageModerationsResult
APIKeyID stringOptional

When group_by=api_key_id, this field provides the API key ID of the grouped usage result.

Model stringOptional

When group_by=model, this field provides the model name of the grouped usage result.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

UserID stringOptional

When group_by=user_id, this field provides the user ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageImagesResult struct{…}

The aggregated images usage details of the specific time bucket.

Images int64

The number of images processed.

NumModelRequests int64

The count of requests made to the model.

Object OrganizationUsageImagesResult
APIKeyID stringOptional

When group_by=api_key_id, this field provides the API key ID of the grouped usage result.

Model stringOptional

When group_by=model, this field provides the model name of the grouped usage result.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

Size stringOptional

When group_by=size, this field provides the image size of the grouped usage result.

Source stringOptional

When group_by=source, this field provides the source of the grouped usage result, possible values are image.generation, image.edit, image.variation.

UserID stringOptional

When group_by=user_id, this field provides the user ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageAudioSpeechesResult struct{…}

The aggregated audio speeches usage details of the specific time bucket.

Characters int64

The number of characters processed.

NumModelRequests int64

The count of requests made to the model.

Object OrganizationUsageAudioSpeechesResult
APIKeyID stringOptional

When group_by=api_key_id, this field provides the API key ID of the grouped usage result.

Model stringOptional

When group_by=model, this field provides the model name of the grouped usage result.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

UserID stringOptional

When group_by=user_id, this field provides the user ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageAudioTranscriptionsResult struct{…}

The aggregated audio transcriptions usage details of the specific time bucket.

NumModelRequests int64

The count of requests made to the model.

Object OrganizationUsageAudioTranscriptionsResult
Seconds int64

The number of seconds processed.

formatint64
APIKeyID stringOptional

When group_by=api_key_id, this field provides the API key ID of the grouped usage result.

Model stringOptional

When group_by=model, this field provides the model name of the grouped usage result.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

UserID stringOptional

When group_by=user_id, this field provides the user ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageVectorStoresResult struct{…}

The aggregated vector stores usage details of the specific time bucket.

Object OrganizationUsageVectorStoresResult
UsageBytes int64

The vector stores usage in bytes.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationUsageCodeInterpreterSessionsResult struct{…}

The aggregated code interpreter sessions usage details of the specific time bucket.

NumSessions int64

The number of code interpreter sessions.

Object OrganizationUsageCodeInterpreterSessionsResult
ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped usage result.

type AdminOrganizationUsageCostsResponseDataResultOrganizationCostsResult struct{…}

The aggregated costs details of the specific time bucket.

Object OrganizationCostsResult
Amount AdminOrganizationUsageCostsResponseDataResultOrganizationCostsResultAmountOptional

The monetary value in its associated currency.

Currency stringOptional

Lowercase ISO-4217 currency e.g. “usd”

Value float64Optional

The numeric value of the cost.

APIKeyID stringOptional

When group_by=api_key_id, this field provides the API Key ID of the grouped costs result.

LineItem stringOptional

When group_by=line_item, this field provides the line item of the grouped costs result.

ProjectID stringOptional

When group_by=project_id, this field provides the project ID of the grouped costs result.

Quantity float64Optional

When group_by=line_item, this field provides the quantity of the grouped costs result.

StartTime int64
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
                }
            ]
        }
    ],
    "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
}