{
  "id": "records-aggregate",
  "name": "Grouped record aggregates",
  "description": "WHEN TO USE: Summarize up to 1,000 records with count/sum/avg/min/max, grouped by up to 5 JSON Pointer fields. Up to 20 uniquely named metrics. Group order follows first occurrence; missing keys are distinguished from null through a parallel missing array. Numeric metrics ignore missing/null, reject other non-numbers and overflow; empty sum/count are 0 and empty avg/min/max are null. No groupBy returns one global group, even for empty input. Maximum 100,000 characters and depth 32.",
  "category": "structured",
  "priceUsd": "0.005",
  "pricingStatus": "proposed-unverified",
  "pricing": {
    "unit": "one successful operation call",
    "proposedNominalUsd": "0.005",
    "sixDecimalTokenBaseUnits": "5000",
    "subscription": false,
    "includesPayerWalletOrNetworkFees": false,
    "liveQuoteVerified": false,
    "condition": "Actual SDK challenge is authoritative only within the caller's explicit authorization; configured six-decimal token peg is an operator assertion, not a conversion guarantee."
  },
  "intents": [
    "group records sum average count",
    "aggregate JSON metrics"
  ],
  "whenToUse": [
    "Calculate count/sum/avg/min/max over supplied bounded records."
  ],
  "whenNotToUse": [
    "Database queries, streaming analytics, or arbitrary formulas."
  ],
  "capabilities": [
    "records-aggregate",
    "group records sum average count",
    "aggregate JSON metrics"
  ],
  "related": [
    "records-filter",
    "records-project"
  ],
  "limits": {
    "requestBytes": 131072,
    "responseBytes": 524288,
    "jsonDepth": 32
  },
  "errorCodes": [
    "INVALID_INPUT",
    "INPUT_TOO_LARGE",
    "OUTPUT_TOO_LARGE"
  ],
  "requirementsProfile": {
    "format": "declared-requirements-v1",
    "facts": {
      "execution.suppliedCode": false,
      "execution.remoteMutation": false,
      "execution.llmInference": false,
      "execution.paidMcp": false,
      "verification.semanticTruth": false,
      "verification.sourceAuthenticity": false,
      "verification.liveVulnerabilities": false,
      "numbers.arbitraryPrecisionJson": false,
      "numbers.model": "ieee754-binary64",
      "privacy.requestBodyPersisted": false,
      "execution.deterministic": true,
      "execution.networkAccess": false,
      "privacy.resultBodyPersisted": false,
      "payment.x402": true,
      "payment.mpp": true,
      "operation.id": "records-aggregate",
      "operation.category": "structured",
      "limit.httpRequestBytes": 131072,
      "limit.requestBytes": 131072,
      "limit.responseBytes": 524288,
      "limit.resultBytes": 523264,
      "limit.jsonDepth": 32,
      "limit.jsonNodes": 20000,
      "input.records.maxItems": 1000,
      "input.groupBy.maxItems": 5,
      "input.metrics.maxItems": 20,
      "input.metrics.minItems": 1
    },
    "unknownPolicy": "Undeclared requirements are unknown, never compatible. Matching declared facts does not establish semantic fit or input validity.",
    "preflight": "/preflight"
  },
  "documentation": "/reference/tools/records-aggregate.md",
  "serviceContract": "/reference/services/records-aggregate.json",
  "errors": [
    {
      "status": 400,
      "meaning": "Malformed JSON, missing/invalid idempotency key, or payment identifier mismatch",
      "retry": "Correct the request before payment"
    },
    {
      "status": 402,
      "meaning": "Payment challenge or rejected payment",
      "retry": "Use official protocol SDK; inspect payment outcome before another payment"
    },
    {
      "status": 409,
      "meaning": "Idempotency conflict, duplicate proof, or PAYMENT_UNCERTAIN",
      "retry": "Keep original key, body, and proof; reconcile uncertainty with operator; never blindly repay"
    },
    {
      "status": 413,
      "meaning": "Input or generated output too large",
      "retry": "Reduce input; no payment attempted for validation failure"
    },
    {
      "status": 415,
      "meaning": "Unsupported media type or compression",
      "retry": "Send uncompressed application/json"
    },
    {
      "status": 422,
      "meaning": "Schema or service-specific semantic validation failure",
      "retry": "Correct input using returned error code; no payment attempted"
    },
    {
      "status": 429,
      "meaning": "Request/payment-attempt rate exceeded",
      "retry": "Wait for rate limit window; preserve existing payment identity"
    },
    {
      "status": 503,
      "meaning": "Payment configuration/provider/state unavailable, or live DNS preparation failed before settlement",
      "retry": "Check readiness; DNS preparation failures may retry the identical key/body/credential only; uncertainty requires reconciliation"
    }
  ],
  "numericPrecision": "JavaScript IEEE-754 numbers; use strings for large integer IDs/exact decimals where the schema accepts strings. No lossless numeric parsing.",
  "paymentWorkflow": {
    "discoveryOnly": false,
    "supportedProtocols": [
      "x402",
      "mpp"
    ],
    "x402": {
      "credentialHeader": "PAYMENT-SIGNATURE",
      "challengeHeader": "PAYMENT-REQUIRED",
      "receiptHeader": "PAYMENT-RESPONSE",
      "version": 2,
      "scheme": "exact",
      "paymentIdentifier": "payment-identifier extension MUST equal the HTTP Idempotency-Key",
      "sdk": "@x402/core with @x402/evm"
    },
    "mpp": {
      "supported": true,
      "credentialHeader": "Authorization",
      "challengeHeader": "WWW-Authenticate",
      "receiptHeader": "Payment-Receipt",
      "method": "tempo",
      "intent": "charge",
      "sdk": "mppx",
      "tokenDecimals": 6
    },
    "steps": [
      "Check configured readiness and the exact service schema",
      "Generate a fresh random Idempotency-Key for this operation; never use a discovery probe fixture for purchases",
      "Send valid input without a credential to obtain the official protocol challenge",
      "Use the official SDK and authorized wallet to fulfill the challenge",
      "Retry only with identical key, body, protocol and credential",
      "On PAYMENT_UNCERTAIN stop and request operator reconciliation; never blindly pay again"
    ],
    "versionedRetries": "Request fingerprint includes service release version. Retries across a version upgrade can conflict; coordinate upgrades outside the 24-hour replay window and reconcile pending attempts.",
    "docs": "/llms.txt"
  },
  "method": "POST",
  "paths": {
    "x402": "/v1/x402/records-aggregate",
    "mpp": "/v1/mpp/records-aggregate"
  },
  "inputSchema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "records": {
        "maxItems": 1000,
        "type": "array",
        "items": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      },
      "groupBy": {
        "default": [],
        "maxItems": 5,
        "type": "array",
        "items": {
          "type": "string",
          "maxLength": 2048,
          "description": "RFC 6901 JSON string pointer; empty string selects the root. URI fragments are not accepted."
        }
      },
      "metrics": {
        "minItems": 1,
        "maxItems": 20,
        "type": "array",
        "items": {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "as": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "op": {
                  "type": "string",
                  "const": "count"
                }
              },
              "required": [
                "as",
                "op"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "as": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 256
                },
                "op": {
                  "type": "string",
                  "enum": [
                    "sum",
                    "avg",
                    "min",
                    "max"
                  ]
                },
                "path": {
                  "type": "string",
                  "maxLength": 2048,
                  "description": "RFC 6901 JSON string pointer; empty string selects the root. URI fragments are not accepted."
                }
              },
              "required": [
                "as",
                "op",
                "path"
              ],
              "additionalProperties": false
            }
          ]
        }
      }
    },
    "required": [
      "records",
      "metrics"
    ],
    "additionalProperties": false,
    "$defs": {
      "__schema0": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "number"
          },
          {
            "type": "boolean"
          },
          {
            "type": "null"
          },
          {
            "type": "array",
            "items": {
              "$ref": "#/$defs/__schema0"
            }
          },
          {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "$ref": "#/$defs/__schema0"
            }
          }
        ]
      }
    }
  },
  "outputSchema": {
    "type": "object",
    "required": [
      "operation",
      "version",
      "result",
      "provenance"
    ],
    "properties": {
      "operation": {
        "const": "records-aggregate",
        "type": "string"
      },
      "version": {
        "const": "0.29.0",
        "type": "string"
      },
      "result": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          "groups": {
            "maxItems": 1000,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "maxItems": 5,
                  "type": "array",
                  "items": {
                    "$ref": "#/properties/result/$defs/__schema0"
                  }
                },
                "missing": {
                  "maxItems": 5,
                  "type": "array",
                  "items": {
                    "type": "boolean"
                  }
                },
                "count": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "metrics": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {
                    "type": [
                      "number",
                      "null"
                    ]
                  }
                }
              },
              "required": [
                "key",
                "missing",
                "count",
                "metrics"
              ],
              "additionalProperties": false
            }
          },
          "groupCount": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "recordCount": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "groups",
          "groupCount",
          "recordCount"
        ],
        "additionalProperties": false,
        "$defs": {
          "__schema0": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              },
              {
                "type": "null"
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/properties/result/$defs/__schema0"
                }
              },
              {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {
                  "$ref": "#/properties/result/$defs/__schema0"
                }
              }
            ]
          }
        }
      },
      "provenance": {
        "type": "object",
        "required": [
          "inputSha256",
          "outputSha256",
          "deterministic",
          "externalRequests"
        ],
        "properties": {
          "inputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "outputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "deterministic": {
            "const": true
          },
          "externalRequests": {
            "const": 0
          }
        }
      }
    },
    "additionalProperties": false
  },
  "exampleInput": {
    "records": [
      {
        "region": "west",
        "revenue": 50
      },
      {
        "region": "west",
        "revenue": 70
      },
      {
        "region": "east",
        "revenue": 40
      }
    ],
    "groupBy": [
      "/region"
    ],
    "metrics": [
      {
        "as": "orders",
        "op": "count"
      },
      {
        "as": "revenue",
        "op": "sum",
        "path": "/revenue"
      }
    ]
  },
  "exampleResponse": {
    "operation": "records-aggregate",
    "version": "0.29.0",
    "result": {
      "groups": [
        {
          "key": [
            "west"
          ],
          "missing": [
            false
          ],
          "count": 2,
          "metrics": {
            "orders": 2,
            "revenue": 120
          }
        },
        {
          "key": [
            "east"
          ],
          "missing": [
            false
          ],
          "count": 1,
          "metrics": {
            "orders": 1,
            "revenue": 40
          }
        }
      ],
      "groupCount": 2,
      "recordCount": 3
    },
    "provenance": {
      "inputSha256": "1924642abbb9dfc99b456bc9f2aa018f71096fa07cd1d5289e23237e3ca70b97",
      "outputSha256": "092e95776a8a0b1c38162cc0100533a2e195b8d90f706500a5865e45ed0a24eb",
      "deterministic": true,
      "externalRequests": 0
    }
  },
  "requiredHeaders": {
    "Content-Type": "application/json",
    "Idempotency-Key": "random 16–128 character operation identifier"
  },
  "fixedExample": "/reference/examples/records-aggregate.json",
  "execution": {
    "deterministic": true,
    "externalRequests": 0,
    "maxExternalRequests": 0,
    "resultSnapshotPersisted": false,
    "fixedExampleIsIllustrativeSnapshot": false,
    "requiresPayment": true,
    "supportsMcpExecution": false
  },
  "releaseSnapshot": {
    "format": "static-release-reference-v1",
    "sourceVersion": "0.29.0",
    "sourceRegistrySha256": "a2b5ec09bf6c38b9d2879d746a4fded374f5928b445377b0270ef6aa8e6cac65",
    "generatedAt": "2026-10-06T15:38:00Z",
    "releaseAcceptance": "not-verified-by-generator",
    "runtimeReadiness": "not-evaluated",
    "livePaymentsVerified": false,
    "indexingVerified": false,
    "apiOrigin": null,
    "notice": "Build-time release reference. Runtime readiness, deployment, payment settlement and external indexing are not evaluated here. Prices are proposed; this file cannot authorize execution or payment."
  }
}
