{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/eurobase-dev/json-schema/eurobase-dev-metering-ingest-request-schema.json",
  "title": "MeteringIngestRequest",
  "description": "The union of every counter sourceReservationIds array and every function request sourceReservationId must exactly equal the top-level sourceReservationIds set. Every row member must belong to that set. A batch contains at most 500 counters plus function requests and at most 2,000 contribution references.",
  "x-generated": "2026-11-07",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/eurobase-dev-openapi.json#/components/schemas/MeteringIngestRequest",
  "type": "object",
  "required": [
    "producerId",
    "batchId",
    "batchSequence",
    "schemaVersion",
    "sourceReservationIds"
  ],
  "properties": {
    "producerId": {
      "type": "string"
    },
    "batchId": {
      "type": "string"
    },
    "batchSequence": {
      "type": "integer"
    },
    "schemaVersion": {
      "type": "string",
      "const": "usage-metering.v2"
    },
    "sourceReservationIds": {
      "type": "array",
      "minItems": 1,
      "maxItems": 500,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 160
      }
    },
    "observedAfter": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "counters": {
      "type": "array",
      "maxItems": 500,
      "items": {
        "type": "object",
        "required": [
          "projectId",
          "resourceType",
          "resourceId",
          "metricCode",
          "unit",
          "windowStart",
          "windowEnd",
          "valueDecimal",
          "sourceFamily",
          "sourceReservationIds",
          "observedAt"
        ],
        "properties": {
          "organizationId": {
            "type": [
              "string",
              "null"
            ]
          },
          "projectId": {
            "type": "string"
          },
          "resourceType": {
            "type": "string"
          },
          "resourceId": {
            "type": "string"
          },
          "metricCode": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "windowStart": {
            "type": "string",
            "format": "date-time"
          },
          "windowEnd": {
            "type": "string",
            "format": "date-time"
          },
          "valueDecimal": {
            "type": "string",
            "pattern": "^[0-9]+(?:\\.[0-9]+)?$"
          },
          "sourceFamily": {
            "type": "string"
          },
          "sourceReservationIds": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 160
            }
          },
          "pricingVersion": {
            "type": [
              "string",
              "null"
            ]
          },
          "observedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    },
    "functionRequests": {
      "type": "array",
      "maxItems": 500,
      "items": {
        "type": "object",
        "required": [
          "sourceReservationId",
          "projectId",
          "resourceType",
          "resourceId",
          "routeId",
          "functionId",
          "startedAt",
          "finishedAt",
          "httpStatus",
          "latencyMs",
          "outcome",
          "sourceFamily"
        ],
        "properties": {
          "sourceReservationId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 160
          },
          "projectId": {
            "type": "string"
          },
          "resourceType": {
            "type": "string",
            "enum": [
              "function"
            ]
          },
          "resourceId": {
            "type": "string"
          },
          "routeId": {
            "type": "string"
          },
          "functionId": {
            "type": "string"
          },
          "deploymentId": {
            "type": [
              "string",
              "null"
            ]
          },
          "method": {
            "type": [
              "string",
              "null"
            ]
          },
          "normalizedPath": {
            "type": [
              "string",
              "null"
            ]
          },
          "observedHost": {
            "type": [
              "string",
              "null"
            ]
          },
          "startedAt": {
            "type": "string",
            "format": "date-time"
          },
          "finishedAt": {
            "type": "string",
            "format": "date-time"
          },
          "httpStatus": {
            "type": "integer"
          },
          "statusClass": {
            "type": [
              "string",
              "null"
            ]
          },
          "latencyMs": {
            "type": "integer"
          },
          "responseBytes": {
            "type": "integer"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "success",
              "error",
              "timeout"
            ]
          },
          "sourceFamily": {
            "type": "string",
            "enum": [
              "gateway"
            ]
          }
        }
      }
    }
  }
}