{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/paywithlocus-com/json-schema/paywithlocus-com-analytics-response-schema.json",
  "title": "AnalyticsResponse",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/paywithlocus-com-openapi.json#/components/schemas/AnalyticsResponse",
  "type": "object",
  "required": [
    "success",
    "analytics"
  ],
  "properties": {
    "success": {
      "const": true
    },
    "analytics": {
      "type": "object",
      "required": [
        "days",
        "bucket",
        "filter",
        "timezone",
        "periodStart",
        "periodEndExclusive",
        "priorPeriodStart",
        "priorPeriodEndExclusive",
        "summary",
        "priorSummary",
        "series",
        "daily",
        "services",
        "providers",
        "users",
        "initiators",
        "usageDrift"
      ],
      "properties": {
        "days": {
          "type": [
            "integer",
            "null"
          ],
          "enum": [
            7,
            30,
            90,
            null
          ],
          "description": "Echo of the legacy form; null when the request used from/to."
        },
        "bucket": {
          "type": "string",
          "enum": [
            "hour",
            "day",
            "week",
            "month"
          ]
        },
        "filter": {
          "$ref": "#/$defs/AnalyticsFilter"
        },
        "timezone": {
          "const": "UTC"
        },
        "periodStart": {
          "type": "string",
          "format": "date-time"
        },
        "periodEndExclusive": {
          "type": "string",
          "format": "date-time"
        },
        "priorPeriodStart": {
          "type": "string",
          "format": "date-time"
        },
        "priorPeriodEndExclusive": {
          "type": "string",
          "format": "date-time"
        },
        "summary": {
          "$ref": "#/$defs/AnalyticsSummary"
        },
        "priorSummary": {
          "$ref": "#/$defs/AnalyticsSummary"
        },
        "series": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnalyticsBucket"
          }
        },
        "daily": {
          "type": "array",
          "description": "series relabelled by the UTC day of each bucket start; identical to series when bucket is day.",
          "items": {
            "$ref": "#/$defs/AnalyticsDay"
          }
        },
        "services": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnalyticsService"
          }
        },
        "providers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnalyticsProvider"
          }
        },
        "users": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnalyticsUser"
          }
        },
        "initiators": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnalyticsInitiator"
          }
        },
        "customerSources": {
          "type": "array",
          "description": "Spend per product over every customer burn in the window (not only the ranked ones), under the same filter.",
          "items": {
            "$ref": "#/$defs/AnalyticsCustomerSource"
          }
        },
        "usageDrift": {
          "oneOf": [
            {
              "$ref": "#/$defs/UsageDriftAnalytics"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "AnalyticsBucket": {
      "type": "object",
      "description": "One gap-filled series bucket.",
      "additionalProperties": false,
      "required": [
        "start",
        "usageUsdc",
        "baseUsdc",
        "marginUsdc",
        "calls",
        "activeUsers"
      ],
      "properties": {
        "start": {
          "type": "string",
          "format": "date-time",
          "description": "First instant of the bucket (UTC)."
        },
        "usageUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "baseUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "marginUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "calls": {
          "type": "integer",
          "minimum": 0
        },
        "activeUsers": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "AnalyticsCustomerSource": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "customers",
        "usageUsdc",
        "calls"
      ],
      "properties": {
        "source": {
          "type": "string"
        },
        "customers": {
          "type": "integer"
        },
        "usageUsdc": {
          "type": "string"
        },
        "calls": {
          "type": "integer"
        }
      }
    },
    "AnalyticsDay": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "date",
        "usageUsdc",
        "baseUsdc",
        "marginUsdc",
        "calls",
        "activeUsers"
      ],
      "properties": {
        "date": {
          "type": "string",
          "format": "date"
        },
        "usageUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "baseUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "marginUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "calls": {
          "type": "integer",
          "minimum": 0
        },
        "activeUsers": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "AnalyticsFilter": {
      "type": "object",
      "additionalProperties": false,
      "description": "The filter the response was computed under, echoed back.",
      "required": [
        "initiator",
        "provider",
        "endpoint"
      ],
      "properties": {
        "initiator": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "type",
                "id"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "oauth_member",
                    "end_user",
                    "agent_connection",
                    "customer",
                    "credential",
                    "unattributed"
                  ]
                },
                "id": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "provider": {
          "type": [
            "string",
            "null"
          ]
        },
        "endpoint": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "AnalyticsInitiator": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "initiatorId",
        "label",
        "authMethod",
        "clients",
        "usageUsdc",
        "marginUsdc",
        "calls",
        "providers"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "oauth_member",
            "end_user",
            "agent_connection",
            "customer",
            "credential",
            "unattributed"
          ]
        },
        "initiatorId": {
          "type": [
            "string",
            "null"
          ]
        },
        "label": {
          "type": "string"
        },
        "authMethod": {
          "type": [
            "string",
            "null"
          ]
        },
        "clients": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "usageUsdc": {
          "type": "string"
        },
        "marginUsdc": {
          "type": "string"
        },
        "calls": {
          "type": "integer"
        },
        "providers": {
          "type": "integer",
          "description": "Distinct providers this spender used in the current window."
        },
        "source": {
          "type": "string",
          "description": "Customer rows only: the product (attribution.source; '' when the charges carried none)."
        },
        "customerId": {
          "type": "string",
          "description": "Customer rows only: the tenant's own customer id. initiatorId is <URL-encoded source>/<customerId>."
        },
        "name": {
          "type": [
            "string",
            "null"
          ],
          "description": "Customer rows only: the customer directory's name, null when unnamed. label is the name when there is one."
        },
        "url": {
          "type": [
            "string",
            "null"
          ],
          "description": "Customer rows only: the directory's link for the customer."
        },
        "adminUrl": {
          "type": [
            "string",
            "null"
          ],
          "description": "Customer rows only: the directory's link into the tenant's own admin for the customer."
        }
      }
    },
    "AnalyticsProvider": {
      "type": "object",
      "description": "Provider-level rollup: every endpoint of one provider folded together.",
      "additionalProperties": false,
      "required": [
        "provider",
        "spenders",
        "endpoints",
        "usageUsdc",
        "baseUsdc",
        "marginUsdc",
        "calls",
        "activeUsers"
      ],
      "properties": {
        "provider": {
          "type": "string"
        },
        "spenders": {
          "type": "integer",
          "description": "Distinct spenders who used the provider."
        },
        "endpoints": {
          "type": "integer",
          "description": "Distinct endpoints used; a provider-level burn with no endpoint counts as one."
        },
        "usageUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "baseUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "marginUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "calls": {
          "type": "integer",
          "minimum": 0
        },
        "activeUsers": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "AnalyticsService": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "provider",
        "endpoint",
        "usageUsdc",
        "baseUsdc",
        "marginUsdc",
        "calls",
        "activeUsers",
        "spenders"
      ],
      "properties": {
        "provider": {
          "type": "string"
        },
        "endpoint": {
          "type": [
            "string",
            "null"
          ]
        },
        "usageUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "baseUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "marginUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "calls": {
          "type": "integer",
          "minimum": 0
        },
        "activeUsers": {
          "type": "integer",
          "minimum": 0,
          "description": "Distinct END USERS. Pooled agents, API keys and members have no end user, so an endpoint driven only by those reports zero here."
        },
        "spenders": {
          "type": "integer",
          "minimum": 0,
          "description": "Distinct spenders, the same population AnalyticsProvider.spenders counts."
        }
      }
    },
    "AnalyticsSummary": {
      "type": "object",
      "required": [
        "usageUsdc",
        "baseUsdc",
        "marginUsdc",
        "calls",
        "activeUsers"
      ],
      "properties": {
        "usageUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "baseUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "marginUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "calls": {
          "type": "integer",
          "minimum": 0
        },
        "activeUsers": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "AnalyticsUser": {
      "type": "object",
      "required": [
        "externalUserId",
        "usageUsdc",
        "marginUsdc",
        "calls"
      ],
      "properties": {
        "externalUserId": {
          "oneOf": [
            {
              "$ref": "#/$defs/ExternalUserId"
            },
            {
              "type": "null"
            }
          ]
        },
        "usageUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "marginUsdc": {
          "$ref": "#/$defs/DecimalString"
        },
        "calls": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "DecimalString": {
      "type": "string",
      "pattern": "^\\d+(?:\\.\\d{1,6})?$",
      "description": "Non-negative exact decimal string with at most six fractional digits. Endpoint-specific positivity and amount limits still apply."
    },
    "ExternalUserId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,199}$",
      "description": "Case-sensitive immutable ID in the tenant namespace. Prefer an identity-provider subject, not an email address."
    },
    "UsageDriftAnalytics": {
      "type": "object",
      "required": [
        "mode",
        "attributionCoverageRequired",
        "currentWindowDays",
        "baselineWindowDays",
        "collecting",
        "active",
        "recentResolved"
      ],
      "properties": {
        "mode": {
          "type": "string",
          "enum": [
            "shadow",
            "enabled"
          ]
        },
        "attributionCoverageRequired": {
          "$ref": "#/$defs/DecimalString"
        },
        "currentWindowDays": {
          "type": "integer"
        },
        "baselineWindowDays": {
          "type": "integer"
        },
        "collecting": {
          "type": "integer",
          "minimum": 0
        },
        "active": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/UsageDriftDetection"
          }
        },
        "recentResolved": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/UsageDriftDetection"
          }
        }
      },
      "additionalProperties": false
    },
    "UsageDriftDetection": {
      "type": "object",
      "required": [
        "id",
        "feature",
        "appVersion",
        "status",
        "severity",
        "mode",
        "coverageRatio",
        "baselineSamples",
        "currentSamples",
        "requiredSamples",
        "baseline",
        "current",
        "percentageChange",
        "adjustedPValue",
        "contributors",
        "lastEvaluatedAt",
        "ledgerFilterPath",
        "informational"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "feature": {
          "type": "string"
        },
        "appVersion": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "SHADOW",
            "ACTIVE",
            "RESOLVED"
          ]
        },
        "severity": {
          "type": "string",
          "enum": [
            "INFO",
            "WARNING",
            "CRITICAL"
          ]
        },
        "mode": {
          "type": "string",
          "enum": [
            "shadow",
            "enabled"
          ]
        },
        "coverageRatio": {
          "$ref": "#/$defs/DecimalString"
        },
        "baselineSamples": {
          "type": "integer",
          "minimum": 0
        },
        "currentSamples": {
          "type": "integer",
          "minimum": 0
        },
        "requiredSamples": {
          "type": "integer",
          "minimum": 0
        },
        "baseline": {
          "type": "object"
        },
        "current": {
          "type": "object"
        },
        "percentageChange": {
          "type": [
            "string",
            "null"
          ]
        },
        "adjustedPValue": {
          "type": [
            "string",
            "null"
          ]
        },
        "contributors": {
          "type": "object"
        },
        "firstSeenAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "detectedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "resolvedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "lastEvaluatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "ledgerFilterPath": {
          "type": "string"
        },
        "informational": {
          "const": true
        }
      }
    }
  }
}