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

# Get Audit Run History Route

> Last N run snapshots for a brand + non-SEO audit type, newest first.

Reads the append-only ``brand_audit_runs`` history (Audits R12) — the
``BrandAudit`` snapshot is clobbered per re-run by design — so the report
UI can diff a re-run against the previous one and plot a score trend
instead of showing a single replaced result.

SEO is deliberately NOT served here: it has its own richer Phase-2 history
at ``/free-audits/seo-history/{brand_id}``, and answering for it from this
(never-written) table would report "no history" for the one audit that has
the most.

Gated on ``AUDIT_LONGITUDINAL_ENABLED`` (404 when off — the table is not
being written) + brand ownership, like the sibling SEO history route.



## OpenAPI

````yaml /openapi.json get /api/v1/free-audits/run-history/{brand_id}
openapi: 3.1.0
info:
  title: AITasker
  version: 0.1.0
servers: []
security: []
paths:
  /api/v1/free-audits/run-history/{brand_id}:
    get:
      tags:
        - Free Audits
        - Free Audits
      summary: Get Audit Run History Route
      description: >-
        Last N run snapshots for a brand + non-SEO audit type, newest first.


        Reads the append-only ``brand_audit_runs`` history (Audits R12) — the

        ``BrandAudit`` snapshot is clobbered per re-run by design — so the
        report

        UI can diff a re-run against the previous one and plot a score trend

        instead of showing a single replaced result.


        SEO is deliberately NOT served here: it has its own richer Phase-2
        history

        at ``/free-audits/seo-history/{brand_id}``, and answering for it from
        this

        (never-written) table would report "no history" for the one audit that
        has

        the most.


        Gated on ``AUDIT_LONGITUDINAL_ENABLED`` (404 when off — the table is not

        being written) + brand ownership, like the sibling SEO history route.
      operationId: >-
        get_audit_run_history_route_api_v1_free_audits_run_history__brand_id__get
      parameters:
        - name: brand_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Brand Id
        - name: audit_type
          in: query
          required: true
          schema:
            type: string
            maxLength: 50
            title: Audit Type
        - name: platform
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                maxLength: 50
              - type: 'null'
            title: Platform
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            maximum: 20
            minimum: 1
            default: 8
            title: Limit
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuditRunHistoryResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    AuditRunHistoryResponse:
      properties:
        brand_id:
          type: string
          format: uuid
          title: Brand Id
        audit_type:
          type: string
          title: Audit Type
        runs:
          items:
            $ref: '#/components/schemas/AuditRunHistoryRun'
          type: array
          title: Runs
      type: object
      required:
        - brand_id
        - audit_type
      title: AuditRunHistoryResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    AuditRunHistoryRun:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        audit_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Audit Id
        created_at:
          type: string
          format: date-time
          title: Created At
        overall_score:
          anyOf:
            - type: number
            - type: 'null'
          title: Overall Score
        grade:
          anyOf:
            - type: string
            - type: 'null'
          title: Grade
        scoring_version:
          anyOf:
            - type: string
            - type: 'null'
          title: Scoring Version
        category_scores:
          additionalProperties:
            type: number
          type: object
          title: Category Scores
        unmeasured_dimensions:
          items:
            type: string
          type: array
          title: Unmeasured Dimensions
        finding_count:
          type: integer
          title: Finding Count
          default: 0
        critical_count:
          type: integer
          title: Critical Count
          default: 0
        findings_complete:
          type: boolean
          title: Findings Complete
          default: false
        findings:
          items:
            $ref: '#/components/schemas/AuditRunHistoryFinding'
          type: array
          title: Findings
      type: object
      required:
        - id
        - created_at
      title: AuditRunHistoryRun
      description: >-
        One immutable ``BrandAuditRun`` serialised for trend/delta consumers.


        ``category_scores`` omits any dimension the run could not measure —
        those

        are named in ``unmeasured_dimensions`` instead. Absence therefore means

        "not measured", never a score of zero, and a consumer must not render it

        as a regression. ``findings_complete`` defaults fail-closed and becomes

        true only when the stored count matches the valid serialized findings;

        against an incomplete run the resolved/new set-diff must be suppressed

        rather than reporting dropped findings as fixed. See

        ``services/audit_run_history.py``.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    AuditRunHistoryFinding:
      properties:
        code:
          type: string
          title: Code
        title:
          anyOf:
            - type: string
            - type: 'null'
          title: Title
        category:
          anyOf:
            - type: string
            - type: 'null'
          title: Category
        severity:
          type: string
          title: Severity
        impact:
          anyOf:
            - $ref: '#/components/schemas/AuditImpact'
            - type: 'null'
      type: object
      required:
        - code
        - severity
      title: AuditRunHistoryFinding
      description: One finding in a historical run snapshot — identity is ``code``.
    AuditImpact:
      properties:
        value:
          type: number
          exclusiveMinimum: 0
          title: Value
        unit:
          type: string
          enum:
            - milliseconds
            - monthly_organic_visits
          title: Unit
      additionalProperties: false
      type: object
      required:
        - value
        - unit
      title: AuditImpact
      description: A positive, finite quantity attached to one audit finding.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````