{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "schema": { "type": "string", "const": "agenticdriver.usage.v2" },
    "eventId": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "runId": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "hostId": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
    },
    "accountId": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
    },
    "subject": { "type": "string", "minLength": 1, "maxLength": 128 },
    "provider": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$"
    },
    "vendor": { "type": "string", "minLength": 1, "maxLength": 80 },
    "model": { "type": "string", "minLength": 1, "maxLength": 200 },
    "authMode": {
      "type": "string",
      "enum": ["api-key", "cli-session", "none"]
    },
    "status": {
      "type": "string",
      "enum": ["completed", "failed", "cancelled"]
    },
    "source": {
      "type": "string",
      "enum": ["provider-response", "cli-report", "adapter-report", "synthetic"]
    },
    "startedAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "finishedAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "expiresAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "usage": {
      "type": "object",
      "properties": {
        "inputTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "outputTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "cachedInputTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "reasoningTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "costUsd": { "type": "number", "minimum": 0 },
        "apiEquivalentCostUsd": { "type": "number", "minimum": 0 }
      },
      "additionalProperties": false
    },
    "observedUsage": {
      "type": "object",
      "properties": {
        "inputTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "outputTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "cachedInputTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "reasoningTokens": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "costUsd": { "type": "number", "minimum": 0 },
        "apiEquivalentCostUsd": { "type": "number", "minimum": 0 }
      },
      "additionalProperties": false
    },
    "coverage": {
      "type": "object",
      "properties": {
        "startedSteps": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "completedSteps": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "reportedSteps": {
          "type": "object",
          "properties": {
            "inputTokens": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "outputTokens": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "cachedInputTokens": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "reasoningTokens": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "costUsd": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "apiEquivalentCostUsd": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "additionalProperties": false
        }
      },
      "required": ["startedSteps", "completedSteps", "reportedSteps"],
      "additionalProperties": false
    },
    "durationMs": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "metadata": {
      "type": "object",
      "propertyNames": { "type": "string", "maxLength": 64 },
      "additionalProperties": { "type": "string", "maxLength": 128 }
    }
  },
  "required": [
    "schema",
    "eventId",
    "runId",
    "hostId",
    "subject",
    "provider",
    "vendor",
    "model",
    "authMode",
    "status",
    "source",
    "startedAt",
    "finishedAt",
    "usage",
    "observedUsage",
    "coverage",
    "durationMs",
    "metadata"
  ],
  "additionalProperties": false
}
