KPIs API

ProBeya provides a comprehensive KPI system organized around the SQCDP framework: Safety, Quality, Cost, Delivery, and People. Each KPI definition is attached to a board and supports manual/automated value entry, target management, time-series analysis, threshold-based alerting (green/amber/red), and SPC (Statistical Process Control) with control limits and capability indices.

Quick Start: Ingesting OEE from Your MES

Record a daily OEE measurement from your manufacturing execution system in a single call:

curl -X POST https://acme.probeya.com/api/v1/kpis/clx9kp001/values \
  -H "Authorization: Bearer probeya_sk_live_7f3a..." \
  -H "Content-Type: application/json" \
  -d '{
    "value": 87.3,
    "date": "2026-04-13",
    "comment": "Line 2 down 45min for seal replacement. OEE recovery by 14:00.",
    "source": "mes_historian"
  }'

Endpoints

GET /api/v1/kpis

List all KPI definitions for a specific board, enriched with the latest value and active target for each.

tRPC: kpis.list | Scope: read:kpis | Org context: Required

Parameters:

NameTypeRequiredDescription
boardIdstring (query)YesThe board to list KPIs for
curl -H "Authorization: Bearer probeya_sk_live_7f3a..." \
     "https://acme.probeya.com/api/v1/kpis?boardId=clx9bd001"

Response:

{
  "data": [
    {
      "id": "clx9kp001",
      "name": "OEE (Overall Equipment Effectiveness)",
      "category": "delivery",
      "unit": "%",
      "frequency": "daily",
      "direction": "higher_is_better",
      "dataSource": "manual",
      "boardId": "clx9bd001",
      "organizationId": "clx9abc123def",
      "thresholds": {
        "red": 65,
        "amber": 75,
        "green": 85
      },
      "latestValue": {
        "value": 82.5,
        "date": "2026-04-12",
        "status": "amber"
      },
      "activeTarget": {
        "targetValue": 90,
        "periodStart": "2026-01-01",
        "periodEnd": "2026-12-31"
      },
      "createdAt": "2026-02-01T10:00:00.000Z"
    },
    {
      "id": "clx9kp002",
      "name": "Right First Time",
      "category": "quality",
      "unit": "%",
      "frequency": "daily",
      "direction": "higher_is_better",
      "dataSource": "manual",
      "boardId": "clx9bd001",
      "organizationId": "clx9abc123def",
      "thresholds": {
        "red": 90,
        "amber": 95,
        "green": 98
      },
      "latestValue": {
        "value": 96.2,
        "date": "2026-04-12",
        "status": "amber"
      },
      "activeTarget": {
        "targetValue": 99.0,
        "periodStart": "2026-01-01",
        "periodEnd": "2026-06-30"
      },
      "createdAt": "2026-02-01T10:05:00.000Z"
    },
    {
      "id": "clx9kp003",
      "name": "Safety Incidents (LTI)",
      "category": "safety",
      "unit": "count",
      "frequency": "monthly",
      "direction": "lower_is_better",
      "dataSource": "manual",
      "boardId": "clx9bd001",
      "organizationId": "clx9abc123def",
      "thresholds": {
        "green": 0,
        "amber": 1,
        "red": 3
      },
      "latestValue": {
        "value": 0,
        "date": "2026-04-01",
        "status": "green"
      },
      "activeTarget": {
        "targetValue": 0,
        "periodStart": "2026-01-01",
        "periodEnd": "2026-12-31"
      },
      "createdAt": "2026-02-01T10:10:00.000Z"
    }
  ]
}

Errors:

CodeDescriptionCauseFix
401UNAUTHORIZEDMissing or invalid authenticationCheck your Bearer token
404NOT_FOUNDBoard not found in this organizationVerify the boardId and org context

POST /api/v1/kpis/:id/values

Record a single manual KPI measurement. Uses upsert semantics — if a value already exists for the same KPI and date, it is overwritten. The enteredById is automatically set to the authenticated user for audit trail compliance.

tRPC: kpis.setValue | Scope: write:kpis | Org context: Required

Parameters:

NameTypeRequiredDescription
idstring (path)YesThe KPI definition ID
valuenumber or stringYesThe measurement value
datestringYesISO 8601 date (e.g., 2026-04-13)
commentstringNoOptional note about the measurement
sourcestringNoData source identifier (default: manual)
curl -X POST https://acme.probeya.com/api/v1/kpis/clx9kp002/values \
  -H "Authorization: Bearer probeya_sk_live_7f3a..." \
  -H "Content-Type: application/json" \
  -d '{
    "value": 97.8,
    "date": "2026-04-13",
    "comment": "Reject on Line 1 was a labeling error, not product quality",
    "source": "manual"
  }'

Response:

{
  "data": {
    "id": "clx9kv120",
    "kpiDefinitionId": "clx9kp002",
    "value": 97.8,
    "date": "2026-04-13",
    "comment": "Reject on Line 1 was a labeling error, not product quality",
    "source": "manual",
    "enteredById": "clx9us001",
    "organizationId": "clx9abc123def",
    "createdAt": "2026-04-13T14:00:00.000Z"
  }
}

Side effects:

  • Logs activity event with KPI name, value, and date
  • Evaluates threshold alerts (red/amber/green) and sends notifications if breached
  • Fires kpi.value_recorded webhook
  • Invalidates Redis cache for KPI data

Errors:

CodeDescriptionCauseFix
400BAD_REQUESTInvalid date format or missing valueUse YYYY-MM-DD date format
401UNAUTHORIZEDMissing or invalid authenticationCheck your Bearer token
403FORBIDDENInsufficient scopeAPI key needs write:kpis scope
404NOT_FOUNDKPI definition not found in this orgVerify the KPI ID and org context

POST /api/v1/kpis/:id/batch-values (tRPC: kpis.batchSetValues)

Record multiple measurements in a single call. Ideal for MES/SCADA integrations that push daily data for multiple dates or multiple KPIs. Scales linearly: 365 rows take approximately 200ms.

curl -X POST https://acme.probeya.com/api/v1/kpis/clx9kp001/batch-values \
  -H "Authorization: Bearer probeya_sk_live_7f3a..." \
  -H "Content-Type: application/json" \
  -d '{
    "values": [
      { "date": "2026-04-10", "value": 84.1, "source": "mes_historian" },
      { "date": "2026-04-11", "value": 86.7, "source": "mes_historian" },
      { "date": "2026-04-12", "value": 82.5, "source": "mes_historian" },
      { "date": "2026-04-13", "value": 87.3, "source": "mes_historian" }
    ]
  }'

Response:

{
  "data": {
    "inserted": 4,
    "kpiDefinitionId": "clx9kp001"
  }
}

Threshold Alerting

KPIs support automatic traffic-light evaluation based on configurable thresholds. When a new measurement breaches the red threshold, ProBeya sends a notification to relevant team members.

DirectionGreenAmberRed
higher_is_bettervalue >= greenvalue >= amber AND value < greenvalue < amber
lower_is_bettervalue <= greenvalue <= amber AND value > greenvalue > amber

Example: OEE thresholds

Thresholds: red=65, amber=75, green=85 (higher_is_better)

OEE = 87.3% → GREEN  (87.3 >= 85)
OEE = 79.1% → AMBER  (79.1 >= 75 but < 85)
OEE = 62.4% → RED    (62.4 < 75) — notification sent

SQCDP Categories

CategoryDescriptionTypical KPIs
safetySafety incidents, near-misses, complianceLTI rate, near-miss count, safety observation rate
qualityDefect rates, yield, first-pass qualityRight First Time %, batch rejection rate, OOS count
costCost per unit, budget variance, wasteCost per unit, scrap %, energy cost/unit
deliveryOEE, on-time delivery, lead timeOEE %, on-time-in-full (OTIF), cycle time
peopleAbsenteeism, training hours, engagementAbsenteeism %, training hours/FTE, mood score

Pharma Integration Scenarios


SPC (Statistical Process Control)

ProBeya includes a built-in SPC engine for advanced KPI analysis, accessible via the tRPC-only kpis.getControlChart procedure:

  • Control limits calculated using standard Western Electric rules (X-bar, R-chart)
  • Capability indices (Cp, Cpk) for process capability assessment
  • Rule violations detected automatically: runs above/below center, trends, outliers
  • Configurable via the spcConfig field on the KPI definition

Expected response time: 20-100ms depending on dataset size (SPC calculations are performed in-memory).


KPI Hierarchy

KPIs can be organized in parent-child relationships. A parent KPI’s value is automatically computed from its children (e.g., a site-level OEE computed from individual line OEEs). Use kpis.getTree to fetch the full hierarchy and kpis.recalculate to recompute parent values.


tRPC-Only KPI Procedures

ProcedureDescriptionExpected Latency
kpis.defineCreate a new KPI definition on a board10-30ms
kpis.updateUpdate KPI definition (name, thresholds, unit, etc.)10-30ms
kpis.deleteDelete a KPI and all its values/targets (cascade)15-50ms
kpis.listByCategoryList KPIs grouped by SQCDP category10-50ms
kpis.getValueGet the latest value for a specific KPI3-10ms
kpis.getHistoryGet time-series data with optional date range filter5-30ms
kpis.batchSetValuesRecord multiple measurements in a single call20-200ms
kpis.getAlertsGet KPIs currently breaching red/amber thresholds10-50ms
kpis.getTargetsGet all targets for a KPI3-10ms
kpis.setTargetCreate or update a period-specific target10-30ms
kpis.getTreeGet full KPI hierarchy tree for a board10-50ms
kpis.getChildrenGet child KPIs of a parent KPI5-20ms
kpis.recalculateRecompute a parent KPI value from children15-60ms
kpis.getControlChartGet SPC control chart data with control limits20-100ms
kpis.updateSpcConfigUpdate SPC configuration for a KPI10-30ms

Rate Limiting

PlanRequests/minBatch values/call
Free6030
Starter12090
Pro300365
Enterprise6001000