{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/shardflux-dev/json-schema/shardflux-dev-spend-cap-schema.json",
  "title": "SpendCap",
  "description": "Opt-in overage with a spend cap. Off by default. While it is on, workspaces open and run past the plan’s CPU-hours and RAM GiB-hours allowances, and the usage past them is charged at the rates below, up to the effective cap per billing period. At the cap, and while a plan invoice is past due, a used-up allowance refuses new starts (402 allowance_exhausted) and running workspaces are paused. Nothing is deleted.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/shardflux-dev-openapi.json#/components/schemas/SpendCap",
  "type": "object",
  "required": [
    "state",
    "available",
    "enabled",
    "paused",
    "cap_minor",
    "effective_cap_minor",
    "max_cap_minor",
    "charges_minor",
    "remaining_minor",
    "percent_of_cap",
    "currency",
    "resets_at",
    "lines",
    "projected_reached_at"
  ],
  "properties": {
    "state": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "unavailable"
          ]
        },
        {
          "type": "string",
          "enum": [
            "off"
          ]
        },
        {
          "type": "string",
          "enum": [
            "paused"
          ]
        },
        {
          "type": "string",
          "enum": [
            "within_allowance"
          ]
        },
        {
          "type": "string",
          "enum": [
            "accruing"
          ]
        },
        {
          "type": "string",
          "enum": [
            "warning"
          ]
        },
        {
          "type": "string",
          "enum": [
            "reached"
          ]
        }
      ],
      "description": "unavailable: the plan has no opt-in overage or the organization has no paid subscription. off: available, not turned on. paused: on, but a plan invoice is past due, so overage behaves as off until it is paid. within_allowance: on, no usage past the allowances yet. accruing: on, usage past an allowance is being charged. warning: charges are 80 % of the effective cap or more. reached: less than one cent of the cap is left, so starts are refused (402 allowance_exhausted, reason spend_cap_reached) and running workspaces are paused."
    },
    "available": {
      "type": "boolean",
      "description": "The plan offers opt-in overage (catalog overage `opt_in`) and the organization pays for the plan with a subscription."
    },
    "enabled": {
      "type": "boolean",
      "description": "An owner or billing member turned overage on (spend-policy overage_enabled)."
    },
    "paused": {
      "type": "boolean",
      "description": "A plan invoice is past due (payment grace or restriction): overage behaves as off until it is paid."
    },
    "cap_minor": {
      "anyOf": [
        {
          "type": "integer",
          "description": "The configured spend cap per billing period, minor units of `currency`. Null: never set."
        },
        {
          "type": "null"
        }
      ]
    },
    "effective_cap_minor": {
      "type": "integer",
      "description": "The cap that applies: min(cap_minor, max_cap_minor), or max_cap_minor when no cap is set. 0 when overage is unavailable."
    },
    "max_cap_minor": {
      "anyOf": [
        {
          "type": "integer",
          "description": "The current plan price: the largest cap that can be set, so a downgrade lowers the effective cap. Null without a subscription price."
        },
        {
          "type": "null"
        }
      ]
    },
    "charges_minor": {
      "type": "integer",
      "description": "Overage charged this period so far, whole minor units (floor). It is billed on the next invoice and never exceeds the effective cap. Accrued charges stay when overage is turned off or paused."
    },
    "remaining_minor": {
      "type": "integer",
      "description": "What is left under the effective cap, whole minor units (floor)."
    },
    "percent_of_cap": {
      "anyOf": [
        {
          "type": "number",
          "description": "Charges as a percentage of the effective cap (2 decimals). Null when overage is unavailable."
        },
        {
          "type": "null"
        }
      ]
    },
    "currency": {
      "type": "string",
      "description": "ISO 4217 code, lower case (the plan price currency)."
    },
    "resets_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the billing period ends: charges and the cap start again from zero."
    },
    "lines": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "allowance",
          "unit",
          "units_over",
          "billed_units",
          "rate_minor",
          "amount_minor"
        ],
        "properties": {
          "allowance": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "ram_gib_hours"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "cpu_hours"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "gpu_hours"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "retained_state_gib"
                ]
              }
            ],
            "description": "The allowances overage covers (gpu_hours on plans with a GPU-hour rate; retained_state_gib, retained storage above the included GiB, on plans with a storage rate). Transfer never accrues overage."
          },
          "unit": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "gib_hours"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "hours"
                ]
              },
              {
                "type": "string",
                "enum": [
                  "gib_months"
                ]
              }
            ],
            "description": "gib_hours for ram_gib_hours, hours for cpu_hours (CPU-hours) and gpu_hours (GPU-hours), gib_months for retained_state_gib (a GiB-month is 730 GiB-hours)."
          },
          "units_over": {
            "type": "number",
            "description": "Usage past the allowance this period, in unit-hours (charged or not: usage before overage was turned on, while paused or past the cap is never charged)."
          },
          "billed_units": {
            "type": "number",
            "description": "The part of it charged this period, in unit-hours."
          },
          "rate_minor": {
            "type": "number",
            "description": "Minor units per unit-hour past the allowance (4 = $0.04 per RAM GiB-hour; 12 = $0.12 per CPU-hour)."
          },
          "amount_minor": {
            "type": "integer",
            "description": "billed_units × rate_minor, whole minor units (floor). Lines are floored one by one, so they may add up to one minor unit less than charges_minor."
          }
        },
        "additionalProperties": false
      },
      "description": "One line per dimension, RAM first (the invoice lines of the period). Empty when the plan has no overage rates."
    },
    "projected_reached_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "description": "When the charges reach the effective cap at the average burn of this period so far. Null when not accruing or when it would fall after resets_at."
    }
  },
  "additionalProperties": false
}