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
Theme

Completions

client.Admin.Organization.Usage.Completions(ctx, query) (*AdminOrganizationUsageCompletionsResponse, error)
GET
/organization/usage/completions

Get completions usage details for the organization.

Completions

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.Completions(context.TODO(), openai.AdminOrganizationUsageCompletionsParams{
    StartTime: 0,
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.Data)
}
Response example
{
    "object": "page",
    "data": [
        {
            "object": "bucket",
            "start_time": 1730419200,
            "end_time": 1730505600,
            "results": [
                {
                    "object": "organization.usage.completions.result",
                    "input_tokens": 1000,
                    "input_cached_tokens": 400,
                    "input_cache_write_tokens": 100,
                    "input_cache_write_30m_tokens": 75,
                    "input_cache_write_12h_tokens": 25,
                    "input_uncached_tokens": 500,
                    "output_tokens": 500,
                    "input_text_tokens": 400,
                    "output_text_tokens": 400,
                    "input_cached_text_tokens": 300,
                    "input_audio_tokens": 50,
                    "input_cached_audio_tokens": 50,
                    "output_audio_tokens": 50,
                    "input_image_tokens": 50,
                    "input_cached_image_tokens": 50,
                    "output_image_tokens": 50,
                    "num_model_requests": 5,
                    "project_id": null,
                    "user_id": null,
                    "api_key_id": null,
                    "model": null,
                    "batch": null,
                    "service_tier": null
                }
            ]
        }
    ],
    "has_more": true,
    "next_page": "page_AAAAAGdGxdEiJdKOAAAAAGcqsYA="
}
Parameters
query AdminOrganizationUsageCompletionsParams
StartTime param.Field[int64]

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

APIKeyIDs param.Field[[]string]
Optional

Return only usage for these API keys.

Batch param.Field[bool]
Optional

If true, return batch jobs only. If false, return non-batch jobs only. By default, return both.

Width of each time bucket in response. Currently 1m, 1h and 1d are 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 usage data by the specified fields. Support fields include project_id, user_id, api_key_id, model, batch, service_tier, api_source or any combination of them. 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.

Limit param.Field[int64]
Optional

Specifies the number of buckets to return.

  • bucket_width=1d: default: 7, max: 31
  • bucket_width=1h: default: 24, max: 168
  • bucket_width=1m: default: 60, max: 1440
Models param.Field[[]string]
Optional

Return only usage for these models.

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 usage for these projects.

UserIDs param.Field[[]string]
Optional

Return only usage for these users.

Returns
type AdminOrganizationUsageCompletionsResponse struct{…}
Data []AdminOrganizationUsageCompletionsResponseData
HasMore bool
NextPage string
Object Page
Returns Examples
Response example
{
    "object": "page",
    "data": [
        {
            "object": "bucket",
            "start_time": 1730419200,
            "end_time": 1730505600,
            "results": [
                {
                    "object": "organization.usage.completions.result",
                    "input_tokens": 1000,
                    "input_cached_tokens": 400,
                    "input_cache_write_tokens": 100,
                    "input_cache_write_30m_tokens": 75,
                    "input_cache_write_12h_tokens": 25,
                    "input_uncached_tokens": 500,
                    "output_tokens": 500,
                    "input_text_tokens": 400,
                    "output_text_tokens": 400,
                    "input_cached_text_tokens": 300,
                    "input_audio_tokens": 50,
                    "input_cached_audio_tokens": 50,
                    "output_audio_tokens": 50,
                    "input_image_tokens": 50,
                    "input_cached_image_tokens": 50,
                    "output_image_tokens": 50,
                    "num_model_requests": 5,
                    "project_id": null,
                    "user_id": null,
                    "api_key_id": null,
                    "model": null,
                    "batch": null,
                    "service_tier": null
                }
            ]
        }
    ],
    "has_more": true,
    "next_page": "page_AAAAAGdGxdEiJdKOAAAAAGcqsYA="
}