Skip to content

Usage ignores most fields returned by /v2/usage #86

Description

@eliot488995568

The /v2/usage response now contains more usage types than Usage exposes.
Only character_*, document_* and team_document_* are parsed; everything else is silently dropped.

Note: this payload is only returned on Pro accounts — a Free key returns the short form, which is why the extra fields went unnoticed.

Actual response (Pro):

{
  "character_count": 5947223,
  "character_limit": 1000000000000,
  "products": [
    {
      "product_type": "write",
      "billing_unit": "characters",
      "api_key_unit_count": 0,
      "account_unit_count": 5643,
      "api_key_character_count": 0,
      "character_count": 5643
    },
    {
      "product_type": "translate",
      "billing_unit": "characters",
      "api_key_unit_count": 636,
      "account_unit_count": 5941580,
      "api_key_character_count": 636,
      "character_count": 5941580
    },
    {
      "product_type": "speechToText",
      "billing_unit": "minutes",
      "api_key_unit_count": 30,
      "account_unit_count": 30,
      "api_key_character_count": 0,
      "character_count": 0
    },
    {
      "product_type": "speechToSpeech",
      "billing_unit": "minutes",
      "api_key_unit_count": 12,
      "account_unit_count": 12,
      "api_key_character_count": 0,
      "character_count": 0
    }
  ],
  "api_key_character_count": 636,
  "api_key_character_limit": 1000000000000,
  "speech_to_text_milliseconds_count": 0,
  "speech_to_text_milliseconds_limit": 0,
  "speech_to_text_minutes_count": 30,
  "speech_to_text_minutes_limit": 600,
  "speech_to_speech_minutes_count": 12,
  "speech_to_speech_minutes_limit": 600,
  "start_time": "2025-05-13T09:18:42Z",
  "end_time": "2025-06-13T09:18:42Z"
}

Missing:

  • api_key_character_* (per-key quota)
  • speech_to_text_milliseconds_*, speech_to_text_minutes_*
  • speech_to_speech_minutes_*
  • products[] (per-product breakdown, incl. billing_unit)
  • start_time / end_time (billing period)

Consequences: no way to check the API-key quota or the speech quotas, and anyLimitReached() returns false while one of them is exhausted.

Proposal: add the matching UsageDetail fields (buildUsageDetail() already handles any <prefix>_count / <prefix>_limit pair),
include them in anyLimitReached() and __toString(), and expose products, startTime, endTime.
All new fields nullable → no BC break, Free accounts keep null.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions