openapi: 3.1.0
info:
  title: PDF Accessibility API
  version: "1.0.0"
  description: |
    Check and fix PDF accessibility. Checking is free; fixing uses one page credit per page.
    API access is included from the Business plan. Authenticate with `X-Api-Key: pdfa_live_...`.
servers:
  - url: https://pdfaccessibility.org
security:
  - ApiKey: []
components:
  securitySchemes:
    ApiKey: { type: apiKey, in: header, name: X-Api-Key }
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code: { type: string, examples: [insufficient_credits, plan_required, not_found, rate_limited, unauthorized, not_ready] }
            message: { type: string }
            data: { type: object }
    Issue:
      type: object
      properties:
        id: { type: string, examples: [not_tagged] }
        category: { type: string, enum: [structure, reading_order, images, tables, forms, navigation, metadata, text, contrast] }
        severity: { type: string, enum: [critical, serious, moderate, minor] }
        title: { type: string }
        what: { type: string }
        who: { type: string }
        clauses: { type: array, items: { type: string } }
        pages: { type: array, items: { type: integer } }
        count: { type: integer }
        autofix: { type: string, enum: [yes, partly, no] }
        human_review: { type: boolean }
    CheckResult:
      type: object
      properties:
        score: { type: integer, minimum: 0, maximum: 100 }
        grade: { type: string, enum: [pass, fair, fail] }
        categories: { type: object, additionalProperties: { type: object, properties: { label: { type: string }, score: { type: integer }, weight: { type: integer }, issues: { type: integer } } } }
        issues: { type: array, items: { $ref: "#/components/schemas/Issue" } }
        passed: { type: array, items: { type: string } }
        human_review: { type: array, items: { type: object } }
        summary: { type: object }
        preview: { type: array, items: { type: object, properties: { page: { type: integer }, role: { type: string }, text: { type: string } } } }
        preview_mode: { type: string, enum: [tags, content] }
    Document:
      type: object
      properties:
        id: { type: string, examples: [d_abc123def456] }
        filename: { type: string }
        pages: { type: integer }
        status: { type: string, enum: [checking, checked, fixing, fixed, failed] }
        error: { type: string }
        score_before: { type: [integer, "null"] }
        score_after: { type: [integer, "null"] }
        pages_charged: { type: integer }
        created_at: { type: string, format: date-time }
        expires_at: { type: string, format: date-time }
        check: { $ref: "#/components/schemas/CheckResult" }
        fix:
          type: object
          properties:
            before: { $ref: "#/components/schemas/CheckResult" }
            after: { $ref: "#/components/schemas/CheckResult" }
            review: { type: array, items: { type: object } }
            counters: { type: object }
            ocr_pages: { type: array, items: { type: integer } }
            font_substitutions: { type: array, items: { type: object } }
        links:
          type: object
          properties:
            fixed_pdf: { type: string, format: uri }
            report_pdf: { type: string, format: uri }
            report_json: { type: string, format: uri }
paths:
  /v1/check:
    post:
      summary: Upload or fetch a PDF and check it (free)
      parameters:
        - { name: fix, in: query, schema: { type: boolean }, description: Fix automatically after the check }
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema: { type: object, properties: { file: { type: string, format: binary } }, required: [file] }
          application/json:
            schema: { type: object, properties: { url: { type: string, format: uri } }, required: [url] }
      responses:
        "202": { description: Accepted, content: { application/json: { schema: { $ref: "#/components/schemas/Document" } } } }
        "400": { description: Not a PDF / bad URL, content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "413": { description: Too large }
  /v1/fix:
    post:
      summary: Fix a checked document (uses page credits)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [document_id]
              properties:
                document_id: { type: string }
                lang: { type: string, examples: [en-US] }
                title: { type: string }
                ai: { type: boolean, description: false = AI off (no data sent to an AI provider) }
                ocr: { type: boolean }
                suffix: { type: string, description: 'Suffix for the download file name, default "-accessible", "none" for none' }
      responses:
        "202": { description: Fix queued, content: { application/json: { schema: { $ref: "#/components/schemas/Document" } } } }
        "402": { description: Not enough credits (data contains a quote), content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
        "409": { description: Not ready or already fixed }
  /v1/documents/{id}:
    parameters: [{ name: id, in: path, required: true, schema: { type: string } }]
    get:
      summary: Document status and results
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Document" } } } }
    delete:
      summary: Delete the document and its files now
      responses: { "204": { description: Deleted } }
  /v1/documents/{id}/{file}:
    get:
      summary: Download a file
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
        - { name: file, in: path, required: true, schema: { type: string, enum: [fixed.pdf, original.pdf, report.pdf, report.json] } }
      responses:
        "200": { description: File }
        "410": { description: Deleted under the retention setting }
  /v1/scans:
    post:
      summary: Scan a website for PDFs
      requestBody:
        required: true
        content: { application/json: { schema: { type: object, properties: { url: { type: string } }, required: [url] } } }
      responses: { "202": { description: Scan queued } }
  /v1/scans/{id}:
    get:
      summary: Scan progress and PDF inventory
      parameters: [{ name: id, in: path, required: true, schema: { type: string } }]
      responses: { "200": { description: OK } }
  /v1/account:
    get:
      summary: Plan and page credits
      responses: { "200": { description: OK } }
webhooks:
  documentEvent:
    post:
      summary: "document.checked, document.fixed, document.failed, scan.completed"
      description: Signed with header X-PDFA-Signature t=<unix>,v1=<hex HMAC-SHA256 of "t.body" with your webhook secret>.
      requestBody:
        content:
          application/json:
            schema: { type: object, properties: { id: { type: string }, type: { type: string }, created: { type: integer }, data: { $ref: "#/components/schemas/Document" } } }
      responses: { "200": { description: Acknowledge } }
