## Completions

`admin.organization.usage.completions(**kwargs) -> UsageCompletionsResponse`

**get** `/organization/usage/completions`

Get completions usage details for the organization.

### Parameters

- `start_time: Integer`

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

- `api_key_ids: Array[String]`

  Return only usage for these API keys.

- `batch: bool`

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

- `bucket_width: :"1m" | :"1h" | :"1d"`

  Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default to `1d`.

  - `:"1m"`

  - `:"1h"`

  - `:"1d"`

- `end_time: Integer`

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

- `group_by: Array[:project_id | :user_id | :api_key_id | 3 more]`

  Group the usage data by the specified fields. Support fields include `project_id`, `user_id`, `api_key_id`, `model`, `batch`, `service_tier` or any combination of them.

  - `:project_id`

  - `:user_id`

  - `:api_key_id`

  - `:model`

  - `:batch`

  - `:service_tier`

- `limit: Integer`

  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: Array[String]`

  Return only usage for these models.

- `page: String`

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

- `project_ids: Array[String]`

  Return only usage for these projects.

- `user_ids: Array[String]`

  Return only usage for these users.

### Returns

- `class UsageCompletionsResponse`

  - `data: Array[Data{ end_time, object, results, start_time}]`

    - `end_time: Integer`

    - `object: :bucket`

      - `:bucket`

    - `results: Array[OrganizationUsageCompletionsResult{ input_tokens, num_model_requests, object, 10 more} | OrganizationUsageEmbeddingsResult{ input_tokens, num_model_requests, object, 4 more} | OrganizationUsageModerationsResult{ input_tokens, num_model_requests, object, 4 more} | 8 more]`

      - `class OrganizationUsageCompletionsResult`

        The aggregated completions usage details of the specific time bucket.

        - `input_tokens: Integer`

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

        - `num_model_requests: Integer`

          The count of requests made to the model.

        - `object: :"organization.usage.completions.result"`

          - `:"organization.usage.completions.result"`

        - `output_tokens: Integer`

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

        - `api_key_id: String`

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

        - `batch: bool`

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

        - `input_audio_tokens: Integer`

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

        - `input_cached_tokens: Integer`

          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: String`

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

        - `output_audio_tokens: Integer`

          The aggregated number of audio output tokens used.

        - `project_id: String`

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

        - `service_tier: String`

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

        - `user_id: String`

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

      - `class OrganizationUsageEmbeddingsResult`

        The aggregated embeddings usage details of the specific time bucket.

        - `input_tokens: Integer`

          The aggregated number of input tokens used.

        - `num_model_requests: Integer`

          The count of requests made to the model.

        - `object: :"organization.usage.embeddings.result"`

          - `:"organization.usage.embeddings.result"`

        - `api_key_id: String`

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

        - `model: String`

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

        - `project_id: String`

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

        - `user_id: String`

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

      - `class OrganizationUsageModerationsResult`

        The aggregated moderations usage details of the specific time bucket.

        - `input_tokens: Integer`

          The aggregated number of input tokens used.

        - `num_model_requests: Integer`

          The count of requests made to the model.

        - `object: :"organization.usage.moderations.result"`

          - `:"organization.usage.moderations.result"`

        - `api_key_id: String`

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

        - `model: String`

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

        - `project_id: String`

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

        - `user_id: String`

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

      - `class OrganizationUsageImagesResult`

        The aggregated images usage details of the specific time bucket.

        - `images: Integer`

          The number of images processed.

        - `num_model_requests: Integer`

          The count of requests made to the model.

        - `object: :"organization.usage.images.result"`

          - `:"organization.usage.images.result"`

        - `api_key_id: String`

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

        - `model: String`

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

        - `project_id: String`

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

        - `size: String`

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

        - `source: String`

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

        - `user_id: String`

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

      - `class OrganizationUsageAudioSpeechesResult`

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

        - `characters: Integer`

          The number of characters processed.

        - `num_model_requests: Integer`

          The count of requests made to the model.

        - `object: :"organization.usage.audio_speeches.result"`

          - `:"organization.usage.audio_speeches.result"`

        - `api_key_id: String`

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

        - `model: String`

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

        - `project_id: String`

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

        - `user_id: String`

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

      - `class OrganizationUsageAudioTranscriptionsResult`

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

        - `num_model_requests: Integer`

          The count of requests made to the model.

        - `object: :"organization.usage.audio_transcriptions.result"`

          - `:"organization.usage.audio_transcriptions.result"`

        - `seconds: Integer`

          The number of seconds processed.

        - `api_key_id: String`

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

        - `model: String`

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

        - `project_id: String`

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

        - `user_id: String`

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

      - `class OrganizationUsageVectorStoresResult`

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

        - `object: :"organization.usage.vector_stores.result"`

          - `:"organization.usage.vector_stores.result"`

        - `usage_bytes: Integer`

          The vector stores usage in bytes.

        - `project_id: String`

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

      - `class OrganizationUsageCodeInterpreterSessionsResult`

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

        - `num_sessions: Integer`

          The number of code interpreter sessions.

        - `object: :"organization.usage.code_interpreter_sessions.result"`

          - `:"organization.usage.code_interpreter_sessions.result"`

        - `project_id: String`

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

      - `class OrganizationUsageFileSearchesResult`

        The aggregated file search calls usage details of the specific time bucket.

        - `num_requests: Integer`

          The count of file search calls.

        - `object: :"organization.usage.file_searches.result"`

          - `:"organization.usage.file_searches.result"`

        - `api_key_id: String`

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

        - `project_id: String`

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

        - `user_id: String`

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

        - `vector_store_id: String`

          When `group_by=vector_store_id`, this field provides the vector store ID of the grouped usage result.

      - `class OrganizationUsageWebSearchesResult`

        The aggregated web search calls usage details of the specific time bucket.

        - `num_model_requests: Integer`

          The count of model requests.

        - `num_requests: Integer`

          The count of web search calls.

        - `object: :"organization.usage.web_searches.result"`

          - `:"organization.usage.web_searches.result"`

        - `api_key_id: String`

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

        - `context_level: String`

          When `group_by=context_level`, this field provides the search context size of the grouped usage result.

        - `model: String`

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

        - `project_id: String`

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

        - `user_id: String`

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

      - `class OrganizationCostsResult`

        The aggregated costs details of the specific time bucket.

        - `object: :"organization.costs.result"`

          - `:"organization.costs.result"`

        - `amount: Amount{ currency, value}`

          The monetary value in its associated currency.

          - `currency: String`

            Lowercase ISO-4217 currency e.g. "usd"

          - `value: Float`

            The numeric value of the cost.

        - `api_key_id: String`

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

        - `line_item: String`

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

        - `project_id: String`

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

        - `quantity: Float`

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

    - `start_time: Integer`

  - `has_more: bool`

  - `next_page: String`

  - `object: :page`

    - `:page`

### Example

```ruby
require "openai"

openai = OpenAI::Client.new(admin_api_key: "My Admin API Key")

response = openai.admin.organization.usage.completions(start_time: 0)

puts(response)
```

#### Response

```json
{
  "data": [
    {
      "end_time": 0,
      "object": "bucket",
      "results": [
        {
          "input_tokens": 0,
          "num_model_requests": 0,
          "object": "organization.usage.completions.result",
          "output_tokens": 0,
          "api_key_id": "api_key_id",
          "batch": true,
          "input_audio_tokens": 0,
          "input_cached_tokens": 0,
          "model": "model",
          "output_audio_tokens": 0,
          "project_id": "project_id",
          "service_tier": "service_tier",
          "user_id": "user_id"
        }
      ],
      "start_time": 0
    }
  ],
  "has_more": true,
  "next_page": "next_page",
  "object": "page"
}
```
