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

# List Earned Premium (Multi-Policy)

> Returns earned premium for multiple policies, paginated by policy. Each
item in the response has the same shape as the single-policy endpoint
for the requested detail level.

Use `segmentScope` to control which policies are included based on
segment date matching:
- `"all"` — every policy
- `{"asOf":"YYYY-MM-DD"}` — policies with segments active on that date
- `{"fromDate":"YYYY-MM-DD","toDate":"YYYY-MM-DD"}` — policies with
  segments overlapping the date range

Use `filters` to narrow results by field values in policy data.

The earned premium date range is a half-open interval `[startDate, endDate)`
and must not exceed 366 days.

**Required permission:** `company.policy:read`




## OpenAPI

````yaml /openapi/generated-external-api.yaml get /api/v1/external/companies/{companyId}/policies/list/earned-premium
openapi: 3.0.3
info:
  title: AI Insurance External API
  description: External API for AI Insurance platform
  version: 1.0.0
  contact:
    email: support@aiinsurance.io
servers:
  - url: https://app.aiinsurance.io
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/v1/external/companies/{companyId}/policies/list/earned-premium:
    get:
      tags:
        - Field Model Earned Premium
      summary: List Earned Premium (Multi-Policy)
      description: >
        Returns earned premium for multiple policies, paginated by policy. Each

        item in the response has the same shape as the single-policy endpoint

        for the requested detail level.


        Use `segmentScope` to control which policies are included based on

        segment date matching:

        - `"all"` — every policy

        - `{"asOf":"YYYY-MM-DD"}` — policies with segments active on that date

        - `{"fromDate":"YYYY-MM-DD","toDate":"YYYY-MM-DD"}` — policies with
          segments overlapping the date range

        Use `filters` to narrow results by field values in policy data.


        The earned premium date range is a half-open interval `[startDate,
        endDate)`

        and must not exceed 366 days.


        **Required permission:** `company.policy:read`
      operationId: listEarnedPremium
      parameters:
        - $ref: '#/components/parameters/companyId'
        - name: startDate
          in: query
          required: true
          schema:
            type: string
            format: date
          description: |
            Start of the earned premium window (inclusive). ISO 8601 date
            (`YYYY-MM-DD`). Must be before or equal to `endDate`.
        - name: endDate
          in: query
          required: true
          schema:
            type: string
            format: date
          description: |
            End of the earned premium window (exclusive). ISO 8601 date
            (`YYYY-MM-DD`). The range `[startDate, endDate)` must not exceed
            366 days.
        - name: detail
          in: query
          schema:
            type: string
            enum:
              - transactions
              - days
              - daysAndTransactions
            default: transactions
          description: |
            Response granularity per policy:
            - `transactions` — `transactionTotals` only (default)
            - `days` — adds `days` array with net earned premium per day
            - `daysAndTransactions` — adds `days` array with per-transaction
              `contributions` on each day
        - name: segmentScope
          in: query
          required: true
          schema:
            type: string
          description: |
            JSON-encoded segment scope filter. Controls which policies are
            included based on segment date matching. Values:
            - `"all"` — every policy
            - `{"asOf":"YYYY-MM-DD"}` — point-in-time
            - `{"fromDate":"YYYY-MM-DD","toDate":"YYYY-MM-DD"}` — date range
          examples:
            all:
              summary: All policies
              value: '"all"'
            asOf:
              summary: Point-in-time
              value: '{"asOf":"2025-06-15"}'
            range:
              summary: Date range
              value: '{"fromDate":"2025-01-01","toDate":"2025-06-30"}'
        - name: filters
          in: query
          schema:
            type: string
          description: >
            JSON-encoded array of field filters. Each filter targets a field in

            the segment's `fieldModelV1Data` and supports type-specific
            operators

            (text, number, boolean, date, currency, optionSet, address).
          examples:
            textFilter:
              summary: Text field filter
              value: >-
                [{"fieldReferenceId":"policyNumber","fieldType":"text","operator":"equals","value":"POL-001"}]
            numberFilter:
              summary: Number field filter
              value: >-
                [{"fieldReferenceId":"annualPremium","fieldType":"number","operator":"greaterThan","value":50000}]
        - name: timeTravelBackToDate
          in: query
          schema:
            type: string
            format: date-time
          description: |
            Only include transactions created before this timestamp (ISO 8601).
            Useful for auditing historical earned premium state.
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
          description: |
            Maximum number of policies to return per page (default 50, max 200).
        - name: offset
          in: query
          schema:
            type: integer
            minimum: 0
            default: 0
          description: |
            Number of policies to skip (0-based, default 0).
      responses:
        '200':
          description: Paginated list of per-policy earned premium
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EarnedPremiumListResponse'
              examples:
                transactionsDetail:
                  summary: Default detail level (transactions)
                  value:
                    items:
                      - policyId: 550e8400-e29b-41d4-a716-446655440001
                        policyNumber: POL-2025-001
                        earnedPremiumTotal: 42465.75
                        transactionTotals:
                          - transactionId: 660e8400-e29b-41d4-a716-446655440001
                            policyVersion: 1
                            action: NEW_BUSINESS
                            totalContribution: 42465.75
                      - policyId: 550e8400-e29b-41d4-a716-446655440002
                        policyNumber: POL-2025-002
                        earnedPremiumTotal: 28000
                        transactionTotals:
                          - transactionId: 660e8400-e29b-41d4-a716-446655440010
                            policyVersion: 1
                            action: NEW_BUSINESS
                            totalContribution: 25000
                          - transactionId: 660e8400-e29b-41d4-a716-446655440011
                            policyVersion: 2
                            action: ENDORSE
                            totalContribution: 3000
                    pagination:
                      offset: 0
                      limit: 50
                      total: 2
                withDays:
                  summary: Daily time series
                  value:
                    items:
                      - policyId: 550e8400-e29b-41d4-a716-446655440001
                        policyNumber: POL-2025-001
                        earnedPremiumTotal: 465.76
                        transactionTotals:
                          - transactionId: 660e8400-e29b-41d4-a716-446655440001
                            policyVersion: 1
                            action: NEW_BUSINESS
                            totalContribution: 465.76
                        days:
                          - date: '2025-01-01'
                            earnedPremium: 232.88
                          - date: '2025-01-02'
                            earnedPremium: 232.88
                    pagination:
                      offset: 0
                      limit: 50
                      total: 1
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                missingDates:
                  summary: Missing required date parameters
                  value:
                    error:
                      code: INVALID_REQUEST
                      message: startDate and endDate must be valid ISO dates
                dateRangeTooLarge:
                  summary: Date range exceeds 366 days
                  value:
                    error:
                      code: INVALID_REQUEST
                      message: Date range must not exceed 366 days
                limitExceeded:
                  summary: Limit exceeds maximum
                  value:
                    error:
                      code: INVALID_REQUEST
                      message: limit must not exceed 200
                invalidSegmentScope:
                  summary: Invalid JSON in segmentScope
                  value:
                    error:
                      code: INVALID_REQUEST
                      message: segmentScope must be valid JSON
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    companyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Company identifier
  schemas:
    EarnedPremiumListResponse:
      type: object
      description: Paginated list of per-policy earned premium results.
      required:
        - items
        - pagination
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/EarnedPremiumPolicyResponse'
        pagination:
          type: object
          required:
            - offset
            - limit
            - total
          properties:
            offset:
              type: integer
              description: Number of policies skipped (0-based)
            limit:
              type: integer
              description: Maximum number of policies returned per page
            total:
              type: integer
              description: Total number of matching policies across all pages
    ErrorResponse:
      type: object
      description: Standard error response for all external API endpoints
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Machine-readable error code
              example: VALIDATION_ERROR
            message:
              type: string
              description: Human-readable error message
              example: 'submissionId: Required field is missing'
            details:
              type: array
              description: Additional details for validation errors (field-level errors)
              items:
                type: object
                properties:
                  field:
                    type: string
                    description: The field that caused the error
                    example: submissionId
                  message:
                    type: string
                    description: Description of the field error
                    example: Required field is missing
    EarnedPremiumPolicyResponse:
      type: object
      description: >
        Earned premium for a single policy over the requested date range. Shape
        varies by detail level: - `transactions` — `transactionTotals` only
        (default) - `days` — adds `days` array (without per-transaction
        contributions) - `daysAndTransactions` — adds `days` array with
        `contributions` per day
      required:
        - policyId
        - policyNumber
        - earnedPremiumTotal
        - transactionTotals
      properties:
        policyId:
          type: string
          format: uuid
          description: The policy ID
        policyNumber:
          type: string
          description: Human-readable policy number
        earnedPremiumTotal:
          type: number
          description: >
            Total earned premium across all transactions for the requested date
            range
        transactionTotals:
          type: array
          description: >
            Each transaction's total earned premium contribution over the
            requested date range. Always present.
          items:
            $ref: '#/components/schemas/EarnedPremiumTransactionRangeTotal'
        days:
          type: array
          description: >
            Daily earned premium time series. Only present when `detail=days` or
            `detail=daysAndTransactions`. Contains one entry per day in the
            half-open interval [startDate, endDate).
          items:
            $ref: '#/components/schemas/EarnedPremiumOneDayTotal'
    EarnedPremiumTransactionRangeTotal:
      type: object
      description: >
        One transaction's total earned premium contribution over the requested
        date range. Present at every detail level.
      required:
        - transactionId
        - policyVersion
        - action
        - totalContribution
      properties:
        transactionId:
          type: string
          format: uuid
          description: The transaction that produced this contribution
        policyVersion:
          type: integer
          description: Policy version number at the time of this transaction
        action:
          type: string
          enum:
            - NEW_BUSINESS
            - ENDORSE
            - CANCEL
            - REINSTATE
            - RENEW
          description: The transaction action type
        totalContribution:
          type: number
          description: >
            Net earned premium contributed by this transaction over the
            requested date range. Positive for
            NEW_BUSINESS/ENDORSE/REINSTATE/RENEW, negative for CANCEL.
    EarnedPremiumOneDayTotal:
      type: object
      description: >
        Net earned premium on a single day. Present when `detail=days` or
        `detail=daysAndTransactions`.
      required:
        - date
        - earnedPremium
      properties:
        date:
          type: string
          format: date
          description: The calendar date (YYYY-MM-DD)
        earnedPremium:
          type: number
          description: >
            Net earned premium on this day — the sum of all active transaction
            contributions whose effective range includes this date.
        contributions:
          type: array
          description: >
            Per-transaction breakdown of daily contributions. Only present when
            `detail=daysAndTransactions`.
          items:
            $ref: '#/components/schemas/EarnedPremiumTransactionOneDayContribution'
    EarnedPremiumTransactionOneDayContribution:
      type: object
      description: >
        One transaction's earned premium contribution on a single day. Present
        when `detail=daysAndTransactions`.
      required:
        - transactionId
        - policyVersion
        - action
        - dailyContribution
      properties:
        transactionId:
          type: string
          format: uuid
          description: The transaction that produced this contribution
        policyVersion:
          type: integer
          description: Policy version number at the time of this transaction
        action:
          type: string
          enum:
            - NEW_BUSINESS
            - ENDORSE
            - CANCEL
            - REINSTATE
            - RENEW
          description: The transaction action type
        dailyContribution:
          type: number
          description: >
            This transaction's daily earned premium rate. The transaction
            spreads its premium change evenly across its effective date range.
  responses:
    Unauthorized:
      description: Unauthorized - Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingApiKey:
              summary: Missing API key
              value:
                error:
                  code: UNAUTHORIZED
                  message: Authorization header is required
            bearerTokenNotAllowed:
              summary: Bearer token used instead of API key
              value:
                error:
                  code: UNAUTHORIZED
                  message: External API endpoints require API key authentication
    Forbidden:
      description: Forbidden - Insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            insufficientPermissions:
              summary: Insufficient permissions
              value:
                error:
                  code: FORBIDDEN
                  message: Insufficient permissions to perform this action
    InternalServerError:
      description: Internal Server Error - Unexpected error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internalError:
              summary: Unexpected server error
              value:
                error:
                  code: INTERNAL_ERROR
                  message: An unexpected error occurred. Please try again later.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Include your API key in the Authorization
        header.

````