# RiskMotor
# Public screening API — the contract customers integrate against.
#
# This file is the SOURCE OF TRUTH for the published surface. The human page at
# riskmotor.com/docs is written from it, and it is served at
# riskmotor.com/openapi.yaml so customers can generate clients and import it
# into Postman.
#
# ⚠ `type` and `code` on an error, and the field names below, are a published
# contract: changing one breaks customers silently. Prose (`message`,
# descriptions) may be reworded freely.
openapi: 3.1.0

info:
  title: RiskMotor Screening API
  version: "1.0.0"
  summary: Screen a person or company against official restriction and PEP registries.
  description: |
    RiskMotor screens names against official sanctions, trade-restriction and
    politically-exposed-person registries, and returns **potential matches for
    human review** — never a determination.

    Two ideas do the most work in every response, and conflating them is the
    most common integration mistake:

    - A **unique listing** is one designation by one authority. This is what
      `unique_listing_count` counts, and what a compliance decision is about.
    - A **source confirmation** is one official file that carries that
      designation. Treasury publishes the same SDN entry in both the SDN list
      and the Consolidated Screening List, so one listing routinely arrives
      with two confirmations. **Two confirmations are not two sanctions.**

    Likewise, `match_confidence` answers "is this the same real-world entity?"
    It is not a measure of how serious the listing is — that is `severity`.
  contact:
    name: RiskMotor
    url: https://riskmotor.com
  license:
    name: Proprietary
    url: https://riskmotor.com/terms

servers:
  - url: https://api.riskmotor.com/v1
    description: Production

security:
  - bearerApiKey: []

tags:
  - name: Screening
    description: Run a screening and read back the ones you have run.
  - name: Batches
    description: |
      Screen many subjects in one job. A batch row produces an ordinary
      screening — same engine, same metering, same audit record — so a name
      screened in a batch is indistinguishable from one screened on its own
      except for the `batch_id` recording which job produced it.
  - name: Datasets
    description: What is screened against, and how current it is.
  - name: Monitoring
    description: |
      Enrol a subject and we re-screen it daily, telling you when something
      NEW appears against it.

      ⚠ **Each check is a screening and is billed as one.** Enrolling a
      subject is a standing daily commitment, not a one-off cost — 100
      subjects is 100 screenings a day. Monitoring is therefore unavailable on
      TEST keys, and each account has a cap on how many subjects it may
      monitor at once.

      Enrolment screens immediately and returns the result. That first result
      is the baseline, which is why an existing designation never arrives as
      an alert: you were told about it when you enrolled.

      Alerts are the set difference of listing keys against the previous
      check, so a listing that disappears is not an alert, re-ordering is not
      an alert, and a subject that newly MATCHES a years-old listing is.
  - name: Adverse media
    description: |
      Optional add-on: whether the press reports anything adverse about the
      subject — negative news in the last 180 days, or a major past event —
      with evidence an auditor can open. It is a **separate, asynchronous
      job** requested beside a screening (`adverse_media: true`) or on an
      existing one, delivered in a few minutes, and **billed per delivered
      run** on top of the screening. Every finding is something a named
      publisher *reported*: never a RiskMotor conclusion, and never part of
      the screening's `overall_status` or `highest_severity`.
  - name: RTU lookups
    description: |
      Guatemala only: a taxpayer's record in SAT's Registro Tributario
      Unificado (RTU), looked up by NIT and a reference date (date of birth
      for a person, date of incorporation for a company), with SAT's own
      certificate as a PDF and its QR code.

      **Asynchronous and slow by nature.** SAT's portal is paced, so a lookup
      takes from a few minutes to some hours. The request answers `202` at once
      with a queue position; the result arrives by the
      `rtu_lookup.completed` webhook, or by polling `GET /rtu-lookups/{id}`.

      **Billed only when SAT answers** — any answer, including "NIT not
      registered" or "date does not match". A lookup SAT could not answer
      (portal down, verification failed) is retried for you and, if it still
      fails, ends `FAILED` and is not billed.

      **The document links are the permission.** Whoever holds `pdf_url` or
      `qr_url` can open the taxpayer's record. Show them only to the person
      who asked, never log them, and revoke them
      (`POST /rtu-lookups/{id}/revoke-links`) if one leaks.

      **TEST keys use a sandbox** and never reach SAT. Sandbox NITs, each with
      one outcome (any date): `10000011` SUCCESS, `10000038` NIT_NOT_FOUND,
      `10000046` DATE_MISMATCH, `10000054` NIT_INACTIVE, `10000062` — SAT
      unavailable, ends `FAILED`. Any other valid NIT answers NIT_NOT_FOUND.
  - name: Tax compliance lookups
    description: |
      Guatemala only: whether a taxpayer is up to date with SAT
      (Superintendencia de Administración Tributaria), looked up by NIT
      through SAT's Verificador Integrado — "Solvencia fiscal SAT" in the web
      app. SAT says whether the taxpayer **presents incumplimientos** and, if
      so, which: RTU data pending update, omitted returns (year, period, tax,
      form), books pending authorization, and any category SAT adds later
      (type `OTHER`, with SAT's own label and text). SAT's own report comes
      as a PDF.

      **Asynchronous and slow by nature.** SAT answers one lookup every few
      minutes for every customer together, so a lookup takes from a few
      minutes to some hours. The request answers `202` at once with a queue
      position; the result arrives by the `tax_compliance_lookup.completed`
      webhook, or by polling `GET /tax-compliance-lookups/{id}`.

      **Billed only when SAT answers** — "up to date", "presents
      incumplimientos" and "NIT not registered" alike. A lookup SAT could not
      answer (portal down, verification failed) is retried before it is
      reported and, if it still fails, ends `FAILED` and is not billed.

      **The PDF link is the permission.** Whoever holds `pdf_url` can open
      SAT's report. Show it only to the person who asked, never log it, and
      revoke it (`POST /tax-compliance-lookups/{id}/revoke-links`) if it leaks.

      **A verdict relayed, not a determination.** `has_incumplimientos` is
      SAT's own flag at `sat_checked_at`; RiskMotor relays it unchanged and
      does not verify it.

      **TEST keys use a sandbox** and never reach SAT. Sandbox NITs, each with
      one outcome: `20000014` SUCCESS, up to date; `20000022` SUCCESS with
      incumplimientos (every category, `OTHER` included); `20000030`
      NIT_NOT_FOUND; `20000049` — verification failed, ends `FAILED`. Any
      other valid NIT answers NIT_NOT_FOUND. Sandbox answers carry no PDF.
  - name: Registro de Detenciones Guatemala searches
    description: |
      Guatemala only: the **Registro de Detenciones Guatemala** (the Organismo Judicial's
      Registro Central de Detenidos), searched by a person's name in parts — first name, second
      name, first surname, second surname. Each answer lists the
      registrations Registro de Detenciones Guatemala published for that text: document, date of arrest,
      detention centre, who ordered it and the court, exactly as Registro de Detenciones Guatemala wrote
      them (placeholders such as `"No Porta"` or `"-"` included).

      **Read the caveats before relying on a result.** Every answered search
      carries `caveats` — always all four, records found or not:
      `TEXT_NOT_PEOPLE` (Registro de Detenciones Guatemala matches text, not people: "JUAN" also finds
      "JUANA", and a registration may belong to someone else with the same
      name), `NO_RECORDS_NOT_CLEAN` (no registrations is not a clean record:
      a misspelling or a missing part can miss them), `DETENTION_SNAPSHOT`
      (a registration is a detention on its date; it says nothing about
      today) and `NOT_CRIMINAL_RECORD` (detentions, not convictions). Show
      them to whoever reads the result.

      **People only, and never a guess.** Send the parts you know for certain
      and leave the others out: every part you send must appear in the
      registration. We never split a full name for you — a wrong split
      returns a reassuring "no records" for the wrong text.

      **Asynchronous.** Registro de Detenciones Guatemala answers one search at a time for everyone, so
      the request answers `202` with a queue position and an estimate in
      minutes; the result arrives by the `recede_search.completed` webhook,
      or by polling `GET /recede-searches/{id}`. A Registro de Detenciones Guatemala search never
      changes a screening's `overall_status`.

      **Billed only when Registro de Detenciones Guatemala answers** — `RECORDS_FOUND` and `NO_RECORDS`
      alike. A search Registro de Detenciones Guatemala could not answer ends `FAILED` and is not
      billed; nor is one refused or cancelled.

      **When the source itself is down.** If the Organismo Judicial's site stops answering, new
      LIVE searches are still accepted but wait in our queue rather than failing; `queue.source`
      and, while it waits, the search's `source` say `available: false` and since when. They are
      sent by themselves once it is back.

      **TEST keys use a sandbox** and never reach Registro de Detenciones Guatemala. Sandbox names,
      first name `PRUEBA` and first surname: `REGISTROS` → RECORDS_FOUND with
      two fabricated registrations, `SINREGISTROS` → NO_RECORDS,
      `NODISPONIBLE` → Registro de Detenciones Guatemala unavailable (ends `FAILED`), `ILEGIBLE` →
      extraction failed (ends `FAILED`). Any other valid name answers
      NO_RECORDS.
  - name: Webhooks
    description: |
      Rather than polling a long batch, have us tell you when it finishes.
      Endpoints are configured by RiskMotor on request — there is no endpoint
      to manage them, because they carry a signing secret we must hold in
      clear and hand over out of band.

      **Verifying a delivery.** Every request carries
      `RiskMotor-Signature: t=<unix>,v1=<hex>`, an HMAC-SHA256 over
      `<timestamp>.<raw body>` using your endpoint's signing secret. Compute
      the same over the RAW body — not a re-serialised copy — compare in
      constant time, and reject a timestamp more than five minutes old. The
      timestamp is inside the signed material, so it cannot be swapped for a
      fresh one.

      **Answer quickly.** We wait ten seconds, then treat it as a failure.
      Acknowledge with a 2xx and do your work afterwards.

      **Retries.** Anything that is not a 2xx is retried at roughly 1, 5 and
      25 minutes, then 2, 6 and 12 hours, and given up after that. Each
      attempt carries the same `RiskMotor-Delivery-Id` and the same event
      `id`, so **deduplicate on it** — a delivery you already processed can
      arrive again if your 200 was lost on the way back.

      Headers on every delivery: `RiskMotor-Signature`,
      `RiskMotor-Event-Type`, `RiskMotor-Delivery-Id`.

      Event types: `batch.completed`, which fires on any terminal state —
      read `data.status` for `COMPLETED`, `PARTIAL` or `CANCELLED`;
      `adverse_media.completed`, which fires when an adverse media run
      reaches any terminal state, including `PROVIDER_FAILURE` — an
      integration never waits forever. `data` carries `run_id`,
      `screening_id`, `status`, `finding_count`, `highest_severity` and
      `requires_human_review`.

      `rtu_lookup.completed` fires when an RTU lookup is settled —
      `COMPLETED` (SAT answered) or `FAILED` (it could not); `data` is the
      same object `GET /rtu-lookups/{id}` returns, document links included.

      `tax_compliance_lookup.completed` fires when a tax compliance lookup is
      settled — `COMPLETED` (SAT answered) or `FAILED` (it could not); `data`
      is the same object `GET /tax-compliance-lookups/{id}` returns, the PDF
      link included.

      `recede_search.completed` fires when a Registro de Detenciones Guatemala search is settled —
      `COMPLETED` (Registro de Detenciones Guatemala answered) or `FAILED` (it could not); `data` is a
      `RecedeSearchListItem`: counts and the outcome, **never the
      registrations** — fetch `GET /recede-searches/{id}` for them.

paths:
  /screenings:
    post:
      tags: [Screening]
      summary: Screen a subject
      operationId: createScreening
      description: |
        Runs a screening and returns the consolidated result. **This is the
        billable call** — every request that returns 200 is one metered run.

        Send an `Idempotency-Key`. A client cannot distinguish a request that
        never arrived from a response lost on the way back, so retrying after a
        timeout is correct — and without the header that retry is a second
        billable run.
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ScreeningRequest" }
            examples:
              company:
                summary: A company, narrowed by country
                value: { name: "Example Trading Company", type: "COMPANY", country: "GT" }
              personWithId:
                summary: A person, with an identifier to confirm identity
                value:
                  name: "Juan Pérez García"
                  type: "PERSON"
                  country: "GT"
                  dob: "1975-03-14"
                  identifier_type: "PASSPORT"
                  identifier_value: "A1234567"
      responses:
        "200":
          description: The screening ran. A result with no matches is a success, not a 404.
          headers:
            X-Request-Id: { $ref: "#/components/headers/XRequestId" }
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Minute-Limit: { $ref: "#/components/headers/RateLimitMinuteLimit" }
            X-RateLimit-Minute-Remaining: { $ref: "#/components/headers/RateLimitMinuteRemaining" }
            Idempotent-Replay:
              description: |
                `true` when this is a stored response replayed for a repeated
                `Idempotency-Key`. A replay is not metered, so it carries no
                rate-limit headers.
              schema: { type: string, enum: ["true"] }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Screening" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "409":
          description: |
            A request with this `Idempotency-Key` is still running. Wait and
            retry rather than starting a second billable screening.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: |
            This `Idempotency-Key` was already used for a **different** request.
            Refused rather than replayed: returning the earlier subject's result
            would tell you that you screened someone you never screened.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "402": { $ref: "#/components/responses/PaymentRequired" }
        "429": { $ref: "#/components/responses/QuotaExceeded" }
        "500": { $ref: "#/components/responses/ServerError" }

    get:
      tags: [Screening]
      summary: List your screenings
      operationId: listScreenings
      description: |
        Screenings this account has run **through the API**, newest first.
        Runs made by people in the web app are deliberately not listed here:
        those belong to individual users, and an API key is not a reason to
        hand over what a colleague searched. LIVE and TEST are separate.

        Scheduled **monitoring** checks are also excluded by default — a
        customer monitoring 500 subjects generates 500 runs a day, which would
        bury the calls they made themselves. Pass `include=monitoring` to see
        them. Either way an individual monitoring run is always retrievable by
        its id.
      parameters:
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 25 }
        - name: include
          in: query
          description: Set to `monitoring` to include scheduled monitoring checks in the list.
          schema: { type: string, enum: [monitoring] }
        - name: starting_after
          in: query
          description: A screening id from a previous page. Keyset, not offset — rows cannot shift under you between pages.
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: A page of screenings.
          headers:
            X-RateLimit-Minute-Limit: { $ref: "#/components/headers/RateLimitMinuteLimit" }
            X-RateLimit-Minute-Remaining: { $ref: "#/components/headers/RateLimitMinuteRemaining" }
          content:
            application/json:
              schema:
                type: object
                required: [object, data, has_more]
                properties:
                  object: { type: string, const: list }
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/ScreeningSummary" }
                  has_more: { type: boolean }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/QuotaExceeded" }

  /screenings/{id}:
    get:
      tags: [Screening]
      summary: Retrieve a screening
      operationId: getScreening
      description: |
        Returns the screening exactly as it was answered at the time, replayed
        from the stored snapshot — never recomputed against today's data. A
        screening read back a year later says what it said then, which is what
        makes it usable as an audit record.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: The stored screening.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/ScreeningSummary"
                  - type: object
                    properties:
                      result: { $ref: "#/components/schemas/Screening" }
                      notice: { $ref: "#/components/schemas/Notice" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404":
          description: |
            No such screening on this account. Another account's screening
            answers identically — a 403 would confirm the id is real.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /screenings/{id}/adverse-media:
    post:
      tags: [Adverse media]
      summary: Request adverse media for an existing screening
      operationId: requestAdverseMedia
      description: |
        Queues an adverse media run for a screening you can read. Idempotent
        while a run is live: a second call answers the same `run_id` with
        `created: false` and is not billed. After a `PROVIDER_FAILURE`, pass
        `force: true` to start a new run — a new billable run.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                force: { type: boolean, default: false }
      responses:
        "201":
          description: A run was queued.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AdverseMediaRequest" }
        "200":
          description: A run was already live for this screening; nothing new was queued or billed.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AdverseMediaRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403":
          description: "`adverse_media_not_enabled` — the account cannot request adverse media."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "402":
          description: "`spend_cap_reached`, or a plan refusal (`subscription_required`, `usage_limit_reached`, …)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`adverse_media_run_exists` — a previous run failed; send `force: true` to start another."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: "`test_adverse_media_quota` — a TEST key's daily allowance for adverse media runs is spent."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503":
          description: "`feature_disabled` — adverse media is temporarily switched off platform-wide; `enqueue_failed` — the run could not be queued, request it again."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    get:
      tags: [Adverse media]
      summary: Read the adverse media run of a screening
      operationId: getAdverseMedia
      description: |
        The run's status (poll `stage` while it is in progress; a run takes a
        few minutes), its surfaced findings with the reviewer's current
        decision, and the evidence considered — publisher, title, URL and
        dates. Article text is never returned: open the publisher.

        A `PROVIDER_FAILURE` is reported as such, never as "no findings".
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: The run.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/AdverseMediaRun" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404":
          description: No such screening, or adverse media was never requested for it.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /batches:
    post:
      tags: [Batches]
      summary: Submit a batch
      operationId: createBatch
      description: |
        Creates a **draft**. Nothing is screened and nothing is billed until
        you confirm it — the draft exists so you can check the quote and the
        row count first.

        Rows whose name is shorter than two characters are dropped rather than
        queued, and counted in `rows_skipped`: a row that cannot be screened
        must never reach the queue, where it would fail and look like an
        outage.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [rows]
              properties:
                rows:
                  type: array
                  maxItems: 2000
                  items:
                    type: object
                    required: [name]
                    properties:
                      row_no:
                        type: integer
                        description: Your own row number, echoed back on every result so findings reconcile against your records.
                      name: { type: string }
                      type: { type: string, enum: [PERSON, COMPANY, UNKNOWN] }
                      country: { type: string }
                      dob: { type: string }
                      identifier_type: { type: string }
                      identifier_value: { type: string }
                      adverse_media:
                        type: boolean
                        default: false
                        description: |
                          Also run an adverse media check on this row once it is
                          screened — a separate run, billed per row on its own
                          statement line, only if it is delivered. Choose rows
                          individually; the quote's `adverse` line counts them.
                          Requires adverse media on your account (else 403
                          `adverse_media_not_enabled`). A value that is not a
                          boolean is a 400 `invalid_adverse_media`.
                      recede:
                        type: boolean
                        default: false
                        description: |
                          Also search Registro de Detenciones Guatemala for this row once it is screened,
                          with the name in `recede_name`. People only (a COMPANY
                          row is a 400 `recede_person_only`); billed per answered
                          search. The quote's `recede` line counts these rows.
                      recede_name:
                        allOf:
                          - $ref: "#/components/schemas/RecedeName"
                        description: Required when `recede` is true. An invalid name is a 400 `invalid_recede_name` naming the row.
                      renap:
                        type: boolean
                        default: false
                        description: |
                          Also look the row's DPI (`identifier_value`) up in RENAP
                          once the row is screened. A person in Guatemala with a
                          valid 13-digit DPI only, else a 400 naming the row
                          (`renap_person_only`, `renap_not_guatemala`,
                          `renap_invalid_cui`). Billed per lookup RENAP answers,
                          including "no such DPI". The quote's `renap` line counts
                          these rows. Requires RENAP on your account (else 403
                          `renap_not_enabled`); at confirm, 409 `renap_capacity`
                          says how many fit right now (`max_renap_rows`).
                      rtu:
                        type: boolean
                        default: false
                        description: |
                          Also look `nit` up in SAT's RTU against
                          `reference_date`. SAT answers few lookups an hour for
                          every customer, so a batch can ask for a limited number
                          (400 `rtu_batch_too_large` with `max`) and an account a
                          limited number waiting (429 `rtu_queue_full` with
                          `room`). Billed per lookup SAT answers — including NIT
                          not found and a date that does not match. Read SAT's
                          record with `GET /v1/rtu-lookups/{lookup_id}`.
                      tax_compliance:
                        type: boolean
                        default: false
                        description: |
                          Also ask SAT whether `nit` is up to date with SAT
                          (tax compliance) once the row is screened. SAT answers
                          one lookup every few minutes for every customer, so a
                          batch can ask for a limited number (400
                          `tax_compliance_batch_too_large` with `max`) and an
                          account a limited number waiting (429
                          `tax_compliance_queue_full` with `room`). Billed per
                          lookup SAT answers, "NIT not registered" included.
                          Requires tax compliance on your account (else 403
                          `tax_compliance_not_enabled`). Read SAT's answer with
                          `GET /v1/tax-compliance-lookups/{lookup_id}`.
                      nit:
                        type: string
                        description: Guatemalan NIT, with or without the hyphen. Required when `rtu` or `tax_compliance` is true; a wrong check digit is a 400 `invalid_nit` naming the row.
                      reference_date:
                        type: string
                        format: date
                        description: |
                          The date SAT compares against: a person's date of birth,
                          a company's date of incorporation (YYYY-MM-DD, not in
                          the future). Defaults to `dob` when absent. Invalid is a
                          400 `invalid_reference_date` naming the row.
                threshold: { type: integer, minimum: 30, maximum: 100 }
                sources: { type: array, items: { type: string } }
      responses:
        "201":
          description: The draft, with a quote.
          content:
            application/json:
              schema:
                type: object
                properties:
                  batch: { $ref: "#/components/schemas/Batch" }
                  quote: { $ref: "#/components/schemas/BatchQuote" }
                  row_count: { type: integer, description: "Rows actually queued, after unusable ones were dropped." }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/QuotaExceeded" }
    get:
      tags: [Batches]
      summary: List batches
      operationId: listBatches
      parameters:
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 25 }
      responses:
        "200":
          description: Batches raised by this account through the API.
          content:
            application/json:
              schema:
                type: object
                properties:
                  batches:
                    type: array
                    items: { $ref: "#/components/schemas/Batch" }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /batches/{id}:
    get:
      tags: [Batches]
      summary: Retrieve a batch and its progress
      operationId: getBatch
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: The batch and a live count of where its rows have got to.
          content:
            application/json:
              schema:
                type: object
                properties:
                  batch: { $ref: "#/components/schemas/Batch" }
                  progress: { $ref: "#/components/schemas/BatchProgress" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /batches/{id}/confirm:
    post:
      tags: [Batches]
      summary: Confirm a batch and start it
      operationId: confirmBatch
      description: |
        Freezes the row count and starts the queue. **This is where the work
        becomes chargeable** — the number frozen here is the number on the
        invoice, and it is never recomputed.

        The whole batch is checked against your remaining daily allowance and
        refused outright if it will not fit. Running half of a batch and
        failing the rest is the worst of the available answers, so it is not
        one of them.

        Rows that asked for adverse media are checked the same way, whole: when
        they will not fit this month's adverse media capacity the batch is
        refused with 409 `adverse_media_capacity` and `max_adverse_runs` — the
        number that would fit — so you can resubmit with fewer rows marked.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Confirmed; the queue has started.
          content:
            application/json:
              schema:
                type: object
                properties:
                  batch: { $ref: "#/components/schemas/Batch" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: |
            The batch is no longer a draft (`conflict`), or its adverse media
            rows will not fit (`adverse_media_capacity`, with
            `max_adverse_runs`). Nothing was reserved or billed.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "403":
          description: Adverse media rows on an account without adverse media (`adverse_media_not_enabled`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "402":
          description: |
            The account's plan cannot cover the whole batch (see
            `PaymentRequired`). The batch stays a draft and nothing is billed.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: |
            The batch needs more screenings than remain in today's allowance.
            The message names both numbers. Split it, raise the account's
            limit, or confirm it after the reset.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /batches/{id}/cancel:
    post:
      tags: [Batches]
      summary: Cancel a batch
      operationId: cancelBatch
      description: |
        Withdraws everything not yet started. Rows already screened stay done
        and stay billed — that work was really performed.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Cancelled.
          content:
            application/json:
              schema:
                type: object
                properties:
                  batch: { $ref: "#/components/schemas/Batch" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: The batch has already finished or been cancelled.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /batches/{id}/adverse-media:
    post:
      tags: [Batches]
      summary: Add adverse media to rows already screened
      operationId: addBatchAdverseMedia
      description: |
        Requests an adverse media check on rows of a CONFIRMED batch — typically
        after reading the results, for the rows that need review. Rows whose
        previous check failed (`PROVIDER_FAILURE`, `CANCELLED`) or could not be
        queued (`REFUSED`) may be asked again; that is a new run, billed only
        if it is delivered.

        Two calls on purpose: send `confirm: false` (the default) to get the
        quote and the eligible count — nothing is reserved — then the same
        `row_ids` with `confirm: true`. Rows not yet screened, not screened at
        all, or already checked are skipped and counted in `skipped`, never
        charged. Choose rows for a batch you have NOT confirmed yet with each
        row's `adverse_media` field instead (409 `batch_not_confirmed`).
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [row_ids]
              properties:
                row_ids:
                  type: array
                  minItems: 1
                  maxItems: 2000
                  items: { type: string, format: uuid }
                  description: Row `id`s from `GET /v1/batches/{id}/rows`.
                confirm:
                  type: boolean
                  default: false
      responses:
        "200":
          description: The quote (`confirm` false). Nothing was reserved.
          content:
            application/json:
              schema:
                type: object
                properties:
                  eligible: { type: integer }
                  skipped: { $ref: "#/components/schemas/AdverseSkipped" }
                  quote: { $ref: "#/components/schemas/AdverseQuote" }
        "202":
          description: Reserved and queued. Results appear on the rows as each run completes.
          content:
            application/json:
              schema:
                type: object
                properties:
                  requested: { type: integer }
                  retried: { type: integer, description: How many of them repeat a check that had failed. }
                  queued: { type: integer, description: "Queued in this request; the rest follow within minutes." }
                  skipped: { $ref: "#/components/schemas/AdverseSkipped" }
                  quote: { $ref: "#/components/schemas/AdverseQuote" }
        "400":
          description: "`invalid_row_ids`, or `no_eligible_rows` when confirming a selection with nothing to check."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "402":
          description: The account's plan cannot cover these checks (see `PaymentRequired`).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "403":
          description: "`adverse_media_not_enabled` for this account."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`batch_not_confirmed`, or `adverse_media_capacity` with `max_adverse_runs`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: "`test_adverse_media_quota`: a TEST key's daily adverse media allowance."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /batches/{id}/rows:
    get:
      tags: [Batches]
      summary: Read a batch's rows and their outcomes
      operationId: listBatchRows
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
        - name: outcome
          in: query
          description: Narrow to one outcome, e.g. only the rows needing review.
          schema: { type: string, enum: [RESTRICTIONS, PEP_ONLY, NO_MATCH] }
        - name: include
          in: query
          description: |
            Set to `result` to get each row's FULL consolidated result inline,
            instead of fetching them one at a time. This is the answer to "2,000
            rows should not mean 2,000 requests".

            Full results are large, so this mode is paged — use `limit` and
            `offset`. Offset paging is safe here specifically because a batch's
            row set is fixed once created, so nothing shifts under a reader.
          schema: { type: string, enum: [result] }
        - name: limit
          in: query
          description: Rows per page. Only used with `include=result`.
          schema: { type: integer, minimum: 1, maximum: 100, default: 25 }
        - name: offset
          in: query
          description: Rows to skip. Only used with `include=result`.
          schema: { type: integer, minimum: 0, default: 0 }
      responses:
        "200":
          description: |
            Every row with its outcome. Without `include=result` each row
            carries a one-line summary and a `screening_request_id` to fetch;
            with it, each row carries the whole `result` object — the same
            shape `POST /v1/screenings` returns — plus `offset` and `has_more`.
          content:
            application/json:
              schema:
                type: object
                properties:
                  rows:
                    type: array
                    items: { $ref: "#/components/schemas/BatchRow" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /monitored-subjects:
    post:
      tags: [Monitoring]
      summary: Enrol a subject
      operationId: enrolMonitoredSubject
      description: |
        Screens the subject immediately, returns that result as the baseline,
        and re-screens it daily from then on. **The enrolment screening and
        every subsequent check are billed as screenings.**
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name]
              properties:
                name: { type: string, minLength: 2 }
                type: { type: string, enum: [PERSON, COMPANY, UNKNOWN] }
                country: { type: string }
                dob: { type: string }
                identifier_type: { type: string }
                identifier_value: { type: string }
                sources: { type: array, items: { type: string } }
                threshold: { type: integer, minimum: 30, maximum: 100 }
                external_ref:
                  type: string
                  description: Your own identifier — a case or client number. Echoed on every alert so a finding lands in your system without a lookup.
      responses:
        "201":
          description: Enrolled, with the baseline screening.
          content:
            application/json:
              schema:
                type: object
                properties:
                  monitored_subject: { $ref: "#/components/schemas/MonitoredSubject" }
                  baseline: { $ref: "#/components/schemas/Screening" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403":
          description: |
            A TEST key (monitoring bills, so it is live-only), the key lacks
            `monitoring:write`, or the account is already monitoring as many
            subjects as its limit allows.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "402": { $ref: "#/components/responses/PaymentRequired" }
    get:
      tags: [Monitoring]
      summary: List monitored subjects
      operationId: listMonitoredSubjects
      parameters:
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 100, default: 25 }
      responses:
        "200":
          description: Subjects this account is monitoring.
          content:
            application/json:
              schema:
                type: object
                properties:
                  object: { type: string, const: list }
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/MonitoredSubject" }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /monitored-subjects/{id}:
    get:
      tags: [Monitoring]
      summary: Retrieve a monitored subject
      operationId: getMonitoredSubject
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: The subject.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/MonitoredSubject" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      tags: [Monitoring]
      summary: Pause, resume, or relabel
      operationId: updateMonitoredSubject
      description: |
        Only `status` and `external_ref` may change. The screening input is
        frozen on purpose: a subject whose name is edited is a DIFFERENT
        subject, and rewriting it in place would rebase the alert history onto
        someone else. Enrol a new one instead.

        Pausing stops the daily checks, and therefore the daily charge.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status: { type: string, enum: [ACTIVE, PAUSED] }
                external_ref: { type: [string, "null"] }
      responses:
        "200":
          description: The updated subject.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/MonitoredSubject" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
    delete:
      tags: [Monitoring]
      summary: Stop monitoring a subject
      operationId: deleteMonitoredSubject
      description: |
        Checks stop and the charge stops with them. The screenings already
        performed stay in your history — they were run and billed.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Removed.
          content:
            application/json:
              schema:
                type: object
                properties:
                  deleted: { type: boolean }
                  id: { type: string, format: uuid }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /rtu-lookups:
    post:
      tags: [RTU lookups]
      summary: Request an RTU lookup
      operationId: createRtuLookup
      description: |
        Queues a lookup and answers at once with its position in the queue.
        The NIT's verification digit and the date are checked here, so a typo
        is refused immediately, costs nothing and never reaches SAT. Send an
        `Idempotency-Key`: a retry then replays instead of queueing (and
        billing) the lookup twice. Requires `rtu:write`.
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [nit, reference_date]
              properties:
                nit:
                  type: string
                  description: With or without the hyphen (`1234567-8` or `12345678`); `K` as a check digit is accepted.
                  example: "1031154-71"
                reference_date:
                  type: string
                  format: date
                  description: Date of birth for a person, date of incorporation for a company. Must match SAT's record.
                  example: "2018-11-16"
                customer_reference:
                  type: string
                  maxLength: 128
                  description: Yours, echoed back on the lookup and in its webhook.
      responses:
        "202":
          description: Queued.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/RtuLookup"
                  - type: object
                    properties:
                      queue:
                        type: object
                        properties:
                          position: { type: integer, description: "1 = next to be sent to SAT." }
                          estimated_hours:
                            type: [number, "null"]
                            description: Rough wait, from the rate SAT answered over the last day. Null until there is history.
        "400":
          description: "`invalid_nit` (wrong verification digit), `invalid_reference_date`, `invalid_customer_reference`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "402":
          description: A plan refusal (`subscription_required`, `usage_limit_reached`, …).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "403":
          description: "`rtu_not_enabled` — the account cannot request RTU lookups; or `insufficient_scope`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: "`test_rtu_quota` — this TEST key's daily sandbox allowance is spent."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503":
          description: "`feature_disabled` — RTU lookups are temporarily switched off."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    get:
      tags: [RTU lookups]
      summary: List RTU lookups
      operationId: listRtuLookups
      description: |
        This account's lookups made with keys of the same environment, newest
        first. Items carry no record and no document links — open one for
        those. Requires `rtu:read`.
      parameters:
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: offset, in: query, schema: { type: integer, minimum: 0, default: 0 } }
      responses:
        "200":
          description: A page of lookups.
          content:
            application/json:
              schema:
                type: object
                properties:
                  object: { type: string, enum: [list] }
                  has_more: { type: boolean }
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/RtuLookupListItem" }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /rtu-lookups/{id}:
    get:
      tags: [RTU lookups]
      summary: Retrieve an RTU lookup
      operationId: getRtuLookup
      description: The lookup, with SAT's record and the document links once SAT has answered. Requires `rtu:read`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: The lookup.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RtuLookup" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /rtu-lookups/{id}/cancel:
    post:
      tags: [RTU lookups]
      summary: Cancel an RTU lookup that has not been sent
      operationId: cancelRtuLookup
      description: |
        Only a lookup still `QUEUED` can be cancelled; once it is at SAT it will
        be answered (and, if SAT answers, billed). Requires `rtu:write`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: Cancelled.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RtuLookup" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`not_cancellable` — already sent to SAT, or finished."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /rtu-lookups/{id}/revoke-links:
    post:
      tags: [RTU lookups]
      summary: Revoke an RTU lookup's document links
      operationId: revokeRtuLinks
      description: |
        Invalidates every document link issued for this lookup — including
        those already delivered by webhook — and returns the lookup with new
        ones. Use it when a link has leaked. Requires `rtu:write`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: The lookup, with new links.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RtuLookup" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`no_documents` — the lookup has no document links (not answered with a record, or a TEST lookup)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /tax-compliance-lookups:
    post:
      tags: [Tax compliance lookups]
      summary: Request a tax compliance lookup
      operationId: createTaxComplianceLookup
      description: |
        Queues a lookup and answers at once with its position in the queue.
        The NIT's verification digit is checked here, so a typo is refused
        immediately, costs nothing and never reaches SAT. Send an
        `Idempotency-Key`: a retry then replays instead of queueing (and
        billing) the lookup twice. Requires `tax_compliance:write`.
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [nit]
              properties:
                nit:
                  type: string
                  description: With or without the hyphen (`1234567-8` or `12345678`); `K` as a check digit is accepted.
                  example: "2000002-2"
                customer_reference:
                  type: string
                  maxLength: 128
                  description: Yours, echoed back on the lookup and in its webhook.
      responses:
        "202":
          description: Queued.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/TaxComplianceLookup"
                  - type: object
                    properties:
                      queue:
                        type: object
                        properties:
                          position: { type: integer, description: "1 = next to be sent to SAT." }
                          estimated_hours:
                            type: number
                            description: Rough wait, from SAT's current pace and the lookups ahead of this one.
        "400":
          description: "`invalid_nit` (wrong verification digit), `invalid_customer_reference`, `invalid_body`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "402":
          description: A plan refusal (`subscription_required`, `usage_limit_reached`, …).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "403":
          description: "`tax_compliance_not_enabled` — the account cannot request tax compliance lookups; or `insufficient_scope`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: "`test_tax_compliance_quota` — this TEST key's daily sandbox allowance is spent."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503":
          description: "`feature_disabled` — tax compliance lookups are temporarily switched off."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    get:
      tags: [Tax compliance lookups]
      summary: List tax compliance lookups
      operationId: listTaxComplianceLookups
      description: |
        This account's lookups made with keys of the same environment, newest
        first. Items carry SAT's verdict, the taxpayer's name and each
        category's type and count — never the category detail or the PDF
        link; open one for those. Requires `tax_compliance:read`.
      parameters:
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: offset, in: query, schema: { type: integer, minimum: 0, default: 0 } }
      responses:
        "200":
          description: A page of lookups.
          content:
            application/json:
              schema:
                type: object
                properties:
                  object: { type: string, enum: [list] }
                  has_more: { type: boolean }
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/TaxComplianceLookupListItem" }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /tax-compliance-lookups/{id}:
    get:
      tags: [Tax compliance lookups]
      summary: Retrieve a tax compliance lookup
      operationId: getTaxComplianceLookup
      description: The lookup, with SAT's verdict, every category and the PDF link once SAT has answered. Requires `tax_compliance:read`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: The lookup.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/TaxComplianceLookup" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /tax-compliance-lookups/{id}/cancel:
    post:
      tags: [Tax compliance lookups]
      summary: Cancel a tax compliance lookup that has not been sent
      operationId: cancelTaxComplianceLookup
      description: |
        Only a lookup still `QUEUED` can be cancelled; once it is at SAT it will
        be answered (and, if SAT answers, billed). Requires `tax_compliance:write`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: Cancelled.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/TaxComplianceLookup" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`not_cancellable` — already sent to SAT, or finished."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /tax-compliance-lookups/{id}/revoke-links:
    post:
      tags: [Tax compliance lookups]
      summary: Revoke a tax compliance lookup's PDF link
      operationId: revokeTaxComplianceLinks
      description: |
        Invalidates the PDF link issued for this lookup — including one already
        delivered by webhook — and returns the lookup with a new one. Use it
        when a link has leaked. Requires `tax_compliance:write`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: The lookup, with a new link.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/TaxComplianceLookup" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`no_documents` — the lookup has no PDF (not answered by SAT, or a TEST lookup)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /recede-searches:
    post:
      tags: [Registro de Detenciones Guatemala searches]
      summary: Request a Registro de Detenciones Guatemala search
      operationId: createRecedeSearch
      description: |
        Queues a search and answers at once with its position in the queue.
        The name is checked here, so a typo is refused immediately, costs
        nothing and never reaches Registro de Detenciones Guatemala. Send an `Idempotency-Key`: a retry
        then replays instead of queueing (and billing) the search twice.
        Requires `recede:write`.
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/RecedeName"
                - type: object
                  properties:
                    customer_reference:
                      type: string
                      maxLength: 128
                      description: Yours, echoed back on the search and in its webhook.
                    screening_id:
                      type: string
                      format: uuid
                      description: |
                        Link the search to one of your screenings, so it is
                        listed with `?screening_id=`. A screening of a company
                        is refused (`recede_person_only`).
            example: { first_name: "ROXANA", first_last_name: "BALDETTI", customer_reference: "exp-77" }
      responses:
        "202":
          description: Queued.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/RecedeSearch"
                  - type: object
                    properties:
                      queue:
                        type: object
                        properties:
                          position: { type: integer, description: "1 = next to be sent to Registro de Detenciones Guatemala." }
                          estimated_minutes:
                            type: [integer, "null"]
                            description: Rough wait, from the pace Registro de Detenciones Guatemala answered at recently (never faster than its nominal pace). `null` while the source is not answering.
                          source: { $ref: "#/components/schemas/RecedeSource" }
        "400":
          description: "`invalid_recede_name` (with `param` naming the part), `recede_person_only`, `invalid_customer_reference`, `invalid_screening_id`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "402":
          description: A plan refusal (`subscription_required`, `usage_limit_reached`, …).
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "403":
          description: "`recede_not_enabled` — the account cannot request Registro de Detenciones Guatemala searches; or `insufficient_scope`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "404": { $ref: "#/components/responses/NotFound" }
        "429":
          description: "`recede_queue_full` — this account already has the maximum waiting; or `test_recede_quota` — a TEST key's daily sandbox allowance is spent."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "503":
          description: "`feature_disabled` — Registro de Detenciones Guatemala searches are temporarily switched off."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    get:
      tags: [Registro de Detenciones Guatemala searches]
      summary: List Registro de Detenciones Guatemala searches
      operationId: listRecedeSearches
      description: |
        This account's searches made with keys of the same environment, newest
        first. Items carry no registrations — open one for those. Requires
        `recede:read`.
      parameters:
        - { name: screening_id, in: query, description: "Only the searches linked to this screening.", schema: { type: string, format: uuid } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: offset, in: query, schema: { type: integer, minimum: 0, default: 0 } }
      responses:
        "200":
          description: A page of searches.
          content:
            application/json:
              schema:
                type: object
                properties:
                  object: { type: string, enum: [list] }
                  has_more: { type: boolean }
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/RecedeSearchListItem" }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /recede-searches/{id}:
    get:
      tags: [Registro de Detenciones Guatemala searches]
      summary: Retrieve a Registro de Detenciones Guatemala search
      operationId: getRecedeSearch
      description: The search, with the Registro de Detenciones Guatemala registrations and the caveats once it has answered. Requires `recede:read`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: The search.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RecedeSearch" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /recede-searches/{id}/cancel:
    post:
      tags: [Registro de Detenciones Guatemala searches]
      summary: Cancel a Registro de Detenciones Guatemala search that has not been sent
      operationId: cancelRecedeSearch
      description: |
        Only a search still `QUEUED` can be cancelled; once it is at Registro de Detenciones Guatemala it
        will be answered (and, if Registro de Detenciones Guatemala answers, billed). Requires
        `recede:write`.
      parameters:
        - { name: id, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200":
          description: Cancelled.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RecedeSearch" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: "`not_cancellable` — already sent to Registro de Detenciones Guatemala, or finished."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /sources:
    get:
      tags: [Datasets]
      summary: List datasets and their freshness
      operationId: listSources
      description: |
        What every screening is run against, and how current each dataset is.
        This is the endpoint to cite when an auditor asks what you screen
        against and when it was last verified.
      responses:
        "200":
          description: The active datasets.
          content:
            application/json:
              schema:
                type: object
                properties:
                  object: { type: string, const: list }
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/Source" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/QuotaExceeded" }

components:
  securitySchemes:
    bearerApiKey:
      type: http
      scheme: bearer
      description: |
        `Authorization: Bearer rm_live_...`

        Your account administrators create keys in the RiskMotor app
        (Settings → API keys); RiskMotor can also issue them. `rm_live_` keys
        are metered and billed;
        `rm_test_` keys run the identical engine against the identical data and
        are never billed.

        **Server-side only.** This API sends no CORS headers, so a browser
        cannot call it — deliberately: a key in a web page is a key in every
        visitor's devtools.
    apiKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
      description: Alternative to `Authorization`, for HTTP layers that reserve it.

  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: |
        Any unique string up to 255 characters — an order id works well. For
        24 hours, a repeat with the same key and the same body replays the
        stored response instead of screening again.
      schema: { type: string, maxLength: 255 }

  headers:
    XRequestId:
      description: Quote this when contacting support; it appears in our logs for the same request.
      schema: { type: string, format: uuid }
    RateLimitLimit:
      description: Screenings allowed per day.
      schema: { type: integer }
    RateLimitRemaining:
      description: Screenings left in the current day.
      schema: { type: integer }
    RateLimitReset:
      description: |
        Unix seconds at which the allowance resets — **local midnight in your
        account's billing timezone**, not UTC midnight, so it matches your own
        records and your invoice.
      schema: { type: integer }
    RateLimitMinuteLimit:
      description: |
        Requests allowed per minute. A separate limit from the daily one, and
        named apart from it because the two have different remedies: this one
        means "slow down", the daily one means "come back tomorrow".
      schema: { type: integer }
    RateLimitMinuteRemaining:
      description: Requests left in the current minute. Present on every response, including reads.
      schema: { type: integer }

  schemas:
    RecedeName:
      type: object
      required: [first_name, first_last_name]
      description: |
        A person's name in the parts Registro de Detenciones Guatemala searches. Each part: letters,
        spaces, hyphens, apostrophes and periods, at most 60 characters; the
        whole name at least 5 characters. Send only parts you know for
        certain — every part sent must appear in the registration.
      properties:
        first_name: { type: string, maxLength: 60 }
        second_name: { type: [string, "null"], maxLength: 60 }
        first_last_name: { type: string, maxLength: 60, description: First surname. }
        second_last_name: { type: [string, "null"], maxLength: 60, description: Second surname. }
    RecedeSearchListItem:
      type: object
      description: A Registro de Detenciones Guatemala search without its registrations — the shape of list items and of the `recede_search.completed` webhook.
      properties:
        object: { type: string, enum: [recede_search] }
        id: { type: string, format: uuid }
        status:
          type: string
          enum: [QUEUED, IN_PROGRESS, COMPLETED, FAILED, REJECTED, CANCELLED]
          description: |
            `QUEUED` waiting to be sent to Registro de Detenciones Guatemala; `IN_PROGRESS` at Registro de Detenciones Guatemala;
            `COMPLETED` Registro de Detenciones Guatemala answered (billed); `FAILED` Registro de Detenciones Guatemala could not
            answer (not billed); `REJECTED` refused before reaching Registro de Detenciones Guatemala
            (not billed); `CANCELLED` withdrawn by you (not billed).
        environment: { type: string, enum: [LIVE, TEST] }
        first_name: { type: string }
        second_name: { type: [string, "null"] }
        first_last_name: { type: string }
        second_last_name: { type: [string, "null"] }
        searched_name: { type: [string, "null"], description: "The text Registro de Detenciones Guatemala was asked for, once it accepted the search." }
        customer_reference: { type: [string, "null"] }
        screening_id: { type: [string, "null"], format: uuid }
        batch_id: { type: [string, "null"], format: uuid }
        outcome:
          type: [string, "null"]
          enum: [RECORDS_FOUND, NO_RECORDS, RECEDE_UNAVAILABLE, EXTRACTION_FAILED, BLOCKED, ABANDONED, null]
          description: The Registro de Detenciones Guatemala answer once `COMPLETED` (`RECORDS_FOUND` or `NO_RECORDS`), or why it could not answer once `FAILED`. Null otherwise.
        recede_answered: { type: [boolean, "null"], description: "True once COMPLETED, false once FAILED." }
        rejection_code: { type: [string, "null"], enum: [NAME_MISSING, NAME_INVALID, NAME_TOO_SHORT, null] }
        reported_total: { type: [integer, "null"], description: How many registrations Registro de Detenciones Guatemala said it found. }
        row_count: { type: [integer, "null"], description: How many registrations were delivered and kept. }
        created_at: { type: string, format: date-time }
        submitted_at: { type: [string, "null"], format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
    RecedeSearch:
      allOf:
        - $ref: "#/components/schemas/RecedeSearchListItem"
        - type: object
          properties:
            rows:
              type: [array, "null"]
              description: |
                The Registro de Detenciones Guatemala registrations, in its order, only once
                `COMPLETED`. Values are exactly as Registro de Detenciones Guatemala published them,
                placeholders included (`"No Porta"`, `"NO TIENE"`, `"-"`).
                Each may be a different person with the same name.
              items: { $ref: "#/components/schemas/RecedeRow" }
            rows_unavailable:
              type: boolean
              description: Registro de Detenciones Guatemala found registrations but they were no longer retrievable when the answer was recovered. Billed — Registro de Detenciones Guatemala answered.
            caveats:
              type: array
              description: All four, on every answered search. Show them before the result.
              items: { type: string, enum: [TEXT_NOT_PEOPLE, NO_RECORDS_NOT_CLEAN, DETENTION_SNAPSHOT, NOT_CRIMINAL_RECORD] }
            notice: { type: string }
            source:
              allOf:
                - $ref: "#/components/schemas/RecedeSource"
              description: Only while a LIVE search is `QUEUED` or `IN_PROGRESS`.
    RecedeSource:
      type: object
      description: |
        Whether Registro de Detenciones Guatemala itself (the Organismo Judicial's site) is
        answering. While it is not, LIVE searches wait in our queue instead of being sent: they
        are not billed, can still be cancelled, and go out by themselves once it is back.
        Unknown reads as available.
      properties:
        available: { type: boolean }
        since: { type: [string, "null"], format: date-time, description: "When it stopped answering, while `available` is false." }
    RecedeRow:
      type: object
      properties:
        index: { type: integer }
        person_name: { type: [string, "null"] }
        document_type: { type: [string, "null"] }
        document_number: { type: [string, "null"] }
        detention_center: { type: [string, "null"] }
        arrest_date: { type: [string, "null"], format: date, description: The date of arrest when it could be read; a calendar date with no time zone. }
        arrest_date_raw: { type: [string, "null"], description: The date exactly as Registro de Detenciones Guatemala wrote it. }
        ordered_by: { type: [string, "null"] }
        court: { type: [string, "null"] }
        status: { type: [string, "null"] }
    RecedeSearchRequestOutcome:
      type: object
      description: The queued search, or the refusal, beside a screening result.
      properties:
        object: { type: string, enum: [recede_search_request] }
        search_id: { type: string, format: uuid }
        status: { type: string, enum: [QUEUED] }
        error:
          type: object
          properties:
            type: { type: string }
            code: { type: string }
            message: { type: string }
            resets_at: { type: [string, "null"], format: date-time }
    RecedeQuote:
      type: object
      description: |
        The Registro de Detenciones Guatemala line — rows with `recede: true`. Same rule as the runs:
        `priced: false` means no rate is configured, not free.
      properties:
        runs: { type: integer }
        unit_price: { type: [number, "null"] }
        amount: { type: [number, "null"] }
        priced: { type: boolean }
        eta_hours: { type: [integer, "null"], description: "Rough hours until the last search is answered, at the Registro de Detenciones Guatemala nominal pace shared by every customer." }
    RtuQuote:
      type: object
      description: |
        The SAT RTU line — rows with `rtu: true`. Same rule as the runs:
        `priced: false` means no rate is configured, not free.
      properties:
        runs: { type: integer }
        unit_price: { type: [number, "null"] }
        amount: { type: [number, "null"] }
        priced: { type: boolean }
        eta_hours_min: { type: [integer, "null"], description: "Hours until the last lookup is answered at SAT's fastest nominal pace, counting the lookups already ahead of it." }
        eta_hours_max: { type: [integer, "null"], description: The same at SAT's slowest nominal pace. }
        eta_hours: { type: [number, "null"], description: The same at the pace answers actually arrived over the last day; null without history. }
    BatchRowRenap:
      type: object
      description: A row's RENAP lookup — status, outcome and comparison codes only. The record and photo are on the screening's own page in the web app.
      properties:
        status: { type: string, description: "`QUEUED`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, or before a lookup exists `WAITING`, `REFUSED` (see `error`), `NOT_SCREENED`." }
        lookup_id: { type: [string, "null"], format: uuid }
        outcome: { type: [string, "null"], enum: [FOUND, NOT_FOUND, null] }
        name_comparison: { type: [string, "null"], description: "The name as screened against RENAP's: MATCH, CONTAINED, PARTIAL, DIFFERENT, NOT_PROVIDED, NOT_AVAILABLE. A comparison, not a determination of identity." }
        dob_comparison: { type: [string, "null"] }
        error: { type: [string, "null"] }
    BatchRowRtu:
      type: object
      description: A row's SAT RTU lookup — status and outcome only. Read SAT's record with `GET /v1/rtu-lookups/{lookup_id}`.
      properties:
        status: { type: string, description: "`QUEUED`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `REJECTED`, `CANCELLED`, or before a lookup exists `WAITING`, `REFUSED` (see `error`), `NOT_SCREENED`." }
        lookup_id: { type: [string, "null"], format: uuid }
        outcome: { type: [string, "null"] }
        error: { type: [string, "null"] }
    BatchRowRecede:
      type: object
      description: A row's Registro de Detenciones Guatemala search — counts and status only; read the registrations with `GET /v1/recede-searches/{search_id}`.
      properties:
        status:
          type: string
          description: |
            The search's own status once queued, or one of three states before
            one exists: `WAITING` (the row is not screened or queued yet),
            `REFUSED` (it could not be queued — see `error`), `NOT_SCREENED`
            (the row itself failed).
        search_id: { type: [string, "null"], format: uuid }
        outcome: { type: [string, "null"] }
        row_count: { type: [integer, "null"] }
        error: { type: [string, "null"] }
    RtuLookup:
      type: object
      properties:
        object: { type: string, enum: [rtu_lookup] }
        id: { type: string, format: uuid }
        status:
          type: string
          enum: [QUEUED, IN_PROGRESS, COMPLETED, FAILED, REJECTED, CANCELLED]
          description: |
            `QUEUED` waiting to be sent to SAT; `IN_PROGRESS` at SAT;
            `COMPLETED` SAT answered (billed); `FAILED` SAT could not answer
            after retries (not billed); `REJECTED` refused before reaching SAT
            (not billed); `CANCELLED` withdrawn by you (not billed).
        environment: { type: string, enum: [LIVE, TEST] }
        nit: { type: string, description: "Normalized: no separators, uppercase K." }
        reference_date: { type: string, format: date }
        customer_reference: { type: [string, "null"] }
        screening_id: { type: [string, "null"], format: uuid }
        outcome:
          type: [string, "null"]
          enum: [SUCCESS, NIT_NOT_FOUND, DATE_MISMATCH, NIT_INACTIVE, NIT_DECEASED, DATE_UNDER_MIN_AGE,
                 SAT_UNAVAILABLE, CAPTCHA_FAILED, EXTRACTION_FAILED, BLOCKED, ABANDONED]
          description: SAT's answer once `COMPLETED`, or the last failure once `FAILED`. Null otherwise.
        sat_answered: { type: [boolean, "null"], description: "True once COMPLETED, false once FAILED." }
        rejection_code: { type: [string, "null"], enum: [NIT_INVALID, DATE_INVALID, null] }
        rtu:
          type: [object, "null"]
          description: SAT's record, verbatim, only when the outcome is SUCCESS.
          properties:
            legal_name: { type: [string, "null"] }
            fields:
              type: array
              description: |
                Every label SAT printed, in page order. Render from this list;
                `key` is a stable machine name where one is known, null for
                labels not yet mapped.
              items:
                type: object
                properties:
                  section: { type: [string, "null"] }
                  label: { type: string }
                  key: { type: [string, "null"] }
                  value: { type: string }
        documents:
          type: [object, "null"]
          description: SAT's certificate and QR. Bearer links — whoever holds one can open the record.
          properties:
            pdf_url:
              type: [string, "null"]
              format: uri
              description: On riskmotor.com. Valid until the links are revoked.
              example: https://riskmotor.com/d/rtu-pdf/0b9a3c1e-5f4d-4e2a-9c7b-1a2b3c4d5e6f/Xq3…/constancia-rtu.pdf
            qr_url:
              type: [string, "null"]
              format: uri
              description: On riskmotor.com. Valid until the links are revoked.
              example: https://riskmotor.com/d/rtu-qr/0b9a3c1e-5f4d-4e2a-9c7b-1a2b3c4d5e6f/Kp9…/codigo-qr-rtu.png
            archive:
              type: object
              description: Our evidence copy of each document. Present on a single lookup (GET by id, the webhook); `null` for a document with no copy.
              properties:
                pdf: { anyOf: [{ $ref: "#/components/schemas/SatDocumentArchive" }, { type: "null" }] }
                qr: { anyOf: [{ $ref: "#/components/schemas/SatDocumentArchive" }, { type: "null" }] }
        created_at: { type: string, format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        notice: { type: string }
    RtuLookupListItem:
      type: object
      description: An RtuLookup without `rtu`, `documents` or `notice`, plus SAT's legal name when found.
      properties:
        object: { type: string, enum: [rtu_lookup] }
        id: { type: string, format: uuid }
        status: { type: string }
        environment: { type: string, enum: [LIVE, TEST] }
        nit: { type: string }
        reference_date: { type: string, format: date }
        customer_reference: { type: [string, "null"] }
        outcome: { type: [string, "null"] }
        legal_name: { type: [string, "null"] }
        created_at: { type: string, format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
    TaxComplianceQuote:
      type: object
      description: |
        The tax compliance line — rows with `tax_compliance: true`. Same rule as
        the runs: `priced: false` means no rate is configured, not free.
      properties:
        runs: { type: integer }
        unit_price: { type: [number, "null"] }
        amount: { type: [number, "null"] }
        priced: { type: boolean }
        eta_hours: { type: [number, "null"], description: "Hours until the last lookup is answered at SAT's current pace, counting the lookups already ahead of it." }
    BatchRowTaxCompliance:
      type: object
      description: A row's tax compliance lookup — status, outcome and SAT's verdict flag only. Read the categories and the PDF with `GET /v1/tax-compliance-lookups/{lookup_id}`.
      properties:
        status: { type: string, description: "`QUEUED`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `REJECTED`, `CANCELLED`, or before a lookup exists `WAITING`, `REFUSED` (see `error`), `NOT_SCREENED`." }
        lookup_id: { type: [string, "null"], format: uuid }
        outcome: { type: [string, "null"] }
        has_incumplimientos: { type: [boolean, "null"], description: "SAT's flag once `COMPLETED` with outcome SUCCESS." }
        error: { type: [string, "null"] }
    TaxComplianceIncumplimiento:
      type: object
      description: |
        One category SAT reported, with SAT's label verbatim. The list is
        OPEN: render `label` for any `type` you do not recognise — SAT adds
        categories, which arrive as `OTHER` with SAT's own `text`.
      required: [type, label]
      properties:
        type: { type: string, description: "`RTU_UPDATE_PENDING`, `OMITTED_RETURNS`, `BOOKS_PENDING`, `OTHER`." }
        label: { type: string, description: "SAT's heading for the category, verbatim." }
        last_update_date: { type: [string, "null"], format: date, description: "`RTU_UPDATE_PENDING`: when the RTU was last updated." }
        returns:
          type: array
          description: "`OMITTED_RETURNS`: each return SAT says was not filed."
          items:
            type: object
            properties:
              year: { type: [integer, "null"] }
              period: { type: [string, "null"] }
              tax: { type: [string, "null"] }
              form: { type: [string, "null"] }
        text: { type: [string, "null"], description: "`OTHER` (and any category with free text): SAT's text, verbatim." }
    SatDocumentArchive:
      type: object
      description: |
        RiskMotor's own copy of a SAT document, taken when the answer arrived
        and fingerprinted with SHA-256, so the document can be shown to be the
        one SAT issued. The link keeps working while the copy is kept: it is
        served from the copy (checked against the fingerprint on every
        opening). After `retain_until` the file is deleted (the link then
        answers 410) and the fingerprint is kept as the record.
      properties:
        status:
          type: string
          enum: [PENDING, FETCHING, ARCHIVED, NOT_AVAILABLE, FAILED, PURGED]
          description: "`ARCHIVED` = copy held. `NOT_AVAILABLE` = the file was gone before it could be copied. `PURGED` = retention over, file deleted."
        sha256: { type: [string, "null"], pattern: "^[0-9a-f]{64}$", description: "SHA-256 of the file's bytes, once archived." }
        size_bytes: { type: [integer, "null"] }
        fetched_at: { type: [string, "null"], format: date-time, description: When the copy was taken. }
        retain_until: { type: string, format: date, description: Kept until this date (from the lookup's completion). }
        legal_hold: { type: boolean, description: While true the copy is never deleted. }
    TaxComplianceLookup:
      type: object
      properties:
        object: { type: string, enum: [tax_compliance_lookup] }
        id: { type: string, format: uuid }
        status:
          type: string
          enum: [QUEUED, IN_PROGRESS, COMPLETED, FAILED, REJECTED, CANCELLED]
          description: |
            `QUEUED` waiting to be sent to SAT; `IN_PROGRESS` at SAT;
            `COMPLETED` SAT answered (billed); `FAILED` SAT could not answer
            (not billed); `REJECTED` refused before reaching SAT (not billed);
            `CANCELLED` withdrawn by you (not billed).
        environment: { type: string, enum: [LIVE, TEST] }
        nit: { type: string, description: "Normalized: no separators, uppercase K." }
        customer_reference: { type: [string, "null"] }
        screening_id: { type: [string, "null"], format: uuid, description: Set when the lookup came from a batch row. }
        batch_id: { type: [string, "null"], format: uuid }
        outcome:
          type: [string, "null"]
          enum: [SUCCESS, NIT_NOT_FOUND, SAT_UNAVAILABLE, CAPTCHA_FAILED, EXTRACTION_FAILED, BLOCKED, ABANDONED]
          description: SAT's answer once `COMPLETED` (SUCCESS or NIT_NOT_FOUND), or the last failure once `FAILED`. Null otherwise.
        sat_answered: { type: [boolean, "null"], description: "True once COMPLETED, false once FAILED." }
        rejection_code: { type: [string, "null"], enum: [NIT_INVALID, null] }
        has_incumplimientos:
          type: [boolean, "null"]
          description: SAT's verdict — true when SAT says the taxpayer presents incumplimientos. Null unless the outcome is SUCCESS.
        verification:
          type: [object, "null"]
          description: SAT's answer, verbatim, only when the outcome is SUCCESS.
          properties:
            has_incumplimientos: { type: boolean }
            sat_checked_at: { type: string, format: date-time, description: When SAT answered. }
            taxpayer:
              type: object
              properties:
                nit: { type: string }
                name: { type: [string, "null"] }
            incumplimientos:
              type: array
              description: Empty when the taxpayer is up to date.
              items: { $ref: "#/components/schemas/TaxComplianceIncumplimiento" }
        document:
          type: [object, "null"]
          description: SAT's report. A bearer link — whoever holds it can open the report. Null for TEST lookups.
          properties:
            pdf_url:
              type: string
              format: uri
              description: On riskmotor.com. Valid until the link is revoked.
              example: https://riskmotor.com/d/tax-pdf/0b9a3c1e-5f4d-4e2a-9c7b-1a2b3c4d5e6f/Xq3…/solvencia-fiscal-sat.pdf
            archive:
              anyOf: [{ $ref: "#/components/schemas/SatDocumentArchive" }, { type: "null" }]
              description: Our evidence copy of the report. `null` when there is none (yet).
        created_at: { type: string, format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        notice: { type: string }
    TaxComplianceLookupListItem:
      type: object
      description: A TaxComplianceLookup without `verification`, `document` or `notice`, plus the taxpayer's name and each category's type and count.
      properties:
        object: { type: string, enum: [tax_compliance_lookup] }
        id: { type: string, format: uuid }
        status: { type: string }
        environment: { type: string, enum: [LIVE, TEST] }
        nit: { type: string }
        customer_reference: { type: [string, "null"] }
        outcome: { type: [string, "null"] }
        has_incumplimientos: { type: [boolean, "null"] }
        taxpayer_name: { type: [string, "null"] }
        incumplimiento_count: { type: [integer, "null"] }
        categories:
          type: [array, "null"]
          items:
            type: object
            properties:
              type: { type: string }
              count: { type: integer, description: "Omitted returns: how many; any other category: 1." }
        created_at: { type: string, format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
    ScreeningRequest:
      type: object
      required: [name]
      properties:
        adverse_media:
          type: boolean
          default: false
          description: |
            Also request an adverse media run for this subject. The screening
            returns as usual; the run is queued and reported under
            `adverse_media` in the response, then read with
            `GET /screenings/{id}/adverse-media`. Billed per delivered run.
            The account must have adverse media enabled.
        recede:
          allOf:
            - $ref: "#/components/schemas/RecedeName"
          description: |
            Also request a Registro de Detenciones Guatemala search for
            this person, with the name in parts. Checked before the screening
            runs — an invalid name is a 400 `invalid_recede_name` (with
            `param` such as `recede.first_last_name`) and a company a 400
            `recede_person_only` — then queued after it and reported under
            `recede` in the response. Billed when Registro de Detenciones Guatemala answers. The account
            must have Registro de Detenciones Guatemala searches enabled.
        name:
          type: string
          minLength: 2
          description: The person or company to screen, as written. Accents and original scripts are preserved.
        type:
          type: string
          enum: [PERSON, COMPANY, UNKNOWN]
          default: UNKNOWN
        country:
          type: string
          description: ISO 3166-1 alpha-2. Raises confidence on a match; never used to exclude one.
        dob:
          type: string
          description: Date of birth, `YYYY-MM-DD` or a year. Strong identity corroboration.
        identifier_type:
          type: string
          description: e.g. PASSPORT, NATIONAL_ID, TAX_ID.
        identifier_value:
          type: string
          description: |
            An exact identifier match is never downgraded because the name is
            spelled differently.
        sources:
          type: array
          items: { type: string }
          description: |
            Dataset codes from `GET /sources`. Omit to screen against
            everything, which is the recommended default — a narrowed list is
            sent verbatim and silently excludes whatever is missing from it.
            An empty array is rejected rather than treated as "all".
        threshold:
          type: integer
          minimum: 30
          maximum: 100
          default: 65
          description: |
            Minimum match score to report. Lower finds more and reviews more.
            Below the default you are trading reviewer time for recall
            deliberately.

    Screening:
      type: object
      description: The consolidated result. Also stored verbatim as the audit record.
      properties:
        screening_id: { type: string, format: uuid }
        adverse_media:
          description: |
            Present only when `adverse_media: true` was sent. Either the queued
            run, or — when the request was refused — an `error` with the same
            `type`/`code` vocabulary as the error envelope. A refusal never
            fails the screening.
          $ref: "#/components/schemas/AdverseMediaRequestOutcome"
        recede:
          description: |
            Present only when `recede` was sent. Either the queued search, or —
            when the queue refused it — an `error`. A refusal never fails the
            screening, and Registro de Detenciones Guatemala never changes `overall_status`.
          $ref: "#/components/schemas/RecedeSearchRequestOutcome"
        environment: { type: string, enum: [LIVE, TEST] }
        overall_status:
          type: string
          enum: [NO_MATCH, REVIEW_REQUIRED]
          description: |
            `REVIEW_REQUIRED` means a human must look, not that the subject is
            sanctioned. A PEP-only result is `REVIEW_REQUIRED` with
            `highest_severity: null` — exposure carries no severity.
        highest_severity:
          type: [string, "null"]
          enum: [CRITICAL, HIGH, MEDIUM, LOW, null]
          description: The weight of the most serious LISTING found. Null when only political exposure was found.
        unique_listing_count:
          type: integer
          description: Distinct designations. **This is the number that matters.**
        source_confirmation_count:
          type: integer
          description: |
            Official files carrying those designations. Always ≥
            `unique_listing_count`, and a larger number does not mean more
            restrictions — it means better corroboration.
        pep_match_count: { type: integer }
        screened_subject:
          type: object
          properties:
            name: { type: string }
            entity_type: { type: string }
            country: { type: [string, "null"] }
        query:
          type: object
          properties:
            name: { type: string }
            normalized_name: { type: string }
            threshold: { type: number }
            sources: { type: array, items: { type: string } }
        matches:
          type: array
          items: { $ref: "#/components/schemas/Match" }
        source_freshness:
          type: object
          additionalProperties: { type: [string, "null"], format: date-time }
          description: When each dataset last CHANGED.
        source_verified_at:
          type: object
          additionalProperties: { type: [string, "null"], format: date-time }
          description: |
            When we last CONFIRMED we hold the authority's current file. Do not
            conflate with `source_freshness`: a list the authority simply has
            not republished is current, not stale, and this is the field that
            says so.
        notice: { $ref: "#/components/schemas/Notice" }

    Notice:
      type: string
      description: |
        The standing caveat, carried in the payload because you render your own
        UI and this is the one place we can still say it.

    Match:
      type: object
      description: One real-world entity we believe your subject may be.
      properties:
        match_rank: { type: integer }
        canonical_entity:
          type: object
          properties:
            name: { type: string }
            entity_type: { type: string }
            other_listed_names: { type: array, items: { type: string } }
            alias_sample: { type: array, items: { type: string } }
        match_confidence:
          type: number
          minimum: 0
          maximum: 1
          description: |
            How likely this is the SAME real-world entity. **Not** a measure of
            how serious the listing is — see `unique_listings[].severity`. A
            0.6 confidence against an SDN is not a confirmed SDN.
        match_score: { type: integer, description: The same judgement on the 0–100 scale. }
        match_type: { type: string, enum: [POSSIBLE, STRONG, VERY_STRONG, EXACT, NAME_SIMILARITY] }
        matched_value: { type: string }
        matched_via: { type: string, description: "Which field carried the match, e.g. NAME, ALIAS, IDENTIFIER." }
        match_reasons:
          type: array
          items: { type: string }
          description: English prose, kept as the persisted audit record.
        match_reason_codes:
          type: array
          description: The same reasons as structured data, so you can phrase them in any language.
          items:
            type: object
            properties:
              code: { type: string }
              params: { type: object }
        match_evidence:
          type: array
          description: Per-field working, so a reviewer can see WHY rather than trusting a number.
          items:
            type: object
            properties:
              field: { type: string, description: "name, identifier, date_of_birth, country" }
              result: { type: string, description: "EXACT, PARTIAL, NO_MATCH, NOT_PROVIDED" }
              detail: { type: string }
              params: { type: object }
        highest_severity: { type: [string, "null"] }
        pep:
          description: Political exposure, deliberately separate from listings. A PEP is not a restriction and implies no wrongdoing.
          oneOf:
            - $ref: "#/components/schemas/PepMatch"
            - type: "null"
        unique_listings:
          type: array
          items: { $ref: "#/components/schemas/UniqueListing" }

    UniqueListing:
      type: object
      description: One designation by one authority.
      properties:
        listing_id: { type: string, format: uuid }
        listing_key:
          type: string
          description: "Stable logical id, e.g. `OFAC_SDN:424`. Deterministic — never derived from name similarity."
        authority: { type: string, description: "UN, US_TREASURY_OFAC, US_COMMERCE_BIS, US_STATE, EU, UK_FCDO, WORLD_BANK, IDB" }
        list: { type: string, description: The authority's own name for the list. }
        severity: { type: string, enum: [CRITICAL, HIGH, MEDIUM, LOW] }
        restriction_class:
          type: string
          enum: [FINANCIAL_BLOCKING, VISA_OR_ENTRY_RESTRICTION, TRADE_RESTRICTION, PROCUREMENT_INTEGRITY, DEBARMENT]
          description: |
            What the restriction DOES, separately from how serious it is. A
            State Department visa restriction is not an OFAC asset freeze, and
            a development-bank debarment is procurement ineligibility — not a
            sanction.
        listed_name: { type: string }
        programs: { type: array, items: { type: string } }
        remarks: { type: [string, "null"], description: "The authority's own note, where published." }
        listed_at: { type: [string, "null"], format: date }
        designation: { type: [object, "null"] }
        listed_details:
          type: object
          description: Identity data as the authority published it.
          properties:
            dates_of_birth: { type: array, items: { type: string } }
            nationalities_countries: { type: array, items: { type: string } }
            identifiers:
              type: array
              items:
                type: object
                properties:
                  type: { type: string }
                  value: { type: string }
                  country: { type: [string, "null"] }
            addresses: { type: array, items: { type: string } }
        source_confirmations:
          type: array
          description: |
            The official files carrying this one designation. More entries mean
            better corroboration, **not more restrictions**.
          items: { $ref: "#/components/schemas/SourceConfirmation" }

    SourceConfirmation:
      type: object
      properties:
        source: { type: string, description: "Dataset code, as in `GET /sources`." }
        source_record_id: { type: string, description: The record's id in that file. }
        role: { type: string, enum: [PRIMARY, CONFIRMATION] }

    PepMatch:
      type: object
      description: |
        Political exposure. Never contributes to `unique_listing_count` or
        `highest_severity`.
      properties:
        person_name: { type: string }
        pep_status: { type: string, enum: [CURRENT, FORMER, UNKNOWN] }
        jurisdictions: { type: array, items: { type: string } }
        positions:
          type: array
          items:
            type: object
            properties:
              position_title: { type: string }
              category: { type: [string, "null"] }
              jurisdiction: { type: [string, "null"] }
              pep_status: { type: string }
              institution: { type: [string, "null"] }
              term_start: { type: [string, "null"] }
              term_end: { type: [string, "null"] }

    Batch:
      type: object
      properties:
        id: { type: string, format: uuid }
        status:
          type: string
          enum: [DRAFT, CONFIRMED, RUNNING, COMPLETED, PARTIAL, CANCELLED]
          description: |
            `DRAFT` costs nothing. `PARTIAL` means the job finished with some
            rows unscreened — read the rows to see which.
        confirmed_row_count:
          type: [integer, "null"]
          description: Frozen at confirm and never recomputed. This is the number on the invoice.
        rows_skipped: { type: integer, description: Rows dropped as unscreenable before queueing. }
        duplicates_collapsed: { type: integer }
        threshold: { type: [number, "null"] }
        sources: { type: [array, "null"], items: { type: string } }
        created_at: { type: string, format: date-time }
        confirmed_at: { type: [string, "null"], format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        adverse_media_rows:
          type: integer
          description: Rows with adverse media requested, at confirm and afterwards.
        recede_rows:
          type: integer
          description: Rows with a Registro de Detenciones Guatemala search requested.

    BatchQuote:
      type: object
      description: |
        What the batch will cost in the terms of your own contract.
      properties:
        runs: { type: integer }
        priced:
          type: boolean
          description: |
            ⚠ **`false` does not mean free.** It means no rate is configured on
            the account, so we quote the run count and say nothing about money
            rather than print a figure that is not a commercial commitment.
        currency: { type: [string, "null"] }
        unit_price: { type: [number, "null"] }
        amount: { type: [number, "null"] }
        included_remaining: { type: [integer, "null"] }
        overage_runs: { type: [integer, "null"] }
        adverse:
          $ref: "#/components/schemas/AdverseQuote"
        recede:
          $ref: "#/components/schemas/RecedeQuote"
        renap:
          $ref: "#/components/schemas/AdverseQuote"
          description: "The RENAP line — rows with `renap: true`. Same rule as the runs."
        rtu:
          $ref: "#/components/schemas/RtuQuote"
        tax_compliance:
          $ref: "#/components/schemas/TaxComplianceQuote"

    AdverseQuote:
      type: object
      description: |
        The adverse media line — rows with `adverse_media: true`. A separate
        line on your statement, beside the runs. Same rule as the runs:
        `priced: false` means no rate is configured, not free.
      properties:
        runs: { type: integer }
        unit_price: { type: [number, "null"] }
        amount: { type: [number, "null"] }
        priced: { type: boolean }

    AdverseSkipped:
      type: object
      description: Rows of the request that will not be checked, and why. Never charged.
      properties:
        not_found: { type: integer }
        already_requested: { type: integer }
        not_screened: { type: integer }

    BatchProgress:
      type: object
      description: Live counts across the batch's rows.
      properties:
        total: { type: integer }
        pending: { type: integer }
        running: { type: integer }
        done: { type: integer }
        failed: { type: integer }
        skipped: { type: integer }
        restrictions: { type: integer, description: Rows that found a restriction. }
        pep_only: { type: integer, description: Rows that found only political exposure. }
        no_match: { type: integer }
        am_requested: { type: integer, description: "Rows with adverse media requested. Each is in exactly one of the next three." }
        am_pending: { type: integer }
        am_done: { type: integer, description: Delivered. }
        am_failed: { type: integer, description: "Failed, refused, or the row itself was never screened." }
        am_with_findings: { type: integer, description: Delivered with at least one reported finding. }

    BatchRow:
      type: object
      properties:
        id: { type: string, format: uuid, description: "The row's handle — what `POST /v1/batches/{id}/adverse-media` takes." }
        row_no: { type: integer, description: "Your own row number, as submitted." }
        query_name: { type: string }
        status: { type: string, enum: [PENDING, RUNNING, DONE, FAILED, SKIPPED] }
        outcome:
          type: [string, "null"]
          enum: [RESTRICTIONS, PEP_ONLY, NO_MATCH, null]
        screening_request_id:
          type: [string, "null"]
          format: uuid
          description: Fetch it from `/v1/screenings/{id}` for the full consolidated result.
        error: { type: [string, "null"] }
        adverse_media:
          oneOf:
            - $ref: "#/components/schemas/BatchRowAdverse"
            - type: "null"
          description: |
            Null when adverse media was not requested for this row. Read the
            findings with `GET /v1/screenings/{id}/adverse-media`. Adverse
            media never changes the row's `outcome`.
        recede:
          oneOf:
            - $ref: "#/components/schemas/BatchRowRecede"
            - type: "null"
          description: Null when Registro de Detenciones Guatemala was not requested for this row. Never changes the row's `outcome`.
        renap:
          oneOf:
            - $ref: "#/components/schemas/BatchRowRenap"
            - type: "null"
          description: Null when a RENAP lookup was not requested for this row. Never changes the row's `outcome`.
        rtu:
          oneOf:
            - $ref: "#/components/schemas/BatchRowRtu"
            - type: "null"
          description: Null when an RTU lookup was not requested for this row. Never changes the row's `outcome`.
        tax_compliance:
          oneOf:
            - $ref: "#/components/schemas/BatchRowTaxCompliance"
            - type: "null"
          description: Null when a tax compliance lookup was not requested for this row. Never changes the row's `outcome`.

    BatchRowAdverse:
      type: object
      properties:
        status:
          type: string
          description: |
            The run's own status once queued (`QUEUED` … `COMPLETED`,
            `REQUIRES_HUMAN_REVIEW`, `INSUFFICIENT_EVIDENCE`, `PROVIDER_FAILURE`,
            `CANCELLED`), or one of three states before a run exists:
            `WAITING` (the row is not screened or queued yet), `REFUSED` (it could
            not be queued — see `error`), `NOT_SCREENED` (the row itself failed).
        run_id: { type: [string, "null"], format: uuid }
        finding_count: { type: integer }
        highest_severity: { type: [string, "null"], enum: [CRITICAL, HIGH, MEDIUM, LOW, null] }
        error: { type: [string, "null"], description: "The refusal code when `status` is `REFUSED`." }

    AdverseMediaRequest:
      type: object
      properties:
        object: { type: string, enum: [adverse_media_request] }
        run_id: { type: string, format: uuid }
        status: { type: string, enum: [QUEUED] }
        created:
          type: boolean
          description: False when a live run already existed; nothing new was billed.

    AdverseMediaRequestOutcome:
      type: object
      description: The queued run, or the refusal, beside a screening result.
      properties:
        object: { type: string, enum: [adverse_media_request] }
        run_id: { type: string, format: uuid }
        status: { type: string, enum: [QUEUED] }
        created: { type: boolean }
        error:
          type: object
          properties:
            type: { type: string }
            code: { type: string }
            message: { type: string }
            resets_at: { type: [string, "null"], format: date-time }

    AdverseMediaEvidence:
      type: object
      description: One article or official page considered. Never the text — open the publisher.
      properties:
        id: { type: string, format: uuid }
        publisher: { type: [string, "null"] }
        title: { type: [string, "null"] }
        url: { type: string, format: uri }
        publication_date: { type: [string, "null"], format: date }
        date_source:
          type: string
          enum: [PAGE, PROVIDER, UNKNOWN]
          description: Where the date came from. Only PAGE and PROVIDER dates support a "recent" flag.
        source_type: { type: string, enum: [NEWS, OFFICIAL, COURT, REGULATOR, SOCIAL, AGGREGATOR, OTHER] }
        fetch_status:
          type: string
          description: Whether the page could be read. FETCHED, PARTIAL (paywall, truncated, bot wall) or FAILED; a finding resting on an unread page always requires human review.
        sources_count:
          type: integer
          description: How many independent search sources returned this page. Source names are not disclosed.
        language: { type: [string, "null"] }

    AdverseMediaFinding:
      type: object
      description: |
        One reported event. `subject_match` answers "is this the same person
        or company?" and `severity` answers "if so, how serious?" — read
        them separately, exactly like confidence and severity on a match.
        Findings with an INSUFFICIENT or NOT_SAME_SUBJECT identity are never
        returned.
      properties:
        id: { type: string, format: uuid }
        subject_match: { type: string, enum: [HIGH, MEDIUM, LOW] }
        category:
          type: string
          enum: [FRAUD, CORRUPTION, MONEY_LAUNDERING, TERRORISM_FINANCING, SANCTIONS_EVASION, ORGANIZED_CRIME, VIOLENT_CRIME, REGULATORY, TAX, ENVIRONMENTAL, LABOR, OTHER]
        subcategory: { type: [string, "null"] }
        event_status:
          type: string
          enum: [REPORTED_INVESTIGATION, REPORTED_ALLEGATION, REPORTED_CHARGE, REPORTED_CONVICTION, REPORTED_SETTLEMENT, REPORTED_ACQUITTAL, REPORTED_DISMISSAL, UNCLEAR]
          description: What was REPORTED, by the cited publishers. Not a finding of fact.
        severity: { type: string, enum: [CRITICAL, HIGH, MEDIUM, LOW] }
        recent_180_days:
          type: boolean
          description: True only when a cited page or provider date falls inside the recent window.
        historical_major_event: { type: boolean }
        event_date: { type: [string, "null"], format: date }
        event_date_precision: { type: string, enum: [DAY, MONTH, YEAR, UNKNOWN] }
        headline_en: { type: string }
        headline_es: { type: string }
        summary_en: { type: string }
        summary_es: { type: string }
        reason_codes: { type: array, items: { type: string } }
        escalated: { type: boolean, description: "A second, stronger model reviewed this event." }
        fingerprint: { type: string, description: Stable key for the same reported case across re-runs. }
        review_status: { type: string, enum: [UNREVIEWED, POSSIBLE_MATCH, TRUE_MATCH, FALSE_POSITIVE, ESCALATED] }
        reviewed_at: { type: [string, "null"], format: date-time }
        review_notes: { type: [string, "null"] }
        evidence: { type: array, items: { $ref: "#/components/schemas/AdverseMediaEvidence" } }
        exonerating_evidence:
          type: array
          items: { $ref: "#/components/schemas/AdverseMediaEvidence" }
          description: Pages reporting an acquittal, dismissal, withdrawal or correction. Shown first.

    AdverseMediaRun:
      type: object
      properties:
        object: { type: string, enum: [adverse_media_run] }
        run_id: { type: string, format: uuid }
        screening_id: { type: string, format: uuid }
        status:
          type: string
          enum: [QUEUED, RETRIEVING, FETCHING, ADJUDICATING, COMPLETED, COMPLETED_WITH_WARNINGS, INSUFFICIENT_EVIDENCE, REQUIRES_HUMAN_REVIEW, PROVIDER_FAILURE, CANCELLED]
          description: |
            COMPLETED with `finding_count: 0` means nothing adverse was found
            in the sources searched — not that the subject is clean.
            INSUFFICIENT_EVIDENCE means too little could be retrieved to
            assess. PROVIDER_FAILURE means the check could not be completed;
            request it again (`force: true`).
        stage:
          type: [string, "null"]
          enum: [QUEUED, RETRIEVING, FETCHING, ADJUDICATING, null]
          description: What is happening now; null once terminal. Poll every few seconds.
        requested_at: { type: string, format: date-time }
        completed_at: { type: [string, "null"], format: date-time }
        adjudicator_version: { type: [string, "null"] }
        finding_count: { type: integer }
        highest_severity: { type: [string, "null"], enum: [CRITICAL, HIGH, MEDIUM, LOW, null] }
        has_recent: { type: boolean }
        has_historical_major: { type: boolean }
        requires_human_review: { type: boolean }
        warnings:
          type: array
          items: { type: string, enum: [partial_retrieval, some_pages_unreadable, evidence_capped, events_capped, review_required_by_policy] }
          description: What may have limited this run, for the reader. More values may be added; ignore unknown ones.
        error: { type: [string, "null"], description: A neutral line when the check failed or was cancelled. }
        searched:
          type: [object, "null"]
          description: What was searched — how many public web sources, the recent window, languages, how many pages were considered and read. Source names and queries are not disclosed.
          properties:
            sources_searched: { type: [integer, "null"] }
            recent_window_days: { type: [integer, "null"] }
            languages: { type: array, items: { type: string } }
            evidence_considered: { type: [integer, "null"] }
            evidence_read: { type: [integer, "null"] }
        findings: { type: array, items: { $ref: "#/components/schemas/AdverseMediaFinding" } }
        evidence: { type: array, items: { $ref: "#/components/schemas/AdverseMediaEvidence" } }
        notice: { type: string }

    MonitoredSubject:
      type: object
      description: |
        ⚠ `identifier_value` is never returned. You supplied it; we do not hand
        passport or national ID numbers back out.
      properties:
        adverse_media:
          type: boolean
          description: Also re-check adverse media every `adverse_media_interval_days` (default 30). Each re-check is a billed adverse media run; new reported findings arrive as `adverse_media.alert`.
        adverse_media_interval_days:
          type: integer
          minimum: 7
          maximum: 365
          default: 30
        adverse_media_next_check_at:
          type: [string, "null"]
          format: date-time
        id: { type: string, format: uuid }
        external_ref: { type: [string, "null"] }
        name: { type: string }
        entity_type: { type: [string, "null"] }
        country: { type: [string, "null"] }
        dob: { type: [string, "null"] }
        identifier_type: { type: [string, "null"] }
        sources: { type: [array, "null"], items: { type: string } }
        threshold: { type: [number, "null"] }
        status: { type: string, enum: [ACTIVE, PAUSED] }
        last_checked_at: { type: [string, "null"], format: date-time }
        last_screening_id:
          type: [string, "null"]
          format: uuid
          description: The most recent check, retrievable from `/v1/screenings/{id}`.
        next_check_at: { type: string, format: date-time }
        created_at: { type: string, format: date-time }

    ScreeningSummary:
      type: object
      properties:
        id: { type: string, format: uuid }
        created_at: { type: string, format: date-time }
        query_name: { type: string }
        query_type: { type: string }
        country: { type: [string, "null"] }
        overall_status: { type: string, enum: [NO_MATCH, REVIEW_REQUIRED] }
        highest_severity: { type: [string, "null"] }
        unique_listing_count: { type: integer }
        source_confirmation_count: { type: integer }
        threshold: { type: number }

    Source:
      type: object
      properties:
        code: { type: string }
        name: { type: string }
        record_class:
          type: string
          enum: [RESTRICTION, PEP]
          description: A PEP register is not a restriction list.
        last_successful_sync_at:
          type: [string, "null"]
          format: date-time
          description: When this dataset last CHANGED.
        last_verified_at:
          type: [string, "null"]
          format: date-time
          description: When we last confirmed we hold the authority's current file.
        is_overdue:
          type: boolean
          description: Verification is older than twice this dataset's refresh interval.

    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [type, code, message, request_id]
          properties:
            type:
              type: string
              enum:
                - authentication_error
                - permission_error
                - invalid_request_error
                - rate_limit_error
                - not_found_error
                - conflict_error
                - billing_error
                - api_error
            code:
              type: string
              description: |
                The stable identifier to branch on. `type` and `code` are the
                contract; `message` is prose and may be reworded.
            message: { type: string }
            param: { type: string, description: "The offending field, where one can be named." }
            resets_at:
              type: [string, "null"]
              format: date-time
              description: On billing refusals, when the exhausted allowance returns.
            extra_usage_available:
              type: boolean
              description: On `usage_limit_reached`, whether the plan allows extra usage paid from credits.
            request_id: { type: string, format: uuid }

  responses:
    BadRequest:
      description: The request could not be understood.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example:
            error:
              type: invalid_request_error
              code: invalid_threshold
              message: "`threshold` must be a number between 30 and 100."
              param: threshold
              request_id: 0b5c1d2e-3f4a-5b6c-7d8e-9f0a1b2c3d4e
    Unauthorized:
      description: |
        Missing, malformed, unknown, revoked or expired key — all answered
        identically on purpose. Distinguishing them tells someone probing which
        of their guesses was real.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Forbidden:
      description: The key is valid but lacks the scope, or the account is suspended.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    NotFound:
      description: |
        No such resource on this account. Another account's batch answers
        identically — a 403 would confirm the id is real.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    QuotaExceeded:
      description: |
        Too many requests. **Two different limits answer 429, and the `code`
        tells them apart** — they call for different reactions:

        - `rate_limit_exceeded` — the per-minute ceiling. Slow down and retry
          after `Retry-After` seconds. It counts every request, reads
          included, and a refused request still counts, so hammering keeps you
          refused.
        - `daily_quota_exceeded` — the day's screenings are spent.
          `X-RateLimit-Reset` says when the allowance returns, at local
          midnight in your billing timezone.
        - `usage_window_exceeded` — the plan's short-term cap (e.g. N
          screenings per few hours) is reached. `Retry-After` and `resets_at`
          say when the window reopens.

        Neither is billed: both are checked before any screening runs.
      headers:
        Retry-After: { schema: { type: integer } }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    PaymentRequired:
      description: |
        The account's plan does not cover this call. Nothing ran and nothing
        was billed. Branch on `code`:

        - `subscription_required` — the account has no active plan.
        - `payment_past_due` — the account's plan payment is overdue.
        - `usage_limit_reached` — the period's allowance is spent. `resets_at`
          says when it returns.
        - `insufficient_credits` — the account's prepaid balance cannot cover
          the call.

        In every case, contact your RiskMotor account manager. Accounts on a
        contract (the default) are never refused for these reasons.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example:
            error:
              type: billing_error
              code: usage_limit_reached
              message: "The plan's allowance for this period is used up. Turn on extra usage (or raise its monthly cap) and hold credits to continue, or upgrade the plan. It resets at 2026-11-01T06:00:00.000Z."
              resets_at: "2026-11-01T06:00:00.000Z"
              extra_usage_available: true
              request_id: 0b5c1d2e-3f4a-5b6c-7d8e-9f0a1b2c3d4e
    ServerError:
      description: |
        Our fault. The body carries a `request_id` and nothing else — the cause
        is in our logs under that id.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
