{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/roar-ai-com/json-schema/roar-ai-com-tool-usage-report-schema.json",
  "title": "ToolUsageReport",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/roar-ai-com-openapi.json#/components/schemas/ToolUsageReport",
  "type": "object",
  "required": [
    "summary",
    "byTool",
    "byError",
    "byKey",
    "series"
  ],
  "properties": {
    "summary": {
      "$ref": "#/$defs/ToolUsageSummary"
    },
    "series": {
      "type": "array",
      "description": "Calls per hour (per day past two days), oldest first; an hour with no calls is absent",
      "items": {
        "type": "object",
        "required": [
          "bucket",
          "calls",
          "errors",
          "stopped"
        ],
        "properties": {
          "bucket": {
            "type": "string",
            "format": "date-time"
          },
          "calls": {
            "type": "integer"
          },
          "errors": {
            "type": "integer"
          },
          "stopped": {
            "type": "integer"
          }
        }
      }
    },
    "byTool": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "endpoint",
          "tool",
          "calls",
          "errors",
          "stopped",
          "withheld",
          "redacted",
          "blocked",
          "avgLatencyMs",
          "p95LatencyMs",
          "lastCalledAt"
        ],
        "properties": {
          "endpoint": {
            "type": "string",
            "description": "`mcp:<server>/<tool>`, or `mcp:gateway` for a name that matched no tool"
          },
          "tool": {
            "type": [
              "string",
              "null"
            ],
            "description": "`<server>/<tool>`; null for the `mcp:gateway` bucket"
          },
          "calls": {
            "type": "integer"
          },
          "errors": {
            "type": "integer"
          },
          "stopped": {
            "type": "integer"
          },
          "withheld": {
            "type": "integer"
          },
          "redacted": {
            "type": "integer"
          },
          "blocked": {
            "type": "integer"
          },
          "avgLatencyMs": {
            "type": [
              "integer",
              "null"
            ]
          },
          "p95LatencyMs": {
            "type": [
              "integer",
              "null"
            ]
          },
          "lastCalledAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    },
    "byError": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "code",
          "calls"
        ],
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "unknown_tool",
              "rate_limited",
              "concurrency",
              "guardrail_blocked",
              "guardrail_args_blocked",
              "upstream_error",
              "tool_error",
              "internal_error",
              "approval_pending",
              "approval_denied",
              "grant_limit"
            ]
          },
          "calls": {
            "type": "integer",
            "description": "Rows, not refusals: repeated refusals are logged once per minute per key"
          }
        }
      }
    },
    "byKey": {
      "type": "array",
      "description": "Which key, filed under which project, called which tool",
      "items": {
        "type": "object",
        "required": [
          "apiKeyId",
          "keyName",
          "projectId",
          "projectName",
          "endpoint",
          "tool",
          "calls",
          "errors",
          "stopped"
        ],
        "properties": {
          "apiKeyId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Null once the key is deleted"
          },
          "keyName": {
            "type": [
              "string",
              "null"
            ]
          },
          "projectId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "projectName": {
            "type": [
              "string",
              "null"
            ]
          },
          "endpoint": {
            "type": "string"
          },
          "tool": {
            "type": [
              "string",
              "null"
            ]
          },
          "calls": {
            "type": "integer"
          },
          "errors": {
            "type": "integer"
          },
          "stopped": {
            "type": "integer"
          }
        }
      }
    }
  },
  "$defs": {
    "ToolUsageSummary": {
      "type": "object",
      "required": [
        "calls",
        "errors",
        "stopped",
        "withheld",
        "redacted",
        "blocked",
        "avgLatencyMs",
        "p95LatencyMs"
      ],
      "properties": {
        "calls": {
          "type": "integer"
        },
        "errors": {
          "type": "integer",
          "description": "Calls that FAILED — the tool, its server or we broke (including `tool_error`, an HTTP 200), or no such tool. Since 2026-09-27 this no longer includes calls a rule stopped (`stopped`) or whose answer the guardrail withheld (`withheld`); a monitor on `errors` that expected those should add them"
        },
        "stopped": {
          "type": "integer",
          "description": "Calls a rule stopped before they reached the tool — waiting for or declined an approval, over a limit, too many at once, or the guardrail refusing the arguments. Not failures"
        },
        "withheld": {
          "type": "integer",
          "description": "Calls whose tool ran and whose answer the guardrail withheld — a change may have happened. Not failures"
        },
        "redacted": {
          "type": "integer",
          "description": "Calls whose arguments or result the guardrail masked"
        },
        "blocked": {
          "type": "integer",
          "description": "Calls the guardrail blocked: arguments refused (in `stopped`) or answer withheld (`withheld`)"
        },
        "avgLatencyMs": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Over calls that reached a tool; null when none did"
        },
        "p95LatencyMs": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Over calls that reached a tool; null when none did"
        }
      }
    }
  }
}