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

# Get Bordereau Export Run

> Reports the status of a **bordereau export run** started by
**`POST /policies/bordereau/export-runs`**.

Poll this until `status` is terminal, then fetch the file from
**`GET .../export-runs/{runId}/download`** if it succeeded — or deliver it
to Google Drive via **`POST .../export-runs/{runId}/drive`**.

### Statuses

- **`queued`** — the run exists and is waiting for a worker. A normal state
  every run passes through, **not** a stall: the run is recorded before the
  background work is dispatched.
- **`running`** — the export is streaming rows into its CSV.
- **`succeeded`** — the file is parked and downloadable. `rowCount` and
  `finishedAt` are set.
- **`failed`** — the export stopped early. `error` carries the reason; start
  a new run to retry.
- **`expired`** — the run succeeded, but its CSV has passed the retention
  horizon (`expiresAt`) and been deleted. The run's facts (`rowCount`,
  timestamps) remain readable; start a new export for a fresh file.

The body is **fixed-size** — the export request is not echoed back — so a
poll costs the same however large the export is.

A run's status stays readable for as long as the run exists: nothing removes
a run on a timer (only its FILE expires), and a run id belonging to another
company — or to an entity export run rather than a bordereau one — is a
`404`, exactly as an id that exists nowhere.

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




## OpenAPI

````yaml /openapi/generated-external-api.yaml get /api/v1/companies/{companyId}/policies/bordereau/export-runs/{runId}
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://go.aiinsurance.io
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/v1/companies/{companyId}/policies/bordereau/export-runs/{runId}:
    get:
      tags:
        - Field Model Bordereau
      summary: Get Bordereau Export Run
      description: >
        Reports the status of a **bordereau export run** started by

        **`POST /policies/bordereau/export-runs`**.


        Poll this until `status` is terminal, then fetch the file from

        **`GET .../export-runs/{runId}/download`** if it succeeded — or deliver
        it

        to Google Drive via **`POST .../export-runs/{runId}/drive`**.


        ### Statuses


        - **`queued`** — the run exists and is waiting for a worker. A normal
        state
          every run passes through, **not** a stall: the run is recorded before the
          background work is dispatched.
        - **`running`** — the export is streaming rows into its CSV.

        - **`succeeded`** — the file is parked and downloadable. `rowCount` and
          `finishedAt` are set.
        - **`failed`** — the export stopped early. `error` carries the reason;
        start
          a new run to retry.
        - **`expired`** — the run succeeded, but its CSV has passed the
        retention
          horizon (`expiresAt`) and been deleted. The run's facts (`rowCount`,
          timestamps) remain readable; start a new export for a fresh file.

        The body is **fixed-size** — the export request is not echoed back — so
        a

        poll costs the same however large the export is.


        A run's status stays readable for as long as the run exists: nothing
        removes

        a run on a timer (only its FILE expires), and a run id belonging to
        another

        company — or to an entity export run rather than a bordereau one — is a

        `404`, exactly as an id that exists nowhere.


        **Required permission:** `company.policy:read`
      operationId: getBordereauExportRun
      parameters:
        - $ref: '#/components/parameters/companyId'
        - name: runId
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: >
            The run identifier returned by **`POST

            /policies/bordereau/export-runs`**. Runs are scoped to their company
            AND

            their kind: a run id belonging to another company, or to an entity

            export run rather than a bordereau one, returns `404`, exactly as an
            id

            that exists nowhere does.
      responses:
        '200':
          description: The run's current status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExportRunResponse'
              examples:
                queued:
                  summary: Started, not yet claimed by a worker
                  value:
                    runId: 7c9e6679-7425-40de-944b-e07fc1f90ae7
                    status: queued
                    rowCount: null
                    error: null
                    createdAt: '2026-08-18T12:00:00.000Z'
                    updatedAt: '2026-08-18T12:00:00.000Z'
                    finishedAt: null
                    expiresAt: '2026-09-17T12:00:00.000Z'
                succeeded:
                  summary: The CSV is parked and downloadable
                  value:
                    runId: 7c9e6679-7425-40de-944b-e07fc1f90ae7
                    status: succeeded
                    rowCount: 12840
                    error: null
                    createdAt: '2026-08-18T12:00:00.000Z'
                    updatedAt: '2026-08-18T12:03:41.000Z'
                    finishedAt: '2026-08-18T12:03:41.000Z'
                    expiresAt: '2026-09-17T12:00:00.000Z'
                expired:
                  summary: The run succeeded but its CSV passed the retention horizon
                  value:
                    runId: 7c9e6679-7425-40de-944b-e07fc1f90ae7
                    status: expired
                    rowCount: 12840
                    error: null
                    createdAt: '2026-07-01T12:00:00.000Z'
                    updatedAt: '2026-08-01T03:00:00.000Z'
                    finishedAt: '2026-07-01T12:03:41.000Z'
                    expiresAt: '2026-07-31T12:00:00.000Z'
        '400':
          description: >
            Bad Request - the run id path parameter is missing or is not a UUID.
            A

            well-formed id that belongs to no bordereau run of this company is a

            `404`, not a `400`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalidRunId:
                  summary: Missing or malformed run id
                  value:
                    error:
                      code: INVALID_RUN_ID
                      message: A run id path parameter is required, and must be a UUID.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: |
            Not Found — no bordereau export run with this id exists for this
            company. A run id belonging to a different company, or to an entity
            export run, is reported the same way, so this response never reveals
            whether an id exists elsewhere.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                notFound:
                  summary: Unknown run id for this company's bordereau exports
                  value:
                    error:
                      code: NotFound
                      message: >-
                        Export run 7c9e6679-7425-40de-944b-e07fc1f90ae7 not
                        found.
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - BearerAuth: []
        - ApiKeyAuth: []
components:
  parameters:
    companyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Company identifier
  schemas:
    ExportRunResponse:
      type: object
      description: >
        An export run's current status. Fixed size: there is no echo of the
        export

        request, so a poll costs the same however large the export is.
      required:
        - runId
        - status
        - rowCount
        - error
        - createdAt
        - updatedAt
        - finishedAt
        - expiresAt
      properties:
        runId:
          type: string
          format: uuid
          description: The run identifier
        status:
          type: string
          enum:
            - queued
            - running
            - succeeded
            - failed
            - expired
          description: >-
            `queued` while the run waits for a worker (a normal state, not a
            stall), `running` while it projects and streams, then the terminal
            `succeeded` or `failed` — and `expired` once a succeeded run's CSV
            has passed its retention horizon and been deleted
        rowCount:
          type: integer
          nullable: true
          description: >-
            Data rows written to the CSV (the header row not counted); null
            until the run succeeds. It stays populated on an `expired` run,
            describing the file that existed.
        error:
          type: string
          nullable: true
          description: Why the export stopped; null unless status is `failed`
        createdAt:
          type: string
          format: date-time
          description: When the run was started
        updatedAt:
          type: string
          format: date-time
          description: When the run last made progress or changed status
        finishedAt:
          type: string
          format: date-time
          nullable: true
          description: When the run reached a terminal status; null until then
        expiresAt:
          type: string
          format: date-time
          description: >-
            When the run's CSV artifact passes its retention horizon. After this
            instant the run reports `expired` and the download answers `404` —
            start a new export for a fresh file.
    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'
            userMessages:
              type: array
              description: >-
                Clean, verbatim-displayable messages — one entry per failure,
                free of error-code tags, field paths, and internal noise.
                Suitable for showing to end users as-is.
              items:
                type: string
              example:
                - Exposures of type 'company' require an address
            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
  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: AuthenticationError
                  message: API key authentication required
                  userMessages:
                    - API key authentication required
            invalidApiKey:
              summary: >-
                Invalid API key (e.g. unknown key, or a Bearer token used
                instead of an API key)
              value:
                error:
                  code: AuthenticationError
                  message: Invalid API key
                  userMessages:
                    - Invalid API key
    Forbidden:
      description: Forbidden - Insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            insufficientPermissions:
              summary: Insufficient permissions
              value:
                error:
                  code: AuthorizationError
                  message: User is not authorized to perform the requested action
                  userMessages:
                    - User is not authorized to perform the requested action
            companyMismatch:
              summary: A valid API key naming another company in the URL
              value:
                error:
                  code: AuthorizationError
                  message: API key is not scoped to the requested company
                  userMessages:
                    - API key is not scoped to the requested company
    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: UncaughtActionError
                  message: Uncaught error occurred in <actionName>
                  userMessages:
                    - An unexpected error occurred. Please try again later.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Send your raw API key as the `Authorization`
        header value with NO scheme prefix — `Authorization: YOUR-API-KEY`. Do
        NOT prefix it with `Bearer ` or `ApiKey `, and do not use an `X-API-Key`
        header; those are not accepted.
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        User-principal OAuth 2.0 Bearer authentication. Send a user-scoped Auth0
        access token (audience = the app API audience) as `Authorization: Bearer
        <jwt>`. The request resolves to the user's identity and is authorized by
        their Role on the `{companyId}` in the path — the same role-based
        permissions the web app enforces. This is the path the MCP connector
        uses to act on a user's behalf; endpoints that accept it list both
        `BearerAuth` and `ApiKeyAuth`.

````