{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/usagemax-com/json-schema/usagemax-com-gateway-receipt-schema.json",
  "title": "GatewayReceipt",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/usagemax-com-openapi.json#/components/schemas/GatewayReceipt",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "requestId",
    "revision",
    "model",
    "provider",
    "status",
    "settledAt",
    "currency",
    "customerChargeNanos",
    "providerCostNanos",
    "providerCostBasis",
    "usage"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "requestId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "pattern": "^[A-Za-z0-9_-][A-Za-z0-9_.:-]*$"
    },
    "revision": {
      "type": "integer",
      "minimum": 1
    },
    "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_.:@/-]*$"
    },
    "resolvedModel": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:@/-]*$"
    },
    "traceId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "pattern": "^[A-Za-z0-9_-][A-Za-z0-9_.:-]*$"
    },
    "trace": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "billingStatus",
        "spans"
      ],
      "properties": {
        "billingStatus": {
          "type": "string",
          "enum": [
            "final",
            "pending"
          ]
        },
        "spans": {
          "type": "array",
          "minItems": 1,
          "maxItems": 12,
          "items": {
            "$ref": "#/$defs/GatewaySpan"
          }
        }
      }
    },
    "status": {
      "type": "string",
      "enum": [
        "ok",
        "error",
        "cancelled"
      ]
    },
    "settledAt": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix epoch in milliseconds."
    },
    "startedAt": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix epoch in milliseconds."
    },
    "firstTokenAt": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix epoch in milliseconds."
    },
    "stream": {
      "type": "boolean"
    },
    "currency": {
      "const": "USD"
    },
    "customerChargeNanos": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "description": "USD nanodollars. A null value means this amount was unavailable."
    },
    "providerCostNanos": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "description": "USD nanodollars. A null value means this amount was unavailable."
    },
    "providerCostBasis": {
      "type": "string",
      "enum": [
        "provider_reported",
        "invoice_confirmed",
        "estimated",
        "unknown"
      ]
    },
    "usage": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "inputTokens": {
          "type": "integer",
          "minimum": 0
        },
        "outputTokens": {
          "type": "integer",
          "minimum": 0
        },
        "cacheReadTokens": {
          "type": "integer",
          "minimum": 0
        },
        "cacheWriteTokens": {
          "type": "integer",
          "minimum": 0
        },
        "reasoningTokens": {
          "type": "integer",
          "minimum": 0
        },
        "reportedTotalTokens": {
          "type": "integer",
          "minimum": 0
        },
        "unclassifiedTokens": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  },
  "$defs": {
    "GatewaySpan": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "spanId",
        "kind",
        "startedAt",
        "endedAt",
        "status"
      ],
      "properties": {
        "spanId": {
          "type": "string",
          "pattern": "^[a-f0-9]{16}$"
        },
        "parentSpanId": {
          "type": "string",
          "pattern": "^[a-f0-9]{16}$"
        },
        "kind": {
          "type": "string",
          "enum": [
            "request",
            "reservation",
            "provider",
            "verification",
            "settlement",
            "recovery"
          ]
        },
        "startedAt": {
          "type": "integer",
          "minimum": 0,
          "description": "Unix epoch in milliseconds."
        },
        "endedAt": {
          "type": "integer",
          "minimum": 0,
          "description": "Unix epoch in milliseconds."
        },
        "status": {
          "type": "string",
          "enum": [
            "ok",
            "error"
          ]
        },
        "httpStatus": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599
        },
        "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_.:@/-]*$"
        },
        "outcome": {
          "type": "string",
          "enum": [
            "success",
            "http_error",
            "transport_error",
            "invalid_response",
            "verification_failed",
            "incomplete_stream"
          ]
        }
      }
    }
  }
}