{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/spicrawl-com/json-schema/spicrawl-com-usage-breakdown-schema.json",
  "title": "UsageBreakdown",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/spicrawl-com-usage-api-openapi.yml#/components/schemas/UsageBreakdown",
  "type": "object",
  "required": [
    "period",
    "group_by",
    "groups",
    "totals",
    "unattributed",
    "usage_as_of",
    "stale_seconds"
  ],
  "properties": {
    "period": {
      "$ref": "#/$defs/UsagePeriod"
    },
    "group_by": {
      "type": "string",
      "enum": [
        "day",
        "project",
        "engine",
        "feature",
        "key"
      ],
      "description": "The dimension used."
    },
    "groups": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/UsageGroup"
      },
      "description": "Buckets. Can be empty while `totals` is non-zero (e.g. `group_by=engine` without attribution data)."
    },
    "totals": {
      "allOf": [
        {
          "$ref": "#/$defs/UsageMetricMap"
        }
      ],
      "description": "Billed quantities for the window. Authoritative; use these, not the sum of groups."
    },
    "unattributed": {
      "allOf": [
        {
          "$ref": "#/$defs/UsageMetricMap"
        }
      ],
      "description": "Part of each total the groups do not explain. Always has an entry for every metric in `totals` (0 for `day` and `project`)."
    },
    "usage_as_of": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Freshness of the newest rollup row in the window. Null when the window has no rows."
    },
    "stale_seconds": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "description": "Age of `usage_as_of` in seconds. Null when there are no rows (not \"fresh\"). Large values mean the rollup is behind."
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Caveats a chart would otherwise hide, such as missing engine attribution or a breakdown that does not reconcile. Omitted when empty."
    }
  },
  "$defs": {
    "UsageGroup": {
      "type": "object",
      "required": [
        "key",
        "metrics"
      ],
      "properties": {
        "key": {
          "type": "string",
          "description": "Bucket key: a `YYYY-MM-DD` day, a project id, a rendering tier (`fetch`, `js` or `browser`), or a feature (`extract`, `ai_extract`, `proxy_datacenter`, `proxy_residential`, `batch`). Groups are sorted by key."
        },
        "label": {
          "type": "string",
          "description": "Human label for rendering-tier groups (for example \"JavaScript rendering\"). Absent for other dimensions and unknown tiers."
        },
        "metrics": {
          "$ref": "#/$defs/UsageMetricMap"
        }
      }
    },
    "UsageMetricMap": {
      "type": "object",
      "description": "Metric name to quantity. Keys are UsageMetric values.",
      "additionalProperties": {
        "type": "integer",
        "format": "int64"
      }
    },
    "UsagePeriod": {
      "type": "object",
      "required": [
        "start",
        "end",
        "days",
        "bounds"
      ],
      "description": "Half-open range of UTC days.",
      "properties": {
        "start": {
          "type": "string",
          "format": "date",
          "description": "First day, inclusive."
        },
        "end": {
          "type": "string",
          "format": "date",
          "description": "End day, EXCLUSIVE. The last included day is the day before this."
        },
        "days": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of days in the period."
        },
        "bounds": {
          "type": "string",
          "const": "[start, end)",
          "description": "Always `[start, end)`, a reminder that `end` is exclusive."
        }
      }
    }
  }
}