{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/usagemax-com/json-schema/usagemax-com-gateway-operations-schema.json",
  "title": "GatewayOperations",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/usagemax-com-openapi.json#/components/schemas/GatewayOperations",
  "type": "object",
  "required": [
    "from",
    "through",
    "retainedFromAt",
    "generatedAt",
    "latestReceiptAt",
    "latestRequestId",
    "truncated",
    "groupsTruncated",
    "limit",
    "overall",
    "recent",
    "daily",
    "providers",
    "models",
    "alerts"
  ],
  "properties": {
    "from": {
      "type": "string",
      "format": "date"
    },
    "through": {
      "type": "string",
      "format": "date"
    },
    "retainedFromAt": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix epoch in milliseconds."
    },
    "generatedAt": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix epoch in milliseconds."
    },
    "latestReceiptAt": {
      "type": [
        "integer",
        "null"
      ]
    },
    "latestRequestId": {
      "type": [
        "string",
        "null"
      ]
    },
    "truncated": {
      "type": "boolean"
    },
    "groupsTruncated": {
      "type": "boolean"
    },
    "limit": {
      "type": "integer",
      "minimum": 0
    },
    "overall": {
      "$ref": "#/$defs/GatewayMetrics"
    },
    "daily": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/GatewayMetrics"
      }
    },
    "providers": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/GatewayMetrics"
      }
    },
    "models": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/GatewayMetrics"
      }
    },
    "recent": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "requestId",
          "provider",
          "model",
          "settledAt",
          "status",
          "hasTrace"
        ],
        "properties": {
          "requestId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9_-][A-Za-z0-9_.:-]*$"
          },
          "provider": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:@/-]*$"
          },
          "model": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:@/-]*$"
          },
          "settledAt": {
            "type": "integer",
            "minimum": 0,
            "description": "Unix epoch in milliseconds."
          },
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "error",
              "cancelled"
            ]
          },
          "hasTrace": {
            "type": "boolean"
          }
        }
      }
    },
    "alerts": {
      "type": "object",
      "required": [
        "evaluatedAt",
        "truncated",
        "items"
      ],
      "properties": {
        "evaluatedAt": {
          "type": [
            "integer",
            "null"
          ]
        },
        "truncated": {
          "type": "boolean"
        },
        "items": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key",
              "rule",
              "provider",
              "samples",
              "observed",
              "openedAt",
              "updatedAt"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "provider": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120,
                "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:@/-]*$"
              },
              "samples": {
                "type": "integer",
                "minimum": 0
              },
              "observed": {
                "type": "integer",
                "minimum": 0
              },
              "rule": {
                "type": "string",
                "enum": [
                  "provider_errors",
                  "slow_provider",
                  "billing_pending"
                ]
              },
              "openedAt": {
                "type": "integer",
                "minimum": 0,
                "description": "Unix epoch in milliseconds."
              },
              "updatedAt": {
                "type": "integer",
                "minimum": 0,
                "description": "Unix epoch in milliseconds."
              },
              "resolvedAt": {
                "type": "integer",
                "minimum": 0,
                "description": "Unix epoch in milliseconds."
              }
            }
          }
        }
      }
    }
  },
  "$defs": {
    "GatewayMetrics": {
      "type": "object",
      "required": [
        "key",
        "requests",
        "errors",
        "cancelled",
        "pendingBilling",
        "providerAttempts",
        "providerErrors",
        "traces",
        "inputTokens",
        "outputTokens",
        "cachedTokens",
        "reasoningTokens",
        "costCovered",
        "marginCovered",
        "invoiceConfirmed",
        "customerChargeNanos",
        "knownProviderCostNanos",
        "coveredMarginNanos",
        "latency",
        "firstToken",
        "providerLatency"
      ],
      "properties": {
        "requests": {
          "type": "integer",
          "minimum": 0
        },
        "errors": {
          "type": "integer",
          "minimum": 0
        },
        "cancelled": {
          "type": "integer",
          "minimum": 0
        },
        "pendingBilling": {
          "type": "integer",
          "minimum": 0
        },
        "providerAttempts": {
          "type": "integer",
          "minimum": 0
        },
        "providerErrors": {
          "type": "integer",
          "minimum": 0
        },
        "traces": {
          "type": "integer",
          "minimum": 0
        },
        "inputTokens": {
          "type": "integer",
          "minimum": 0
        },
        "outputTokens": {
          "type": "integer",
          "minimum": 0
        },
        "cachedTokens": {
          "type": "integer",
          "minimum": 0
        },
        "reasoningTokens": {
          "type": "integer",
          "minimum": 0
        },
        "costCovered": {
          "type": "integer",
          "minimum": 0
        },
        "marginCovered": {
          "type": "integer",
          "minimum": 0
        },
        "invoiceConfirmed": {
          "type": "integer",
          "minimum": 0
        },
        "key": {
          "type": "string"
        },
        "customerChargeNanos": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Integer USD nanodollars encoded as a string."
        },
        "knownProviderCostNanos": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Integer USD nanodollars encoded as a string."
        },
        "coveredMarginNanos": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "Integer USD nanodollars encoded as a string."
        },
        "latency": {
          "type": [
            "object",
            "null"
          ],
          "required": [
            "samples",
            "p50",
            "p95",
            "p99"
          ],
          "properties": {
            "samples": {
              "type": "integer",
              "minimum": 0
            },
            "p50": {
              "type": "integer",
              "minimum": 0
            },
            "p95": {
              "type": "integer",
              "minimum": 0
            },
            "p99": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "firstToken": {
          "type": [
            "object",
            "null"
          ],
          "required": [
            "samples",
            "p50",
            "p95",
            "p99"
          ],
          "properties": {
            "samples": {
              "type": "integer",
              "minimum": 0
            },
            "p50": {
              "type": "integer",
              "minimum": 0
            },
            "p95": {
              "type": "integer",
              "minimum": 0
            },
            "p99": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "providerLatency": {
          "type": [
            "object",
            "null"
          ],
          "required": [
            "samples",
            "p50",
            "p95",
            "p99"
          ],
          "properties": {
            "samples": {
              "type": "integer",
              "minimum": 0
            },
            "p50": {
              "type": "integer",
              "minimum": 0
            },
            "p95": {
              "type": "integer",
              "minimum": 0
            },
            "p99": {
              "type": "integer",
              "minimum": 0
            }
          }
        }
      }
    }
  }
}