> ## Documentation Index
> Fetch the complete documentation index at: https://docs.capedigital.co.ke/llms.txt
> Use this file to discover all available pages before exploring further.

# Pipeline velocity — time-in-stage and deal cycle time

> Powers the **Stage velocity** chart and the **Avg. time to close** KPI on the **Leads & pipeline** screen.

Derived from the `LeadEvent` audit trail, not current-state snapshots, so it measures how long leads actually dwell at each stage before moving on.

| Field | Meaning |
|---|---|
| `stages[].avg_days_in_stage` | Mean days a lead waits at the stage before transitioning (null if no exits observed in the period) |
| `stages[].transitions` | Number of stage exits sampled |
| `avg_cycle_days` | Mean days from a lead's first event to commitment, for deals won in the period |
| `won_deals` | Deals committed in the period (cycle-time sample size) |



## OpenAPI

````yaml /openapi/commercial.yaml get /api/v1/analytics/sales/pipeline-velocity
openapi: 3.0.3
info:
  title: Commercial Service API
  version: 1.0.0
  description: |2-

        **Commercial Service API** - Lead management and campaign workflow system.

        ## Versioning
        The API uses URL path versioning (e.g., `/api/v1/`, `/api/v2/`).
        Current version: **v1**
        
servers:
  - url: https://api.capedigital.co.ke/commercial
    description: Production
  - url: http://localhost:8000
    description: Local
security: []
paths:
  /api/v1/analytics/sales/pipeline-velocity:
    get:
      tags:
        - Pipeline
      summary: Pipeline velocity — time-in-stage and deal cycle time
      description: >-
        Powers the **Stage velocity** chart and the **Avg. time to close** KPI
        on the **Leads & pipeline** screen.


        Derived from the `LeadEvent` audit trail, not current-state snapshots,
        so it measures how long leads actually dwell at each stage before moving
        on.


        | Field | Meaning |

        |---|---|

        | `stages[].avg_days_in_stage` | Mean days a lead waits at the stage
        before transitioning (null if no exits observed in the period) |

        | `stages[].transitions` | Number of stage exits sampled |

        | `avg_cycle_days` | Mean days from a lead's first event to commitment,
        for deals won in the period |

        | `won_deals` | Deals committed in the period (cycle-time sample size) |
      operationId: analytics_sales_pipeline_velocity_retrieve
      parameters:
        - in: query
          name: period
          schema:
            type: string
          description: |-
            Period string. Accepted formats:
            - `2026-05` — calendar month
            - `Q2-2026` — quarter (Q1–Q4)
            - `YTD-2026` — year to date
          required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PipelineVelocity'
              examples:
                May2026:
                  value:
                    won_deals: 11
                    avg_cycle_days: '34.20'
                    stages:
                      - key: nurturing
                        label: Nurturing
                        avg_days_in_stage: '12.40'
                        transitions: 38
                      - key: qualification
                        label: Qualification
                        avg_days_in_stage: '3.20'
                        transitions: 30
                      - key: proposal
                        label: Proposal
                        avg_days_in_stage: '6.80'
                        transitions: 24
                      - key: contract
                        label: Contract
                        avg_days_in_stage: '5.10'
                        transitions: 18
                      - key: client_commitment
                        label: Client Commitment
                        avg_days_in_stage: '2.60'
                        transitions: 13
                      - key: deal_closing
                        label: Deal Closing
                        avg_days_in_stage: '4.30'
                        transitions: 11
                  summary: May 2026
          description: ''
      security:
        - bearerAuth: []
components:
  schemas:
    PipelineVelocity:
      type: object
      properties:
        won_deals:
          type: integer
        avg_cycle_days:
          type: string
          format: decimal
          pattern: ^-?\d{0,8}(?:\.\d{0,2})?$
        stages:
          type: array
          items:
            $ref: '#/components/schemas/StageVelocity'
      required:
        - avg_cycle_days
        - stages
        - won_deals
    StageVelocity:
      type: object
      properties:
        key:
          type: string
        label:
          type: string
        avg_days_in_stage:
          type: string
          format: decimal
          pattern: ^-?\d{0,8}(?:\.\d{0,2})?$
          nullable: true
        transitions:
          type: integer
      required:
        - avg_days_in_stage
        - key
        - label
        - transitions
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'Enter your JWT token in the format: Bearer <token>'

````