{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/sigr-bill-v1.json",
  "title": "SiGR Bill v1, signed inference cost or billing receipt",
  "description": "Canonical schema for the Hive SiGR Bill receipt, canonical type sigr.bill. Binds a caller declared inference request (model, input and output token counts, unit prices) into one Ed25519 signature over a recomputable payload_sha256 and a recomputable total_micro_usd. The receipt attests that the recorded token counts and unit prices, multiplied and summed exactly as recorded, produce total_micro_usd. It does not attest that the input or output token counts are themselves accurate, that the unit prices reflect any published price list, or that the underlying inference actually ran.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_sigr\\.bill_[0-9]{10,}_[0-9a-f]{12}$"
    },
    "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{86}$" },
    "key_id": { "type": "string", "pattern": "^did:(hive|web|key):[A-Za-z0-9._:%-]+$" },
    "algorithm": { "type": "string", "const": "Ed25519" },
    "ts": { "type": "integer", "minimum": 1000000000 },
    "signed_body": {
      "type": "object",
      "required": [
        "receipt_type",
        "schema",
        "request_id",
        "tenant_id",
        "model_id",
        "input_tokens",
        "output_tokens",
        "price_input_micro_usd_per_1k",
        "price_output_micro_usd_per_1k",
        "total_micro_usd",
        "billed_at",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "sigr.bill" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "request_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "tenant_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "model_id": { "type": "string", "minLength": 1, "maxLength": 256 },
        "input_tokens": { "type": "integer", "minimum": 0, "maximum": 100000000 },
        "output_tokens": { "type": "integer", "minimum": 0, "maximum": 100000000 },
        "price_input_micro_usd_per_1k": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000,
          "description": "Micro-USD (1e-6 USD) charged per 1000 input tokens. Integer to avoid floating point drift in the signed digest."
        },
        "price_output_micro_usd_per_1k": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000,
          "description": "Micro-USD (1e-6 USD) charged per 1000 output tokens."
        },
        "total_micro_usd": {
          "type": "integer",
          "minimum": 0,
          "description": "Recomputed by the verifier as round(input_tokens * price_input_micro_usd_per_1k / 1000) + round(output_tokens * price_output_micro_usd_per_1k / 1000). A caller supplied total_micro_usd that does not match this recomputation fails TOTAL_RECOMPUTE."
        },
        "billed_at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,9})?Z$"
        },
        "boundary": {
          "type": "string",
          "const": "This receipt attests that total_micro_usd recomputes exactly from the recorded input_tokens, output_tokens, price_input_micro_usd_per_1k, and price_output_micro_usd_per_1k. It does not attest that the token counts are accurate, that the unit prices reflect any published or contractual price list, or that the underlying inference request actually ran."
        }
      }
    }
  }
}
