{
  "$defs": {
    "RuntimeActorIdentity": {
      "additionalProperties": false,
      "description": "Identity of a runtime actor (human, LLM, or service).",
      "properties": {
        "actor_id": {
          "description": "Unique actor identifier",
          "minLength": 1,
          "title": "Actor Id",
          "type": "string"
        },
        "actor_type": {
          "description": "Actor category",
          "pattern": "^(human|llm|service)$",
          "title": "Actor Type",
          "type": "string"
        },
        "display_name": {
          "default": "",
          "description": "Human-readable display name",
          "title": "Display Name",
          "type": "string"
        },
        "model": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Model identifier (e.g., 'claude-opus-4-6')",
          "title": "Model"
        },
        "provider": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Provider (e.g., 'anthropic', 'openai')",
          "title": "Provider"
        },
        "tool": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Tool identifier",
          "title": "Tool"
        }
      },
      "required": [
        "actor_id",
        "actor_type"
      ],
      "title": "RuntimeActorIdentity",
      "type": "object"
    }
  },
  "$id": "spec-kitty-events/token_usage_recorded_payload",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Canonical token and estimated-cost accounting payload.",
  "properties": {
    "actor": {
      "anyOf": [
        {
          "$ref": "#/$defs/RuntimeActorIdentity"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Runtime actor identity when available"
    },
    "estimated_cost_usd": {
      "description": "Estimated USD cost for the usage record",
      "minimum": 0,
      "title": "Estimated Cost Usd",
      "type": "number"
    },
    "input_tokens": {
      "description": "Prompt/input token count",
      "minimum": 0,
      "title": "Input Tokens",
      "type": "integer"
    },
    "mission_id": {
      "description": "Canonical mission identifier",
      "minLength": 1,
      "title": "Mission Id",
      "type": "string"
    },
    "model": {
      "anyOf": [
        {
          "minLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "LLM model when available",
      "title": "Model"
    },
    "output_tokens": {
      "description": "Completion/output token count",
      "minimum": 0,
      "title": "Output Tokens",
      "type": "integer"
    },
    "phase_name": {
      "anyOf": [
        {
          "minLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Mission phase name when known",
      "title": "Phase Name"
    },
    "provider": {
      "anyOf": [
        {
          "minLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "LLM provider when available",
      "title": "Provider"
    },
    "run_id": {
      "anyOf": [
        {
          "minLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Mission run identifier when available",
      "title": "Run Id"
    },
    "source": {
      "description": "Usage data source identifier",
      "minLength": 1,
      "title": "Source",
      "type": "string"
    },
    "step_id": {
      "anyOf": [
        {
          "minLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Mission step identifier when available",
      "title": "Step Id"
    },
    "total_tokens": {
      "description": "Total token count",
      "minimum": 0,
      "title": "Total Tokens",
      "type": "integer"
    },
    "wp_id": {
      "anyOf": [
        {
          "minLength": 1,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Work-package identifier when available",
      "title": "Wp Id"
    }
  },
  "required": [
    "mission_id",
    "input_tokens",
    "output_tokens",
    "total_tokens",
    "estimated_cost_usd",
    "source"
  ],
  "title": "TokenUsageRecordedPayload",
  "type": "object"
}
