Guides

KPIs


Python SDK Integration

While this guide focuses on UI-based workflows, Pay-i also provides comprehensive SDK support for automating KPI creation and data collection. If you're looking to integrate KPIs into your applications programmatically, we recommend the following resources:

The Python SDK provides methods for:

  • Creating KPI definitions for use case types
  • Recording KPI values for specific use case instances
  • Retrieving, updating, and deleting KPI data

For example, to define a KPI and record a value:

from payi import Payi

client = Payi()

# Define a KPI for a use case type
client.use_cases.definitions.kpis.create(
    use_case_name="Chat-Bot",
    kpi_name="Deflection Rate",
    description="Tracks when AI resolves issues without human intervention",
    kpi_type="boolean",
    goal=0.25
)

# Later, record a value for a specific instance
client.use_cases.kpis.create(
    kpi_name="Deflection Rate",
    use_case_id="uc_123456789",
    score=1.0
)

For complete SDK documentation and extensive examples, see the Python SDK KPIs guide.

Implementation Note

KPIs are always associated with a specific use case instance (identified by a use_case_id). This connection ensures that your custom metrics are linked to the exact context in which they were generated, providing a comprehensive view alongside the standard metrics Pay-i already tracks.

When submitting KPI values through the Python SDK, all values are provided as floating-point numbers (float), regardless of the KPI type:

# All KPI values are provided as float
client.use_cases.kpis.create(
    kpi_name="Clickthrough Rate",  # Boolean KPI
    use_case_id=use_case_id,
    score=1.0  # Boolean values: 1.0 = true, 0.0 = false
)

client.use_cases.kpis.create(
    kpi_name="Customer Satisfaction",  # Likert5 KPI
    use_case_id=use_case_id,
    score=4.5  # Rating on 1-5 scale
)

For boolean KPIs specifically, use:

  • 1.0 to represent true/success outcomes
  • 0.0 to represent false/failure outcomes

The Pay-i system interprets these values according to the KPI type, ensuring proper display in dashboards and reports.