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

# Get an agent's key metrics

> The agent's key metrics — the outcomes its owner chose to count — with the count for the period, the average or total for measured metrics, the same figures for the period of equal length before, and optionally the most recent records. Definitions live on the agent (`keyMetrics` on GET /agents/:agentId). The period is the last `days` days (default 30) or a fixed `startDate`–`endDate`.



## OpenAPI

````yaml /api-reference/workspace-api.json get /workspaceapi/agents/{agentId}/key-metrics
openapi: 3.1.0
info:
  title: Abundly Workspace API
  description: >-
    Workspace-level and per-agent data and administration. GET endpoints need a
    workspace API key (wk_) with the Workspace read API scope; POST endpoints
    need the Workspace write API scope. The write endpoints are batch operations
    mirroring the Workspace Manager capability: ids travel in the JSON body,
    each id gets its own result, and per-id failures still return HTTP 200.


    Private agents are listed by /workspaceapi/agents but return 403 on every
    per-agent GET, so enumerate from /workspaceapi/agents?includeOverview=true
    rather than iterating agent ids. Write endpoints can target private agents.
  version: 1.0.0
servers:
  - url: https://service.abundly.ai
    description: Shared platform
  - url: https://{tenant}.service.abundly.ai
    description: Dedicated deployment
    variables:
      tenant:
        default: your-tenant
security:
  - workspaceApiKey: []
paths:
  /workspaceapi/agents/{agentId}/key-metrics:
    get:
      summary: Get an agent's key metrics
      description: >-
        The agent's key metrics — the outcomes its owner chose to count — with
        the count for the period, the average or total for measured metrics, the
        same figures for the period of equal length before, and optionally the
        most recent records. Definitions live on the agent (`keyMetrics` on GET
        /agents/:agentId). The period is the last `days` days (default 30) or a
        fixed `startDate`–`endDate`.
      operationId: agents-agentId-key-metrics
      parameters:
        - name: agentId
          in: path
          required: true
          description: The agent id.
          schema:
            type: string
        - name: days
          in: query
          required: false
          description: >-
            Lookback in days ending at endDate. Default 30. Ignored when
            startDate is given.
          schema:
            type: integer
            minimum: 1
            maximum: 365
        - name: startDate
          in: query
          required: false
          description: ISO timestamp for a fixed period instead of a lookback.
          schema:
            type: string
        - name: endDate
          in: query
          required: false
          description: ISO timestamp. Default now.
          schema:
            type: string
        - name: recentLimit
          in: query
          required: false
          description: >-
            Recent records to include per metric (ref, note, value, when).
            Default 0.
          schema:
            type: integer
            minimum: 0
            maximum: 500
      responses:
        '200':
          description: Success. Empty result sets are also 200.
          content:
            application/json:
              schema:
                description: >-
                  Key metrics for one agent over a period, in the agent's
                  definition order.
                type: object
                properties:
                  agentId:
                    type: string
                  agentName:
                    type: string
                  period:
                    type: object
                    properties:
                      startDate:
                        type: string
                      endDate:
                        type: string
                    required:
                      - startDate
                      - endDate
                    additionalProperties: false
                  metrics:
                    type: array
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                        description:
                          type: string
                        measurement:
                          type: object
                          properties:
                            unit:
                              type: string
                            aggregation:
                              type: string
                              enum:
                                - average
                                - total
                          required:
                            - unit
                            - aggregation
                          additionalProperties: false
                        count:
                          description: Records in the period.
                          type: number
                        totalCount:
                          description: All records ever, regardless of the period.
                          type: number
                        lastRecordedAt:
                          description: Newest record ever, regardless of the period.
                          type: string
                        valueCount:
                          description: >-
                            Records that carried a value; the denominator of an
                            average.
                          type: number
                        aggregate:
                          description: >-
                            Average or total per `measurement.aggregation`;
                            measured metrics with at least one value only.
                          type: number
                        previousCount:
                          description: >-
                            Records in the period of equal length immediately
                            before this one.
                          type: number
                        previousAggregate:
                          description: The same aggregate over that previous period.
                          type: number
                        recent:
                          type: array
                          items:
                            type: object
                            properties:
                              id:
                                type: string
                              value:
                                type: number
                              ref:
                                type: string
                              note:
                                type: string
                              occurredAt:
                                type: string
                            required:
                              - id
                              - occurredAt
                            additionalProperties: false
                      required:
                        - name
                        - count
                        - totalCount
                        - valueCount
                        - previousCount
                        - recent
                      additionalProperties: false
                required:
                  - agentId
                  - agentName
                  - period
                  - metrics
                additionalProperties: false
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/Error'
        '403':
          $ref: '#/components/responses/Error'
        '404':
          $ref: '#/components/responses/Error'
components:
  responses:
    Error:
      description: >-
        Error. Every failure on this API returns JSON with a single `error`
        field.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                description: >-
                  Human-readable message. Every error on this API uses this
                  shape.
                type: string
            required:
              - error
            additionalProperties: false
  securitySchemes:
    workspaceApiKey:
      type: http
      scheme: bearer
      description: >-
        Workspace API key (wk_). GET endpoints require the Workspace read API
        scope, POST endpoints the Workspace write API scope.

````