{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cavuno-com/json-schema/cavuno-com-billing-builder-credits-schema.json",
  "title": "BillingBuilderCredits",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/cavuno-com-billing-api-openapi.yml#/components/schemas/BillingBuilderCredits",
  "type": "object",
  "properties": {
    "object": {
      "type": "string",
      "enum": [
        "billing_builder_credits"
      ]
    },
    "autoTopup": {
      "$ref": "#/$defs/BuilderCreditAutoTopup"
    },
    "grants": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/BuilderCreditGrant"
      },
      "description": "The 20 newest credit grants (refreshes and purchases), newest first."
    },
    "usagePeriods": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/BuilderCreditUsagePeriod"
      },
      "description": "Recent credit spend: up to 14 days, 6 months and 6 billing periods, each newest first."
    }
  },
  "required": [
    "object",
    "autoTopup",
    "grants",
    "usagePeriods"
  ],
  "$defs": {
    "BuilderCreditAutoTopup": {
      "type": "object",
      "properties": {
        "available": {
          "type": "boolean",
          "description": "Whether automatic top-ups are offered at all. When false, no automatic top-up runs, whatever `enabled` says."
        },
        "canTopUp": {
          "type": "boolean",
          "description": "Whether the Board's plan allows buying credits. When false, no automatic top-up runs, whatever `enabled` says."
        },
        "enabled": {
          "type": "boolean",
          "description": "Whether the Board opted in to automatic credit top-ups. False when it never did. Top-ups only run when `available` and `canTopUp` are also true."
        },
        "packTenths": {
          "type": "integer",
          "minimum": 0,
          "description": "Credits bought by each automatic top-up. In tenths of a credit, like GET /usage (10 is one credit)."
        },
        "monthlyCapUsdCents": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "description": "Most that automatic top-ups may spend in one UTC month, in US cents. Null means no cap."
        },
        "disabledReason": {
          "type": [
            "string",
            "null"
          ],
          "description": "Why automatic top-ups are paused, as `{code}|{month}` (for example a declined card), or null. A pause only lasts for the month it names."
        },
        "consentedAt": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 time a person on the Board opted in to automatic top-ups, or null when they never did."
        }
      },
      "required": [
        "available",
        "canTopUp",
        "enabled",
        "packTenths",
        "monthlyCapUsdCents",
        "disabledReason",
        "consentedAt"
      ]
    },
    "BuilderCreditGrant": {
      "type": "object",
      "properties": {
        "source": {
          "type": "string",
          "enum": [
            "refresh",
            "topup",
            "auto-topup"
          ],
          "description": "`refresh`: a one-time refresh of the plan allowance. `topup`: credits a person bought. `auto-topup`: credits bought automatically."
        },
        "tenths": {
          "type": "integer",
          "minimum": 0,
          "description": "Credits granted. In tenths of a credit, like GET /usage (10 is one credit)."
        },
        "remainingTenths": {
          "type": "integer",
          "minimum": 0,
          "description": "Credits of this grant not yet spent. In tenths of a credit, like GET /usage (10 is one credit)."
        },
        "refundedTenths": {
          "type": "integer",
          "minimum": 0,
          "description": "Credits taken back after a refund or a lost dispute. In tenths of a credit, like GET /usage (10 is one credit)."
        },
        "priceUsdCents": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "description": "Price paid for a purchase, in US cents. Null for a refresh, which is free."
        },
        "createdAt": {
          "type": "string",
          "description": "ISO-8601 time the grant was created."
        },
        "expiresAt": {
          "type": [
            "string",
            "null"
          ],
          "description": "ISO-8601 time the unspent credits expire, or null when they never expire (purchases)."
        }
      },
      "required": [
        "source",
        "tenths",
        "remainingTenths",
        "refundedTenths",
        "priceUsdCents",
        "createdAt",
        "expiresAt"
      ]
    },
    "BuilderCreditUsagePeriod": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "day",
            "month",
            "billing"
          ],
          "description": "Window the counter covers: a UTC day, a UTC month, or the billing period of the plan."
        },
        "periodKey": {
          "type": "string",
          "description": "Stable key of the window, in the same form as the `periodKey` fields of GET /usage."
        },
        "usedTenths": {
          "type": "integer",
          "minimum": 0,
          "description": "Credits spent in the window. In tenths of a credit, like GET /usage (10 is one credit)."
        },
        "runCount": {
          "type": "integer",
          "minimum": 0,
          "description": "Metered Builder chat runs counted in the window."
        }
      },
      "required": [
        "kind",
        "periodKey",
        "usedTenths",
        "runCount"
      ]
    }
  }
}