{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/vertesiahq/json-schema/vertesiahq-audit-trail-response-schema.json",
  "title": "AuditTrailResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/vertesiahq-audit-trail-api-openapi.yml#/components/schemas/AuditTrailResponse",
  "type": "object",
  "properties": {
    "events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AuditTrailEvent"
      }
    },
    "hasNext": {
      "type": "boolean",
      "description": "Whether there are more events after this page"
    },
    "limit": {
      "type": "number"
    },
    "offset": {
      "type": "number"
    }
  },
  "required": [
    "events",
    "hasNext",
    "limit",
    "offset"
  ],
  "additionalProperties": false,
  "$defs": {
    "AuditAction": {
      "anyOf": [
        {
          "$ref": "#/$defs/KnownAuditAction"
        },
        {
          "type": "string"
        }
      ]
    },
    "AuditMeter": {
      "type": "object",
      "properties": {
        "category": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "quantity": {
          "type": "number"
        }
      },
      "required": [
        "category",
        "type",
        "quantity"
      ],
      "additionalProperties": false,
      "description": "Generic metering entry attached to audit events. Used for cost attribution, usage tracking, and billing.\n\nExamples:   { category: \"tokens\", type: \"input\", quantity: 1234 }   { category: \"tokens\", type: \"output\", quantity: 567 }   { category: \"compute\", type: \"duration_ms\", quantity: 2100 }   { category: \"processing\", type: \"pages\", quantity: 12 }"
    },
    "AuditTrailEvent": {
      "type": "object",
      "properties": {
        "event_type": {
          "type": "string",
          "const": "audit"
        },
        "event_id": {
          "type": "string"
        },
        "event_category": {
          "$ref": "#/$defs/EventCategory"
        },
        "source": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "root_event_id": {
          "type": "string"
        },
        "caused_by_event_id": {
          "type": "string"
        },
        "hop_count": {
          "type": "number"
        },
        "audit_trail": {
          "type": "boolean"
        },
        "replay_of": {
          "type": "string"
        },
        "replay_root_event_id": {
          "type": "string"
        },
        "replayed_by": {
          "type": "string"
        },
        "action": {
          "$ref": "#/$defs/AuditAction"
        },
        "resource_type": {
          "type": "string"
        },
        "resource_id": {
          "type": "string"
        },
        "timestamp": {
          "type": "string"
        },
        "request_id": {
          "type": "string"
        },
        "status": {
          "type": "number"
        },
        "success": {
          "type": "boolean"
        },
        "principal_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "principal_type": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "effective_principal_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "roles": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "account_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "project_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "tenant_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "account_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "project_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "provider": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Provider type for billable/provider-backed events, e.g. vertexai, bedrock."
        },
        "meters": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AuditMeter"
          },
          "description": "Generic metering data for cost attribution and usage tracking"
        },
        "details": {
          "type": "object",
          "additionalProperties": true,
          "description": "Event-specific metadata — shape varies by action/resource_type"
        }
      },
      "required": [
        "event_type",
        "action",
        "resource_type",
        "resource_id",
        "timestamp",
        "request_id",
        "status",
        "success",
        "principal_id",
        "principal_type",
        "effective_principal_id",
        "roles",
        "account_id",
        "project_id",
        "tenant_id",
        "account_name",
        "project_name"
      ],
      "additionalProperties": false
    },
    "EventCategory": {
      "type": "string",
      "enum": [
        "content",
        "workflow",
        "security",
        "billing",
        "system",
        "external"
      ]
    },
    "KnownAuditAction": {
      "type": "string",
      "enum": [
        "create",
        "update",
        "delete",
        "bulk_create",
        "bulk_change_type",
        "bulk_update",
        "bulk_delete",
        "attach",
        "detach",
        "credentials_fill",
        "credentials_totp_generation",
        "publish",
        "unpublish",
        "search",
        "read",
        "inference",
        "embedding",
        "image_generation",
        "document_processed"
      ]
    }
  }
}