openapi: 3.0.3
info:
  title: Luthor Public API
  version: v1
  description: |
    Public REST API for Marketing reviews, Disclosures, MCP, and Audit packages.

    Account administrators manage public API keys in Settings > API Keys. Create
    multiple named keys with selected permissions and an expiration of 30, 90,
    or 365 days. The secret is shown only once when created; copy it then, as it
    cannot be retrieved later. Revoke a key from Settings to stop its access.

    Settings permissions map to these stable API scopes:

    | Permission | API scopes |
    | --- | --- |
    | Create marketing reviews | `reviews:submit` |
    | View marketing reviews | `reviews:read` |
    | View findings | `findings:read` |
    | Upload revisions | `reviews:revise` |
    | Fact-check claims | `claims:fact_check` |
    | Submit for review | `human_review:request` |
    | Export audit packages | `audit_packets:export` |
    | View disclosures | `disclosures:read`, `approved_language:read` |
    | View workflow settings and rulesets | `policies:read` |
    | Manage webhooks | `webhooks:manage` |
    | Use MCP server | `mcp:use` |

    Keys created in Settings have account-wide workspace access and automatically
    include `workspaces:read`; there is no workspace picker. Permissions still
    control the actions the key can perform. Use MCP server also requires the
    relevant action permissions for the tools and resources being called.
    View disclosures grants both scopes for the Disclosures library: disclosure
    records and their approved text. The `approved-language` API name refers to
    that same library, not a separate feature.

    Manage webhooks registers, lists, and deactivates endpoints. Registered
    review.human_approved subscriptions deliver final human approvals, with signed
    requests and transient-failure retries. Other accepted event names are reserved
    and do not currently deliver. Receipt also requires reviews:read. See the
    [webhook guide](/api-docs/index.html#webhooks) for the verification contract.
    The legacy POST /api/v1/submissions endpoint separately supports webhook_url
    for signed submission.completed callbacks with retries for transient failures.

    Use a public API key for REST and MCP integrations. Personal Microsoft Word
    and PowerPoint tokens are separate credentials: they are accepted only by
    the Office endpoints, GET /api/v1/me, and the documented owner-scoped legacy
    submission reads. Other public API endpoints return 403 for Office tokens.

    Legacy submission endpoints enforce the same scopes and workspace allowlists:
    list/show require reviews:read; claims, violations, and summaries require
    findings:read. Restricted keys cannot see submissions outside their allowed
    workspaces, including unassigned submissions. Existing keys with empty scopes
    retain their legacy unrestricted-scope behavior.
    Review envelopes returned by REST endpoints and MCP resources/tools omit the
    findings array unless the credential also grants findings:read.

    Pagination on GET /api/v1/submissions and its claims/violations list endpoints
    uses page (default 1) and per_page (default 20, range 1–100). The items query
    parameter and pagination.items response field are deprecated aliases retained
    for compatibility, with no scheduled removal date. Conflicting aliases or
    invalid values return 422 (invalid_pagination); unavailable pages return 404
    (page_out_of_range). Empty collections have one valid page with count 0.
    These parameters do not apply to MCP tools or other REST endpoints.
    See [pagination guidance](/api-docs/index.html#pagination) and the
    [API changelog](/api-docs/changelog.html) for examples and release status.

    Typical integration flow:
    1. Submit draft marketing content for AI-assisted pre-review.
    2. Poll the review until processing completes.
    3. Read findings and approved text from the Disclosures library.
    4. Upload revisions until findings are resolved or ready for review.
    5. Submit for review and export an audit package as JSON.

    Luthor API and MCP pre-review responses do not create final compliance
    approval. Final approval requires an authorized human reviewer inside Luthor.
servers:
  - url: /
security:
  - ApiTokenAuth: []
tags:
  - name: Marketing reviews
  - name: Findings
  - name: Audit packages
  - name: Workspaces
  - name: Disclosures
  - name: Workflow settings and rulesets
  - name: Content
  - name: MCP
  - name: Webhooks
  - name: Microsoft Office
paths:
  /api/v1/me:
    get:
      tags: [Microsoft Office]
      summary: Identify the authenticated connection
      description: Accepts public API keys and personal Office tokens. Office tokens identify their Word or PowerPoint integration.
      responses:
        "200":
          description: User, account, and credential identity returned.
          content:
            application/json:
              schema:
                type: object
                required: [user, account, credential]
                properties:
                  user:
                    type: object
                    additionalProperties: true
                  account:
                    type: object
                    additionalProperties: true
                  credential:
                    type: object
                    properties:
                      integration:
                        type: string
                        nullable: true
                        enum: [word, powerpoint, null]
                      expires_at:
                        type: string
                        format: date-time
                        nullable: true
        "401":
          $ref: "#/components/responses/Unauthorized"

  /api/v1/reviews:
    post:
      tags: [Marketing reviews]
      summary: Create marketing review
      description: |
        Requires `reviews:submit`. Creates a marketing review for AI-assisted analysis.
        This endpoint never creates final human approval.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ReviewRequest"
      responses:
        "201":
          description: Marketing review created.
          content:
            application/json:
              schema:
                type: object
                required: [review]
                properties:
                  review:
                    $ref: "#/components/schemas/Review"
                  warnings:
                    type: array
                    items:
                      type: string
                    description: Present when deprecated request identifiers such as client_id were used.
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/UnprocessableEntity"

  /api/v1/reviews/{review_id}:
    get:
      tags: [Marketing reviews]
      summary: View marketing review
      description: Requires `reviews:read`. Findings are included only with `findings:read`.
      parameters:
        - $ref: "#/components/parameters/ReviewId"
      responses:
        "200":
          description: Marketing review returned.
          content:
            application/json:
              schema:
                type: object
                required: [review]
                properties:
                  review:
                    $ref: "#/components/schemas/Review"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/reviews/{review_id}/findings:
    get:
      tags: [Findings]
      summary: List open findings
      description: Requires `findings:read`.
      parameters:
        - $ref: "#/components/parameters/ReviewId"
      responses:
        "200":
          description: Findings returned.
          content:
            application/json:
              schema:
                type: object
                required: [findings]
                properties:
                  findings:
                    type: array
                    items:
                      $ref: "#/components/schemas/Finding"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/reviews/{review_id}/versions:
    post:
      tags: [Marketing reviews]
      summary: Upload revision
      description: Requires `reviews:revise`. Uploads a new text revision to an existing marketing review.
      parameters:
        - $ref: "#/components/parameters/ReviewId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [content]
              properties:
                content:
                  type: object
                  required: [type, value]
                  properties:
                    type:
                      type: string
                      enum: [text]
                    value:
                      type: string
                note:
                  type: string
                unreviewed_findings_action:
                  type: string
                  enum: [compare, discard]
      responses:
        "201":
          description: Revision created.
          content:
            application/json:
              schema:
                type: object
                required: [review]
                properties:
                  review:
                    $ref: "#/components/schemas/Review"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/UnprocessableEntity"

  /api/v1/reviews/{review_id}/request-human-review:
    post:
      tags: [Marketing reviews]
      summary: Submit for review
      description: Requires `human_review:request`. Sends analyzed marketing content into the reviewer approval workflow. Does not approve content.
      parameters:
        - $ref: "#/components/parameters/ReviewId"
      responses:
        "200":
          description: Marketing review submitted for review.
          content:
            application/json:
              schema:
                type: object
                required: [review]
                properties:
                  review:
                    $ref: "#/components/schemas/Review"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/reviews/{review_id}/versions/{revision_id}/file:
    get:
      tags: [Marketing reviews]
      summary: Download a revision file
      description: |
        Requires reviews:read on a public API key and enforces account, workspace,
        visibility, and review/revision ownership boundaries. Office tokens are rejected.
        Any accessible revision is eligible, regardless of approval or processing status,
        when the requested stored file exists. Original is the default; no approval gate
        or file conversion is performed. For text/URL imports, original means the stored
        source file generated at import, if present.

        Returns a 302 redirect to a five-minute bearer download URL. Follow the redirect
        without forwarding the API key to the storage host. The storage response supplies
        the file bytes, Content-Type, and attachment Content-Disposition with the filename.
        The redirect is private and non-cacheable; keep its URL out of logs and history.

        X-Luthor-File-SHA256 hashes the actual selected file bytes. Revision content_hash
        hashes extracted text and is not a file checksum. The first download verifies the
        storage checksum and computes SHA-256 through a temporary file; the digest is then
        cached against the immutable blob identity. Metadata serialization never downloads
        content just to compute a hash. An approved PDF is a generated artifact, not proof
        of approval of the current revision; inspect the review approval object separately.
      parameters:
        - $ref: "#/components/parameters/ReviewId"
        - in: path
          name: revision_id
          required: true
          schema:
            type: string
            format: uuid
        - in: query
          name: variant
          schema:
            type: string
            enum: [original, pdf, approved]
            default: original
          description: Original stored file, available viewable PDF, or generated approved PDF. An unavailable representation never falls back to a different representation.
        - in: query
          name: artifact_id
          schema:
            type: string
            format: uuid
          description: Optional exact ready approved artifact, only valid with variant=approved. Without it, selects the latest available ready artifact for this revision by approval time, then ID descending. No artifact is generated by this request.
      responses:
        "302":
          description: Redirect to the selected file, available for five minutes.
          headers:
            Location:
              schema:
                type: string
                format: uri
              description: Short-lived bearer download URL.
            X-Luthor-Revision-ID:
              schema:
                type: string
                format: uuid
            X-Luthor-File-Variant:
              schema:
                type: string
                enum: [original, pdf, approved]
            X-Luthor-Approval-Artifact-ID:
              schema:
                type: string
                format: uuid
              description: Present only for approved artifact downloads; identifies the exact selected artifact.
            X-Luthor-File-SHA256:
              schema:
                type: string
                pattern: "^[0-9a-f]{64}$"
            X-Luthor-File-Byte-Size:
              schema:
                type: integer
                minimum: 0
            X-Luthor-Download-Expires-At:
              schema:
                type: string
                format: date-time
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: Review/revision inaccessible, or selected file unavailable (not_found or file_not_available).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "422":
          description: Invalid variant or artifact selection (invalid_file_selection).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "429":
          $ref: "#/components/responses/TooManyRequests"
        "502":
          description: Stored checksum validation failed (file_integrity_failed). No URL is issued.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"

        "503":
          description: Required download audit records could not be committed (download_audit_unavailable). No URL is issued; retry later.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"

  /api/v1/reviews/{review_id}/audit-packet:
    get:
      tags: [Audit packages]
      summary: Export audit package
      description: |
        Requires `audit_packets:export`. Exports findings, revisions, and decision
        history as JSON in the `audit_packet` response property. This API export
        is distinct from the report ZIP download available in Luthor.
        Decision history preserves original immutable event rows and adds decision_scope,
        revision_id, and revision_id_source. Older approved events may describe reviewer
        votes rather than final approval; missing revision references remain explicitly
        unknown and are never inferred from the current revision.
      parameters:
        - $ref: "#/components/parameters/ReviewId"
      responses:
        "200":
          description: Audit package returned as JSON.
          content:
            application/json:
              schema:
                type: object
                required: [audit_packet]
                properties:
                  audit_packet:
                    type: object
                    additionalProperties: true
                    properties:
                      review:
                        $ref: "#/components/schemas/Review"
                      versions:
                        type: array
                        items:
                          $ref: "#/components/schemas/ReviewVersion"
                      decision_history:
                        type: array
                        items:
                          type: object
                          additionalProperties: true
                          properties:
                            event_type:
                              type: string
                              description: reviewer_approved is an individual vote; approved is a final approval in new events. Older approved rows may be votes; inspect decision_scope.
                            decision_scope:
                              type: string
                              nullable: true
                              enum: [reviewer, stage, submission, unknown]
                            revision_id:
                              type: string
                              format: uuid
                              nullable: true
                              description: Revision recorded by the event; null when missing or conflicting. Original metadata and hashes remain unchanged.
                            revision_id_source:
                              type: string
                              enum: [metadata, audit_object, reviewable, unknown]
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/clients:
    get:
      tags: [Workspaces]
      summary: List authorized workspaces
      description: Requires `workspaces:read`. The legacy clients path and response property remain for API compatibility.
      responses:
        "200":
          description: Workspaces returned.
          content:
            application/json:
              schema:
                type: object
                required: [clients]
                properties:
                  clients:
                    type: array
                    items:
                      $ref: "#/components/schemas/Client"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"

  /api/v1/clients/{client_id}/policies:
    get:
      tags: [Workflow settings and rulesets]
      summary: View workflow settings and rulesets
      description: Requires `policies:read`. Returns the workspace's configured workflow settings and compliance ruleset information.
      parameters:
        - $ref: "#/components/parameters/ClientId"
      responses:
        "200":
          description: Workflow settings and ruleset information returned.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/clients/{client_id}/disclosures:
    get:
      tags: [Disclosures]
      summary: View workspace disclosures
      description: Requires `disclosures:read`. Returns disclosure records visible to the workspace from the Disclosures library.
      parameters:
        - $ref: "#/components/parameters/ClientId"
      responses:
        "200":
          description: Disclosures returned.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/clients/{client_id}/approved-language:
    get:
      tags: [Disclosures]
      summary: View approved disclosure text
      description: |
        Requires `approved_language:read`. Returns approved text from the same
        Disclosures library. Selecting View disclosures in Settings grants both
        `disclosures:read` and `approved_language:read`. The approved-language
        path and response identifiers remain for API compatibility.
      parameters:
        - $ref: "#/components/parameters/ClientId"
      responses:
        "200":
          description: Approved disclosure text returned.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/content/extract:
    post:
      tags: [Content]
      summary: Normalize submitted content
      responses:
        "200":
          description: Content metadata returned.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true

  /api/v1/content/review-url:
    post:
      tags: [Content]
      summary: Create marketing review from a URL
      responses:
        "201":
          description: Marketing review created.
          content:
            application/json:
              schema:
                type: object
                required: [review]
                properties:
                  review:
                    $ref: "#/components/schemas/Review"

  /api/v1/content/review-batch:
    post:
      tags: [Content]
      summary: Create marketing reviews in a batch
      responses:
        "207":
          description: Per-item results returned.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true

  /api/v1/webhooks:
    get:
      tags: [Webhooks]
      summary: List registered webhook endpoints
      description: Requires webhooks:manage. Lists account endpoints within the key's workspace scope, including deactivated endpoints. Signing secrets are never returned here.
      responses:
        "200":
          description: Registered endpoints.
          content:
            application/json:
              schema:
                type: object
                required: [webhooks]
                properties:
                  webhooks:
                    type: array
                    items:
                      $ref: "#/components/schemas/WebhookEndpoint"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "429":
          $ref: "#/components/responses/TooManyRequests"
    post:
      tags: [Webhooks]
      summary: Register a webhook endpoint
      description: |
        Requires webhooks:manage; delivery also requires reviews:read on the
        registering key. Restricted keys must specify an accessible workspace_id.
        Account-wide keys may omit it. URLs require HTTPS on port 443, without
        credentials or fragments, and public resolved destinations at delivery.
        Redirects are not followed. Only review.human_approved currently delivers;
        other supported names are reserved. Subscriptions affect future approvals
        only. Final human approvals are included; reviewer votes, intermediate stage
        approvals, and automated approvals are excluded.

        signing_secret is returned once and stored encrypted. For each delivery,
        X-Luthor-Signature is sha256= followed by lowercase hexadecimal HMAC-SHA256
        of X-Luthor-Timestamp + "." + the exact raw HTTP body, keyed by the literal
        signing_secret. Timestamp is Unix seconds and refreshed per attempt. Verify
        using constant-time comparison and a five-minute clock tolerance.
        X-Luthor-Event is review.human_approved. X-Luthor-Delivery-Id is a stable
        UUID per endpoint/event. The body is identical across retries.

        Delivery is at least once without ordering guarantees. Return 2xx quickly
        after durable receiver enqueue, and deduplicate by delivery/event ID. Five
        attempts total, with delays of 60 seconds, 5 minutes, 30 minutes, and 2 hours;
        scheduling may run later. Retry 408, 425, 429, 5xx, and connection/DNS/TLS/
        timeout failures. Other 3xx/4xx are permanent failures. Pending deliveries
        are recovered every five minutes. Endpoint, key, creator, scope, workspace,
        and review access are rechecked before each attempt.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WebhookRegistration"
      responses:
        "201":
          description: Endpoint registered; save the signing secret now.
          content:
            application/json:
              schema:
                type: object
                required: [webhook]
                properties:
                  webhook:
                    allOf:
                      - $ref: "#/components/schemas/WebhookEndpoint"
                      - type: object
                        required: [signing_secret]
                        properties:
                          signing_secret:
                            type: string
                            description: Literal HMAC key; returned only at registration.
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "422":
          $ref: "#/components/responses/UnprocessableEntity"
        "429":
          $ref: "#/components/responses/TooManyRequests"
      callbacks:
        humanApproval:
          '{$request.body#/url}':
            post:
              security: []
              summary: Final human approval delivery
              description: Verify the timestamped endpoint-secret HMAC before accepting this request. No API key is sent to the receiver.
              parameters:
                - in: header
                  name: X-Luthor-Event
                  required: true
                  schema:
                    type: string
                    enum: [review.human_approved]
                - in: header
                  name: X-Luthor-Delivery-Id
                  required: true
                  schema:
                    type: string
                    format: uuid
                - in: header
                  name: X-Luthor-Timestamp
                  required: true
                  schema:
                    type: string
                    pattern: '^[0-9]+$'
                - in: header
                  name: X-Luthor-Signature
                  required: true
                  schema:
                    type: string
                    pattern: '^sha256=[0-9a-f]{64}$'
              requestBody:
                required: true
                content:
                  application/json:
                    schema:
                      $ref: "#/components/schemas/HumanApprovalWebhook"
              responses:
                "200":
                  description: Receiver durably accepted the event. Any 2xx succeeds.
  /api/v1/webhooks/{webhook_id}:
    delete:
      tags: [Webhooks]
      summary: Deactivate a registered endpoint
      description: Requires webhooks:manage. Endpoint must be in the account and within the key's workspace scope. Stops future delivery attempts.
      parameters:
        - in: path
          name: webhook_id
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "204":
          description: Endpoint deactivated.
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "429":
          $ref: "#/components/responses/TooManyRequests"
  /api/v1/mcp:
    post:
      tags: [MCP]
      summary: Luthor MCP JSON-RPC endpoint
      description: |
        Hosted MCP endpoint for tools, resources, and prompts. Requires
        `mcp:use` scope for all non-initialize methods. Browser requests with an
        `Origin` header must come from a trusted Luthor origin or a configured
        `MCP_ALLOWED_ORIGINS` value; non-browser MCP clients usually omit
        `Origin`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
      responses:
        "200":
          description: |
            JSON-RPC response. Every entry returned by `tools/list` carries a
            `title` and MCP `annotations` (`readOnlyHint`, `destructiveHint`,
            `idempotentHint`, `openWorldHint`).
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "202":
          description: |
            Accepted JSON-RPC notification (a message without an `id` member).
            The notification is processed but no JSON-RPC response is returned.
        "401":
          description: |
            Missing, expired or revoked credential. The response carries
            `WWW-Authenticate: Bearer resource_metadata="<base>/.well-known/oauth-protected-resource/api/v1/mcp", scope="..."`
            so OAuth clients (Claude, ChatGPT) can start sign-in. When a credential
            was presented and refused, the challenge also carries
            `error="invalid_token"` (or `error="invalid_request"` for a header that
            is neither `Bearer` nor `Token`) and an `error_description`, per
            RFC 6750 §3.1. Accepts either an API key or an OAuth access token
            from `POST /oauth/token`.
    get:
      tags: [MCP]
      summary: Not supported (405)
      security: []
      description: |
        The MCP server is request/response only and does not open a
        server-to-client notification stream. Streamable HTTP clients that
        probe `GET` receive `405` with `Allow: POST` and fall back to `POST`.
        No credential is needed.
      responses:
        "405":
          description: "Method not allowed. `Allow: POST`."
    delete:
      tags: [MCP]
      summary: Not supported (405)
      security: []
      description: |
        Sessions are stateless, so there is nothing to terminate. Returns `405`
        with `Allow: POST`. No credential is needed.
      responses:
        "405":
          description: "Method not allowed. `Allow: POST`."

  /api/v1/submissions:
    get:
      tags: [Marketing reviews]
      summary: List marketing reviews (legacy)
      description: Returns paginated submissions within the key's workspace allowlist. Requires reviews:read on a public API key; Office tokens are rejected. Results are ordered by creation time descending, then ID descending. Results can shift between page requests when records change.
      parameters:
        - in: query
          name: review_status
          required: false
          schema:
            type: string
            enum: [processing, draft, open, approved]
          description: Optional filter by review status.
        - in: query
          name: updated_since
          required: false
          schema:
            type: string
            format: date-time
          description: Inclusive filter on submission updated_at (greater than or equal to this timestamp). Supply a valid ISO 8601 timestamp with seconds and an explicit timezone, e.g. 2026-10-02T12:00:00.123456Z. Blank or malformed values return 422 invalid_filter. Can be combined with review_status and pagination.
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PerPage"
        - $ref: "#/components/parameters/DeprecatedItems"
      responses:
        "200":
          description: Submissions returned.
          content:
            application/json:
              schema:
                type: object
                required: [submissions, pagination]
                properties:
                  submissions:
                    type: array
                    items:
                      $ref: "#/components/schemas/SubmissionSummary"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: Requested page exceeds the available pages (page_out_of_range).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "422":
          description: Invalid pagination parameters (invalid_pagination) or invalid updated_since timestamp (invalid_filter).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "429":
          $ref: "#/components/responses/TooManyRequests"
    post:
      tags: [Marketing reviews]
      summary: Create marketing review (legacy)
      description: |
        Creates a submission from a file upload and enqueues pipeline processing.
        Requires a public API key. Office add-ins create private analyses through
        POST /api/v1/office/analysis_sessions instead.
        Requires reviews:submit. Keys restricted to specific workspaces must use
        POST /api/v1/reviews with a workspace identifier; this legacy endpoint
        does not assign a workspace and returns 403 for those keys.
      requestBody:
        required: true
        description: |
          Provide either `file` (binary upload) or `text` (plain text string).
          If both are present, `text` takes precedence.
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                  description: Document file to analyze.
                text:
                  type: string
                  description: Plain text to analyze (alternative to file upload).
                title:
                  type: string
                  description: Title for the submission (used with `text`).
      responses:
        "201":
          description: Submission created.
          content:
            application/json:
              schema:
                type: object
                required: [submission]
                properties:
                  submission:
                    $ref: "#/components/schemas/SubmissionSummary"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "422":
          $ref: "#/components/responses/UnprocessableEntity"
        "429":
          $ref: "#/components/responses/TooManyRequests"

  /api/v1/submissions/{id}:
    get:
      tags: [Marketing reviews]
      summary: View marketing review (legacy)
      description: |
        Polling endpoint for submission state and aggregate counts.
        Requires reviews:read and respects the key's workspace allowlist.
        Office tokens may read only their creator's submissions from the matching
        Office host. Promoted analyses must belong to the same session creator
        and integration. For older submissions without Office session provenance,
        only the creator's matching Word or PowerPoint document type is readable.
        Other submissions return 404 for Office tokens.
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
            format: uuid
          description: Submission id.
      responses:
        "200":
          description: Submission returned.
          content:
            application/json:
              schema:
                type: object
                required: [submission]
                properties:
                  submission:
                    $ref: "#/components/schemas/SubmissionDetail"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "429":
          $ref: "#/components/responses/TooManyRequests"

  /api/v1/submissions/{id}/risk_summary:
    get:
      tags: [Marketing reviews]
      summary: View marketing review risk summary (legacy)
      description: Requires findings:read and respects workspace restrictions. Office tokens have the same owner and matching-host restrictions as GET /api/v1/submissions/{id}.
      parameters:
        - $ref: "#/components/parameters/SubmissionId"
      responses:
        "200":
          description: Risk summary and finding previews returned, or available false while pending.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/submissions/{id}/compliance_summary:
    get:
      tags: [Marketing reviews]
      summary: View marketing review compliance summary (legacy)
      description: Requires findings:read and respects workspace restrictions. Office tokens have the same owner and matching-host restrictions as GET /api/v1/submissions/{id}.
      parameters:
        - $ref: "#/components/parameters/SubmissionId"
      responses:
        "200":
          description: Compliance summary returned, or summary null while pending.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/submissions/{submission_id}/violations:
    get:
      tags: [Findings]
      summary: List violation findings (legacy)
      description: Returns paginated violations for the submission's current revision. Requires findings:read on a public API key and respects its workspace allowlist. Office tokens are rejected. Results are ordered by creation time ascending, then ID ascending. Results can shift between page requests when records change.
      parameters:
        - in: path
          name: submission_id
          required: true
          schema:
            type: string
            format: uuid
          description: Submission id.
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PerPage"
        - $ref: "#/components/parameters/DeprecatedItems"
      responses:
        "200":
          description: Violations returned.
          content:
            application/json:
              schema:
                type: object
                required: [violations, pagination]
                properties:
                  violations:
                    type: array
                    items:
                      $ref: "#/components/schemas/Violation"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: Submission not found or requested page exceeds the available pages (page_out_of_range).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "422":
          description: Invalid page, per_page, or items value, or conflicting aliases (invalid_pagination).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "429":
          $ref: "#/components/responses/TooManyRequests"

  /api/v1/submissions/{submission_id}/claims:
    get:
      tags: [Findings]
      summary: List claim findings (legacy)
      description: Returns paginated claims for the submission's current revision. Requires findings:read on a public API key and respects its workspace allowlist. Office tokens are rejected. Results are ordered by creation time ascending, then ID ascending. Results can shift between page requests when records change.
      parameters:
        - in: path
          name: submission_id
          required: true
          schema:
            type: string
            format: uuid
          description: Submission id.
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PerPage"
        - $ref: "#/components/parameters/DeprecatedItems"
      responses:
        "200":
          description: Claims returned.
          content:
            application/json:
              schema:
                type: object
                required: [claims, pagination]
                properties:
                  claims:
                    type: array
                    items:
                      $ref: "#/components/schemas/Claim"
                  pagination:
                    $ref: "#/components/schemas/Pagination"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: Submission not found or requested page exceeds the available pages (page_out_of_range).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "406":
          $ref: "#/components/responses/NotAcceptable"
        "422":
          description: Invalid page, per_page, or items value, or conflicting aliases (invalid_pagination).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorEnvelope"
        "429":
          $ref: "#/components/responses/TooManyRequests"

  /api/v1/office/configuration:
    get:
      tags: [Microsoft Office]
      summary: Get Office analysis configuration
      description: |
        Returns the active workflows available to the authenticated PowerPoint
        or Word add-in user. Requires an Office add-in token with
        `reviews:submit`.
      responses:
        "200":
          description: Office analysis configuration returned.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OfficeConfiguration"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"

  /api/v1/office/analysis_sessions:
    post:
      tags: [Microsoft Office]
      summary: Start private Office analysis
      description: |
        Creates an owner-scoped private analysis. It does not appear in normal
        submission lists, review queues, dashboards, reports, or customer
        Submission API responses.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [file]
              properties:
                file:
                  type: string
                  format: binary
                title:
                  type: string
                workflow_id:
                  type: string
                  format: uuid
                  description: Required when multiple active workflows are available.
      responses:
        "201":
          description: Private Office analysis created.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OfficeAnalysisSessionEnvelope"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "422":
          $ref: "#/components/responses/UnprocessableEntity"

  /api/v1/office/analysis_sessions/{id}:
    get:
      tags: [Microsoft Office]
      summary: Get private Office analysis
      description: Returns only an analysis owned by the authenticated add-in user.
      parameters:
        - $ref: "#/components/parameters/OfficeAnalysisSessionId"
      responses:
        "200":
          description: Office analysis returned.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OfficeAnalysisSessionEnvelope"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/office/analysis_sessions/{id}/risk_summary:
    get:
      tags: [Microsoft Office]
      summary: Get Office analysis risk summary
      parameters:
        - $ref: "#/components/parameters/OfficeAnalysisSessionId"
      responses:
        "200":
          description: Risk summary and finding previews returned.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/office/analysis_sessions/{id}/compliance_summary:
    get:
      tags: [Microsoft Office]
      summary: Get Office analysis compliance summary
      parameters:
        - $ref: "#/components/parameters/OfficeAnalysisSessionId"
      responses:
        "200":
          description: Compliance summary returned.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"

  /api/v1/office/analysis_sessions/{id}/review:
    post:
      tags: [Microsoft Office]
      summary: Accept an Office analysis finding or suggestion
      description: |
        Persists the decision against the same canonical finding records used
        by Luthor's in-app Risk Review panel.
      parameters:
        - $ref: "#/components/parameters/OfficeAnalysisSessionId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [finding_id, item_type]
              properties:
                finding_id:
                  type: string
                  format: uuid
                item_type:
                  type: string
                  enum: [violation, claim]
                suggestion_id:
                  type: string
                  format: uuid
                  nullable: true
      responses:
        "200":
          description: Decision persisted and refreshed risk summary returned.
          content:
            application/json:
              schema:
                type: object
                required: [success, risk_summary]
                properties:
                  success:
                    type: boolean
                  risk_summary:
                    type: object
                    additionalProperties: true
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/UnprocessableEntity"

  /api/v1/office/analysis_sessions/{id}/promotion_file:
    put:
      tags: [Microsoft Office]
      summary: Prepare an Office analysis for submission
      description: |
        Uploads the latest Office document and returns the authenticated browser
        handoff used to complete intake and submit the existing analysis for review.
      parameters:
        - $ref: "#/components/parameters/OfficeAnalysisSessionId"
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [file]
              properties:
                file:
                  type: string
                  format: binary
      responses:
        "200":
          description: Latest document stored and browser handoff returned.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OfficeAnalysisSessionEnvelope"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          $ref: "#/components/responses/NotFound"
        "422":
          $ref: "#/components/responses/UnprocessableEntity"

components:
  securitySchemes:
    ApiTokenAuth:
      type: apiKey
      in: header
      name: Authorization
      description: |
        Two formats are accepted:
        - Bearer: `Authorization: Bearer luthor_v1_<48_hex_chars>`
        - Token: `Authorization: Token token="luthor_v1_<48_hex_chars>"`
        New personal Office credentials use `luthor_office_v1_<48_hex_chars>`.
        Existing Office credentials using the older `luthor_v1_` prefix remain
        valid on Office-authorized endpoints. Credential purpose is determined
        by the server record, not by the token prefix.

  parameters:
    Page:
      in: query
      name: page
      required: false
      schema:
        type: integer
        minimum: 1
      description: Page number (defaults to 1). Page 1 is valid for an empty collection; pages beyond the available results return 404.
    PerPage:
      in: query
      name: per_page
      required: false
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 20
      description: Maximum results per page. Defaults to 20 when neither per_page nor items is supplied.
    DeprecatedItems:
      in: query
      name: items
      required: false
      deprecated: true
      schema:
        type: integer
        minimum: 1
        maximum: 100
      description: Deprecated alias for per_page. Use per_page instead. If both are supplied, their values must match.
    SubmissionId:
      in: path
      name: id
      required: true
      schema:
        type: string
        format: uuid
      description: Luthor submission id.
    ReviewId:
      in: path
      name: review_id
      required: true
      schema:
        type: string
        format: uuid
      description: Luthor marketing review ID (also called submission ID in legacy endpoints).
    ClientId:
      in: path
      name: client_id
      required: true
      schema:
        type: string
      description: Workspace UUID or slug within the authenticated token scope. Path name remains client_id for API compatibility.
    OfficeAnalysisSessionId:
      in: path
      name: id
      required: true
      schema:
        type: string
        format: uuid
      description: Owner-scoped private Office analysis id.

  responses:
    Unauthorized:
      description: Missing, invalid, or deactivated API key.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorEnvelope"
          example:
            error:
              code: unauthorized
              message: Invalid API token
    Forbidden:
      description: Wrong credential purpose (including an Office token on a public API endpoint), missing scope, inaccessible workspace, subscription required, or plan limit reached.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorEnvelope"
          examples:
            plan_limit:
              summary: Submission limit exceeded
              value:
                error:
                  code: plan_limit
                  message: You have reached the submission limit for your plan.
            subscription_required:
              summary: Trial ended
              value:
                error:
                  code: subscription_required
                  message: Your trial has ended. Please subscribe to continue creating submissions.
            missing_scope:
              summary: Required scope missing
              value:
                error:
                  code: forbidden
                  message: "Missing required scope: reviews:submit"
    NotAcceptable:
      description: |
        `Accept` header is present but does not allow JSON. Luthor accepts a
        blank `Accept` header, `*/*`, `application/json`, and vendor JSON media
        types ending in `+json`.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorEnvelope"
          example:
            error:
              code: not_acceptable
              message: API requests must accept JSON responses.
    NotFound:
      description: Resource was not found or is outside the authenticated account scope.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorEnvelope"
          example:
            error:
              code: not_found
              message: Resource not found
    UnprocessableEntity:
      description: Validation error.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorEnvelope"
          example:
            error:
              code: invalid
              message: File is required
    TooManyRequests:
      description: Rate limit exceeded.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorEnvelope"
          example:
            error:
              code: rate_limited
              message: Rate limit exceeded. Try again later.

  schemas:
    WebhookRegistration:
      type: object
      required: [url, events]
      properties:
        url:
          type: string
          format: uri
          description: Public HTTPS destination on port 443, without credentials or fragments.
        workspace_id:
          type: string
          format: uuid
          nullable: true
          description: Required for workspace-restricted keys; omission subscribes account-wide for unrestricted keys.
        client_id:
          type: string
          format: uuid
          deprecated: true
          description: Compatibility alias for workspace_id. If both are supplied, they must agree.
        events:
          type: array
          minItems: 1
          items:
            type: string
            enum: [review.created, review.processing, review.completed, review.failed, review.finding.created, review.version.created, review.human_review_requested, review.human_approved, review.changes_required, audit_packet.created]
          description: Only review.human_approved currently delivers; other names are reserved.
          example: [review.human_approved]
        metadata:
          type: object
          additionalProperties: true
    WebhookEndpoint:
      type: object
      required: [webhook_id, workspace_id, client_id, url, events, status, secret_hint, last_delivery_at, created_at, updated_at]
      properties:
        webhook_id:
          type: string
          format: uuid
        workspace_id:
          type: string
          format: uuid
          nullable: true
        client_id:
          type: string
          format: uuid
          nullable: true
          deprecated: true
          description: Mirrors workspace_id.
        url:
          type: string
          format: uri
        events:
          type: array
          items:
            type: string
        status:
          type: string
          enum: [active, deactivated]
        secret_hint:
          type: string
          description: Last eight characters; not sufficient for verification.
        last_delivery_at:
          type: string
          format: date-time
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    HumanApprovalWebhook:
      type: object
      required: [id, type, created_at, account_id, workspace_id, client_id, data]
      properties:
        id:
          type: string
          format: uuid
          description: Immutable approval ReviewEvent ID, also present in data.event_id.
        type:
          type: string
          enum: [review.human_approved]
        created_at:
          type: string
          format: date-time
          description: Immutable event timestamp, not the delivery attempt timestamp.
        account_id:
          type: string
          format: uuid
        workspace_id:
          type: string
          format: uuid
          nullable: true
        client_id:
          type: string
          format: uuid
          nullable: true
          deprecated: true
          description: Mirrors workspace_id.
        data:
          type: object
          required: [review_id, revision_id, version_number, status, approved_at, event_id, download_url]
          properties:
            review_id:
              type: string
              format: uuid
            revision_id:
              type: string
              format: uuid
            version_number:
              type: integer
            status:
              type: string
              enum: [human_approved]
            approved_at:
              type: string
              format: date-time
              nullable: true
            event_id:
              type: string
              format: uuid
              description: Matches envelope id.
            download_url:
              type: string
              description: Relative authenticated original-file download path; not a signed storage URL or attachment availability guarantee.
    OfficeWorkflow:
      type: object
      required: [id, name]
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        description:
          type: string
          nullable: true

    OfficeConfiguration:
      type: object
      required: [integration, workflow_selection_required, workflows]
      properties:
        integration:
          type: string
          enum: [powerpoint, word]
        workflow_selection_required:
          type: boolean
        default_workflow_id:
          type: string
          format: uuid
          nullable: true
        workflows:
          type: array
          items:
            $ref: "#/components/schemas/OfficeWorkflow"

    OfficeAnalysisSession:
      type: object
      required: [id, integration, status, title, processing_status, created_at, expires_at]
      properties:
        id:
          type: string
          format: uuid
        integration:
          type: string
          enum: [powerpoint, word]
        status:
          type: string
          enum: [analyzing, ready, awaiting_intake, promotion_processing, promoted, failed, expired]
        title:
          type: string
        processing_status:
          type: string
          nullable: true
          enum: [initial, uploading, converting, chunking, analyzing, annotating, ready, failed]
        workflow:
          nullable: true
          allOf:
            - $ref: "#/components/schemas/OfficeWorkflow"
        created_at:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
        submission_id:
          type: string
          format: uuid
          description: Present after the Office analysis is promoted to a visible review.
        handoff_url:
          type: string
          format: uri
          description: Present after the latest Office document has been uploaded.

    OfficeAnalysisSessionEnvelope:
      type: object
      required: [analysis_session]
      properties:
        analysis_session:
          $ref: "#/components/schemas/OfficeAnalysisSession"

    Pagination:
      type: object
      required: [page, per_page, items, count, pages]
      properties:
        page:
          type: integer
          minimum: 1
        per_page:
          type: integer
          minimum: 1
          maximum: 100
          description: Maximum results per page.
        items:
          type: integer
          minimum: 1
          maximum: 100
          deprecated: true
          description: Deprecated alias for per_page; retained for compatibility.
        count:
          type: integer
          minimum: 0
        pages:
          type: integer
          minimum: 0

    CurrentRevision:
      type: object
      required: [id, version_number, filename, processing_status]
      properties:
        id:
          type: string
          format: uuid
        version_number:
          type: integer
        filename:
          type: string
        processing_status:
          type: string
          enum: [initial, uploading, chunking, analyzing, ready]

    SubmissionSummary:
      type: object
      required: [id, title, review_status, processing_status, created_at, updated_at, app_url]
      properties:
        id:
          type: string
          format: uuid
        title:
          type: string
        review_status:
          type: string
          enum: [processing, draft, open, approved]
        processing_status:
          type: string
          nullable: true
          enum: [initial, uploading, chunking, analyzing, ready]
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
          description: Submission modification timestamp in UTC with six fractional digits. Revision and audit activity may also advance this value; it is not an approval timestamp.
        app_url:
          type: string
          format: uri
          description: URL to view this submission in the Luthor app.

    SubmissionDetail:
      allOf:
        - $ref: "#/components/schemas/SubmissionSummary"
        - type: object
          required: [violation_count, claim_count, current_revision]
          properties:
            violation_count:
              type: integer
              minimum: 0
            claim_count:
              type: integer
              minimum: 0
            current_revision:
              nullable: true
              allOf:
                - $ref: "#/components/schemas/CurrentRevision"

    RemediationSuggestion:
      type: object
      required: [id, suggestion_text, status, suggestion_type]
      properties:
        id:
          type: string
          format: uuid
        suggestion_text:
          type: string
        status:
          type: string
        suggestion_type:
          type: string
          enum: [text_replacement, instructional]
          description: |
            Shape of this suggestion. `text_replacement` is a redline-style
            substitution for the violation text. `instructional` is a structural
            recommendation (e.g. "add a parallel net value bridge") rendered
            as guidance rather than a diff.

    Violation:
      type: object
      required:
        - id
        - text
        - explanation
        - severity
        - status
        - violation_type
        - regulation_code
        - page_number
        - pages
        - remediation_suggestions
      properties:
        id:
          type: string
          format: uuid
        text:
          type: string
        explanation:
          type: string
        severity:
          type: string
          enum: [high, medium, low]
        status:
          type: string
        violation_type:
          type: string
        regulation_code:
          type: string
          nullable: true
        page_number:
          type: integer
          nullable: true
          description: Primary page; see `pages` for multi-anchor violations.
        pages:
          type: array
          items:
            type: integer
          description: Distinct page numbers the violation references.
        remediation_suggestions:
          type: array
          items:
            $ref: "#/components/schemas/RemediationSuggestion"

    Claim:
      type: object
      required: [id, claim_text, explanation, severity, status, claim_type]
      properties:
        id:
          type: string
          format: uuid
        claim_text:
          type: string
        explanation:
          type: string
        severity:
          type: string
          enum: [high, medium, low]
        status:
          type: string
        claim_type:
          type: string

    ReviewRequest:
      type: object
      required: [asset_type, content]
      properties:
        workspace_id:
          type: string
          description: Preferred workspace UUID or slug. Required only when the API key is workspace-scoped; omit for account-level submissions.
        client_id:
          type: string
          description: Deprecated alias for workspace_id. If both are supplied, workspace_id is used and client_id is ignored.
        advisor_id:
          type: string
        asset_type:
          type: string
          description: Submitted asset type. Common values include `blog_post`, `email`, `social_post`, `website_page`, `advisor_bio`, `newsletter`, `ad`, `video_script`, `presentation`, and `landing_page`; custom values are stored as submitted.
          example: blog_post
        channel:
          type: string
          example: website
        audience:
          type: string
          example: retail_investors
        content:
          type: object
          required: [type, value]
          properties:
            type:
              type: string
              enum: [text, url]
            value:
              type: string
        campaign_id:
          type: string
        requested_review_level:
          type: string
          description: Requested workflow level. Common values include `quick_precheck`, `pre_review`, `formal_pre_review`, and `human_review`; current v1 stores the provided value as review metadata.
          example: pre_review
        metadata:
          type: object
          additionalProperties: true

    Client:
      type: object
      required: [id, slug, name, enabled]
      properties:
        id:
          type: string
          format: uuid
        slug:
          type: string
        name:
          type: string
        enabled:
          type: boolean
        website_url:
          type: string
          nullable: true
        workflow_template:
          type: string
        compliance_ruleset:
          type: string

    Review:
      type: object
      required: [review_id, status, approval, risk_level, summary, next_action, finding_counts, created_at, updated_at]
      properties:
        review_id:
          type: string
          format: uuid
        status:
          type: string
          description: API workflow state. human_approved requires recorded human approval of the current revision. approved means the submission is approved but the current revision lacks that human confirmation (automated approval, unknown provenance, or a revision mismatch).
          enum: [processing, failed, changes_required, ai_precheck_passed, human_review_requested, human_approved, approved, draft, open, changes_requested, stale, closed, archived]
        approval:
          $ref: "#/components/schemas/ApprovalStatus"
        review_status:
          type: string
        processing_status:
          type: string
          nullable: true
        risk_level:
          type: string
          enum: [critical, high, medium, low, negligible]
        summary:
          type: string
        next_action:
          type: string
          enum: [wait_for_results, revise_and_resubmit, request_human_review, wait_for_human_review, none, review_in_luthor]
        client:
          nullable: true
          allOf:
            - $ref: "#/components/schemas/Client"
        content_asset:
          type: object
          additionalProperties: true
          properties:
            current_version:
              nullable: true
              allOf:
                - $ref: "#/components/schemas/ReviewVersion"
        finding_counts:
          type: object
          additionalProperties:
            type: integer
        findings:
          type: array
          description: Present only when the caller is authorized for findings:read.
          items:
            $ref: "#/components/schemas/Finding"
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
          description: Submission modification timestamp in UTC with six fractional digits, consistent with submission list results.
        audit_packet_url:
          type: string

    ReviewVersion:
      type: object
      additionalProperties: true
      properties:
        revision_id:
          type: string
          format: uuid
        version_number:
          type: integer
        content_hash:
          type: string
          nullable: true
          description: SHA-256 of extracted clean text; not a hash of stored file bytes.
        files:
          type: array
          description: Available attached representations. A storage object may later become unavailable; download requests verify availability.
          items:
            $ref: "#/components/schemas/RevisionFile"

    RevisionFile:
      type: object
      required: [variant, artifact_id, filename, content_type, byte_size, file_sha256, download_url]
      properties:
        variant:
          type: string
          enum: [original, pdf, approved]
        artifact_id:
          type: string
          format: uuid
          nullable: true
        filename:
          type: string
        content_type:
          type: string
          description: Download content type; unsafe types may be served as application/octet-stream under storage safety rules.
        byte_size:
          type: integer
          minimum: 0
        file_sha256:
          type: string
          nullable: true
          description: SHA-256 of file bytes when already computed; null until the first download computes it. The download redirect always provides the digest header.
        download_url:
          type: string
          description: Relative authenticated API endpoint path, not a signed storage URL.

    ApprovalStatus:
      type: object
      required: [state, kind, event_id, approved_at, revision_id, revision_id_source, current_revision_approved]
      properties:
        state:
          type: string
          enum: [approved, not_approved]
          description: Current submission state; distinct from proof of human approval.
        kind:
          type: string
          nullable: true
          enum: [human, automated, unknown]
        event_id:
          type: string
          format: uuid
          nullable: true
          description: Latest non-reviewer approval event in the current approval round, if available.
        approved_at:
          type: string
          format: date-time
          nullable: true
        revision_id:
          type: string
          format: uuid
          nullable: true
          description: Recorded approved revision belonging to this review. No current-revision inference or historical backfill is performed.
        revision_id_source:
          type: string
          enum: [metadata, audit_object, reviewable, unknown]
        current_revision_approved:
          type: boolean
          nullable: true
          description: True when the recorded approved revision matches the current revision; false when not approved or mismatched; null when identity is unresolved. True alone does not establish human approval; also check kind or status.

    Finding:
      type: object
      required: [finding_id, finding_type, severity, category, issue, status]
      properties:
        finding_id:
          type: string
          format: uuid
        finding_type:
          type: string
          enum: [risk_finding, claim_verification, disclosure_suggestion]
        severity:
          type: string
        category:
          type: string
        location:
          type: object
          additionalProperties: true
        issue:
          type: string
        suggested_revision:
          type: string
          nullable: true
          description: The first proposed fix. Kept for existing clients; see suggested_revisions for every proposed fix.
        suggested_revisions:
          type: array
          description: Every proposed fix, oldest first. Claim and disclosure findings list at most one entry, matching suggested_revision.
          items:
            type: object
            required: [text]
            properties:
              suggestion_id:
                type: string
                format: uuid
                nullable: true
              suggestion_type:
                type: string
                enum: [text_replacement, instructional]
              text:
                type: string
              explanation:
                type: string
                nullable: true
        policy_reference:
          type: object
          additionalProperties: true
        status:
          type: string

    ErrorObject:
      type: object
      required: [code, message]
      properties:
        code:
          type: string
        message:
          type: string

    ErrorEnvelope:
      type: object
      required: [error]
      properties:
        error:
          $ref: "#/components/schemas/ErrorObject"
