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

# Record a Coverage batch

> Validates and records a versioned payer Coverage batch. Requires `coverages:write`.



## OpenAPI

````yaml /openapi/heyrafiki.openapi.yaml post /coverage_batches
openapi: 3.1.0
info:
  title: Heyrafiki API
  version: 1.0.0
  description: Build Care, Cover and Payment workflows on Heyrafiki.
  contact:
    name: Heyrafiki
    url: https://heyrafiki.space
    email: developers@heyrafiki.space
  license:
    name: All rights reserved
    identifier: LicenseRef-Heyrafiki-Proprietary
servers:
  - url: https://api.heyrafiki.space/v1
security:
  - bearerAuth: []
  - apiKeyAuth: []
paths:
  /coverage_batches:
    post:
      summary: Record a Coverage batch
      description: >-
        Validates and records a versioned payer Coverage batch. Requires
        `coverages:write`.
      operationId: recordCoverageBatch
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
        - $ref: '#/components/parameters/CoverageBatchArtifactReference'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CoverageBatchInput'
      responses:
        '200':
          description: A replayed Coverage batch result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CoverageBatchResult'
        '201':
          description: A recorded Coverage batch result
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CoverageBatchResult'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: A caller-owned key for safely retrying one write.
      schema:
        type: string
        minLength: 8
        maxLength: 255
    CoverageBatchArtifactReference:
      name: X-Heyrafiki-Artifact-Reference
      in: header
      required: true
      description: Stable reference for the source artifact retained by the payer.
      schema:
        type: string
        minLength: 1
        maxLength: 190
        pattern: ^[A-Za-z0-9][A-Za-z0-9:._/-]*$
  schemas:
    CoverageBatchInput:
      type: object
      additionalProperties: false
      required:
        - contract_version
        - batch_reference
        - batch_version
        - source_contract_reference
        - generated_at
        - records
      properties:
        contract_version:
          type: string
          const: '2026-08-01'
        batch_reference:
          type: string
          minLength: 1
          maxLength: 220
          pattern: ^[A-Za-z0-9][A-Za-z0-9:._/-]*$
        batch_version:
          type: string
          minLength: 1
          maxLength: 120
        source_contract_reference:
          type: string
          minLength: 1
          maxLength: 220
          pattern: ^[A-Za-z0-9][A-Za-z0-9:._/-]*$
        generated_at:
          type: string
          format: date-time
        records:
          type: array
          minItems: 1
          maxItems: 500
          items:
            $ref: '#/components/schemas/CoverageBatchRecordInput'
    CoverageBatchResult:
      type: object
      additionalProperties: false
      required:
        - object
        - batch_reference
        - artifact_sha256
        - total
        - recorded
        - replayed
        - observations
      properties:
        object:
          type: string
          const: coverage_batch_result
        batch_reference:
          type: string
        artifact_sha256:
          type: string
          pattern: ^[a-f0-9]{64}$
        total:
          type: integer
          minimum: 1
          maximum: 500
        recorded:
          type: integer
          minimum: 0
          maximum: 500
        replayed:
          type: integer
          minimum: 0
          maximum: 500
        observations:
          type: array
          minItems: 1
          maxItems: 500
          items:
            $ref: '#/components/schemas/CoverageObservation'
    CoverageBatchRecordInput:
      type: object
      additionalProperties: false
      required:
        - coverage_reference
        - record_version
        - tenant_reference
        - member_reference
        - plan_name
        - service_code
        - status
        - currency
        - amount_limit
        - remaining_sessions
        - authorization_required
        - coordination_priority
        - valid_from
        - valid_until
      properties:
        coverage_reference:
          type: string
          minLength: 1
          maxLength: 220
          pattern: ^[A-Za-z0-9][A-Za-z0-9:._/-]*$
        record_version:
          type: string
          minLength: 1
          maxLength: 120
        tenant_reference:
          type: string
          minLength: 1
          maxLength: 220
          pattern: ^[A-Za-z0-9][A-Za-z0-9:._/-]*$
        member_reference:
          type: string
          minLength: 1
          maxLength: 220
          pattern: ^[A-Za-z0-9][A-Za-z0-9:._/-]*$
          description: >-
            An opaque payer reference. Do not send a name, contact detail or
            government identifier.
        plan_name:
          type: string
          minLength: 1
          maxLength: 160
        service_code:
          type: string
          minLength: 1
          maxLength: 220
          pattern: ^[A-Za-z0-9][A-Za-z0-9:._/-]*$
        status:
          type: string
          enum:
            - active
            - paused
            - exhausted
            - expired
        currency:
          type: string
          enum:
            - KES
            - USD
            - EUR
            - GBP
        amount_limit:
          type: integer
          minimum: 1
          maximum: 9007199254740991
          description: Per-Session limit in the currency's minor unit.
        remaining_sessions:
          type: integer
          minimum: 0
          maximum: 100000
        authorization_required:
          type: boolean
        coordination_priority:
          type:
            - integer
            - 'null'
          minimum: 1
          maximum: 100
        valid_from:
          type: string
          format: date-time
        valid_until:
          type: string
          format: date-time
    CoverageObservation:
      type: object
      additionalProperties: false
      required:
        - id
        - object
        - coverage_id
        - source
        - source_contract_reference
        - external_coverage_reference
        - source_version
        - snapshot_version
        - status
        - service_code
        - amount_limit
        - remaining_sessions
        - authorization_required
        - coordination_priority
        - valid_from
        - valid_until
        - observed_at
      properties:
        id:
          type: string
          pattern: ^cobs_[A-Za-z0-9_-]+$
        object:
          type: string
          const: coverage_observation
        coverage_id:
          type: string
          pattern: ^cov_[A-Za-z0-9_-]+$
        source:
          type: string
          enum:
            - payer_api
            - batch_file
        source_contract_reference:
          type: string
        external_coverage_reference:
          type: string
        source_version:
          type: string
        snapshot_version:
          type: integer
          minimum: 1
        status:
          type: string
          enum:
            - active
            - paused
            - exhausted
            - expired
        service_code:
          type: string
        amount_limit:
          type: object
          additionalProperties: false
          required:
            - currency
            - value
          properties:
            currency:
              type: string
              enum:
                - KES
                - USD
                - EUR
                - GBP
            value:
              type: integer
              minimum: 1
        remaining_sessions:
          type: integer
          minimum: 0
        authorization_required:
          type: boolean
        coordination_priority:
          type:
            - integer
            - 'null'
          minimum: 1
        valid_from:
          type: string
          format: date-time
        valid_until:
          type: string
          format: date-time
        observed_at:
          type: string
          format: date-time
    ErrorEnvelope:
      type: object
      additionalProperties: false
      required:
        - error
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - code
            - message
            - docs
          properties:
            code:
              type: string
            message:
              type: string
            docs:
              type: string
              format: uri
  headers:
    RateLimitLimit:
      description: Maximum requests allowed in the current minute.
      schema:
        type: integer
    RateLimitRemaining:
      description: Requests remaining in the current minute.
      schema:
        type: integer
    RateLimitReset:
      description: Unix timestamp when the current limit resets.
      schema:
        type: integer
  responses:
    BadRequest:
      description: The request failed validation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Unauthorized:
      description: The API key is missing or invalid.
      headers:
        WWW-Authenticate:
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Forbidden:
      description: The API key does not permit this operation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Conflict:
      description: The request conflicts with current state.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    PayloadTooLarge:
      description: The request body exceeds the endpoint limit.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    TooManyRequests:
      description: The project exceeded its request limit.
      headers:
        Retry-After:
          description: Seconds until another request should be attempted.
          schema:
            type: integer
        X-RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/RateLimitRemaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/RateLimitReset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    ServiceUnavailable:
      description: The service is temporarily unavailable.
      headers:
        Retry-After:
          schema:
            type: integer
            example: 5
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A sandbox or production secret key.
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: An alternative for clients that cannot set Authorization.

````