{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/withruntime-com/json-schema/withruntime-com-usage-schema.json",
  "title": "Usage",
  "description": "What the org has used and has left, at the card's prices.",
  "x-generated": "2026-11-28",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/withruntime-com-openapi.json#/components/schemas/Usage",
  "type": "object",
  "properties": {
    "orgId": {
      "type": "string",
      "description": "The organization."
    },
    "periodStart": {
      "type": "string",
      "format": "date-time",
      "description": "The month's first moment (UTC)."
    },
    "credited": {
      "type": "string",
      "format": "decimal",
      "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
      "description": "Every credit ever added, in US dollars."
    },
    "spent": {
      "type": "string",
      "format": "decimal",
      "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
      "description": "Every charge ever settled, in US dollars."
    },
    "available": {
      "type": "string",
      "format": "decimal",
      "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
      "description": "What can still be spent: credited less spent, in US dollars."
    },
    "periodSpent": {
      "type": "string",
      "format": "decimal",
      "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
      "description": "Charged this month, in US dollars."
    },
    "meters": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/MeterUse"
      },
      "description": "This month's use and charges by meter."
    },
    "plan": {
      "type": "string",
      "description": "Its plan on the price card."
    },
    "limits": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Limit"
      },
      "description": "Every limit it is held to, with what it uses of each now: the figures a create past one is refused by."
    },
    "spendCap": {
      "type": "string",
      "format": "decimal",
      "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
      "description": "The org's own cap on a month's charges, in US dollars."
    },
    "key": {
      "$ref": "#/$defs/KeyUsage"
    },
    "keySpendCap": {
      "$ref": "#/$defs/KeySpendCap"
    },
    "hours": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/UsageHour"
      },
      "description": "With `by=hour`: what each product used each hour, since the month began or 7 days ago, whichever is earlier, oldest first. Only hours that cost something."
    },
    "lines": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ProductLine"
      },
      "description": "With `by=hour`: what each product's month is made of, a line for each meter it used, its quantity at the card's rate. A product's lines sum to its hours since the month began."
    },
    "keys": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/KeySpend"
      },
      "description": "With `by=key`: what each key's machines and storage used this month, most first. A key the caller may not see is counted under `others`."
    }
  },
  "required": [
    "orgId",
    "periodStart",
    "credited",
    "spent",
    "available",
    "periodSpent",
    "meters",
    "plan",
    "limits"
  ],
  "$defs": {
    "KeySpend": {
      "type": "object",
      "description": "What one key, or what was made with no key, used this month.",
      "properties": {
        "keyId": {
          "type": "string",
          "description": "The key the machines and storage were made with. Omitted for what was made with no key (signed in to the console), and for `others`."
        },
        "name": {
          "type": "string",
          "description": "The key's name."
        },
        "accountId": {
          "type": "string",
          "description": "The person the key acts for, or who made it signed in to the console."
        },
        "email": {
          "type": "string",
          "description": "That person's email address."
        },
        "agentId": {
          "type": "string",
          "description": "The agent or CI pipeline the key acts as."
        },
        "source": {
          "type": "string",
          "description": "`key`: one key's. `console`: made signed in, with no key. `others`: keys the caller may not see, together. `unknown`: made by something deleted too long ago to name."
        },
        "charged": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "Charged this month at the card's rates, in US dollars."
        }
      },
      "required": [
        "source",
        "charged"
      ]
    },
    "KeySpendCap": {
      "type": "object",
      "description": "The spend cap a key's creates are held to, and what is left under it.",
      "properties": {
        "cap": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "The most its holder's machines may spend over windowSeconds, in US dollars."
        },
        "spent": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "What they spent over the window, in US dollars, as the cap counts it."
        },
        "remaining": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "What is left: cap less spent, never below 0. Once 0, a create is refused 403 until the window passes it."
        },
        "windowSeconds": {
          "type": "integer",
          "description": "The rolling window the cap counts over, in seconds."
        }
      },
      "required": [
        "cap",
        "spent",
        "remaining",
        "windowSeconds"
      ]
    },
    "KeyUsage": {
      "type": "object",
      "description": "One key's spend and what its holder runs: a coordinator reads what each worker's key spent.",
      "properties": {
        "keyId": {
          "type": "string",
          "description": "The key's ID."
        },
        "name": {
          "type": "string",
          "description": "Its name."
        },
        "agentId": {
          "type": "string",
          "description": "The agent or CI pipeline it acts as."
        },
        "accountId": {
          "type": "string",
          "description": "The person it acts as or for."
        },
        "daySpent": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "What its calls committed in the last 24 hours, in US dollars, as its spend caps count it."
        },
        "periodSpent": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "What its calls committed this month (UTC), in US dollars."
        },
        "running": {
          "type": "integer",
          "description": "Its holder's machines running now."
        },
        "machines": {
          "type": "integer",
          "description": "Its holder's machines, not deleted."
        }
      },
      "required": [
        "keyId",
        "name",
        "daySpent",
        "periodSpent",
        "running",
        "machines"
      ]
    },
    "Limit": {
      "type": "object",
      "description": "One limit the org is held to, and what it uses of it now.",
      "properties": {
        "name": {
          "type": "string",
          "description": "`running.vcpus`, `running.memory`, `machine.vcpus`, `machine.memory` or `starts.per-second`."
        },
        "unit": {
          "type": "string",
          "enum": [
            "count",
            "bytes",
            "per-second"
          ],
          "description": "What `max` and `used` count."
        },
        "max": {
          "type": "integer",
          "description": "The most it may hold; none for no limit."
        },
        "used": {
          "type": "integer",
          "description": "What it holds now."
        }
      },
      "required": [
        "name",
        "unit",
        "used"
      ]
    },
    "MeterUse": {
      "type": "object",
      "description": "One meter's use and charges this month.",
      "properties": {
        "meter": {
          "type": "string",
          "description": "The card's meter (`cpu`, `memory`, `traffic-out`, ...)."
        },
        "quantity": {
          "type": "string",
          "description": "Used this month, in the meter's base unit, as an integer in text."
        },
        "unit": {
          "type": "string",
          "description": "The base unit: `core-microseconds`, `vcpu-microseconds`, `byte-seconds`, `bytes`, `calls` or `seconds`."
        },
        "charged": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "Charged this month at the card's rate, in US dollars."
        }
      },
      "required": [
        "meter",
        "quantity",
        "unit",
        "charged"
      ]
    },
    "ProductLine": {
      "type": "object",
      "description": "One meter's part of one product's month: a quantity at the card's rate.",
      "properties": {
        "product": {
          "type": "string",
          "description": "What it was used by, as `hours` names it (`sandbox`, `disk`, `traffic`, ...)."
        },
        "meter": {
          "type": "string",
          "description": "The card's meter (`cpu`, `memory`, `traffic-out`, ...)."
        },
        "name": {
          "type": "string",
          "description": "The meter's name on the card (`CPU`, `Memory`), from `names::METERS`."
        },
        "quantity": {
          "type": "string",
          "description": "Used this month, in `unit`, as a decimal in text."
        },
        "unit": {
          "type": "string",
          "description": "What `quantity` counts: `active vCPU-hours`, `GiB-hours`, `GiB-months`, `GB`, ..."
        },
        "rate": {
          "type": "string",
          "description": "The card's price for one of `unit`, as the card writes it (`$0.03 per active vCPU-hour`)."
        },
        "charged": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "What it costs on the price card, before any credit, in US dollars."
        }
      },
      "required": [
        "product",
        "meter",
        "name",
        "quantity",
        "unit",
        "rate",
        "charged"
      ]
    },
    "UsageHour": {
      "type": "object",
      "description": "One product's use in one hour, at the card's prices.",
      "properties": {
        "at": {
          "type": "string",
          "format": "date-time",
          "description": "The hour's first moment (UTC)."
        },
        "product": {
          "type": "string",
          "description": "What it was used by: the machine's kind (`sandbox`, `app`, `function`, `ci`, ...), what is kept on disk (`disk`, `volume`, `snapshot`, `image`), or `traffic`, what was sent out; `machine` or `storage` when what used it was deleted too long ago to name."
        },
        "charged": {
          "type": "string",
          "format": "decimal",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
          "description": "What it costs on the price card, before any credit, in US dollars."
        }
      },
      "required": [
        "at",
        "product",
        "charged"
      ]
    }
  }
}