openapi: 3.1.0
info:
  title: PLLAY Outcomes Oracle — Settlement
  version: 1.3.0
  description: |
    Contract for the settlement machine, written from the deployed oracle-settlement function. Fields marked
    `x-pllay-status: not-live` exist in the code but are switched off.

    Sandbox responses include the header X-PLLAY-Synthetic with the value true.

    ## Changelog

    ### 1.3.0
    POST /v1/events/{id}/reverse does not write a reversal. It returns 403 reversal_requires_dispute.
    The settle request accepts only an optional vision_run_id. outcome, confidence, threshold, model_version,
    reviewer_id, evidence and evidence_uri are set by PLLAY. Clients must not send them. The server rejects
    them with 422 server_locked_field, or in transitional mode ignores them and returns a warnings entry.
    A same-body create replay returns 200 with the header Idempotent-Replay true.
    GET /v1/events/{id}/receipt can list stored receipt rows while anchoring is off.
    A missing or not-owned event on a partner event route returns 404 not_found with message "Event not found".

    ### 1.2.0
    Create does not accept threshold. The working settle body is an empty object.
    spec.game_slug names an auto-settle title, such as fortnite. spec.pov_side (home or away) is required
    when game_slug is dota2 or rocketleague. A title that is not offered for auto-settlement is refused
    with 403 certification_blocked and the message "Title not offered for auto-settlement".

    States: open | locked | held | settled | reversed | voided.
    Transitions: open→locked|voided · locked→held|settled|voided · held→settled|voided · settled→reversed.
    reversed and voided are terminal. See x-pllay-state-machine for the verb, webhook and meaning of each state.

    held is a WAITING state. It is not a success and not a settlement: the result is not final, it goes to a
    person for review, nobody is paid, and the event later moves to settled or voided. A held event has
    outcome = null and settlement_id = null.

    Identifiers (event_id, settlement_id, reversal_settlement_id, reviewer_id) are UUIDs.

    Not in this contract: the partner webhook registration, delivery-log, webhook replay and dead-letter routes,
    the full dispute route, production tests and the admin routes on the same function. They exist but are documented
    elsewhere or are internal. reversal_requires_dispute names POST /v1/events/{id}/dispute. The public "Try it on a clip"
    demo function (supabase/functions/demo) is left out on purpose: it is dark and every route returns 503 demo_disabled.
servers:
  # api.pllay.io is a host-based alias (Vercel rewrite in apps/website/next.config.ts) for the deployed function below.
  # Both answer the same requests; the Supabase URL is the origin the alias forwards to.
  - url: https://api.pllay.io
    description: Partner API host. /v1/vision/verify forwards to partner-api; everything else under /v1 to oracle-settlement. If this host does not answer with JSON, call the function URL below.
  - url: https://gatwzvsfzlhqzisgqlye.supabase.co/functions/v1/oracle-settlement
    description: The deployed oracle-settlement function, called directly.
security:
  - PartnerKey: []
tags:
  - name: events
    description: The settlement state machine.
  - name: evidence
    description: Evidence bundles, receipts and evidence verification.
  - name: sandbox
    description: Public, stateless sandbox fixture. No key.
components:
  securitySchemes:
    PartnerKey:
      type: apiKey
      in: header
      name: X-Partner-Key
      description: |
        Keys are issued as pllay_sk_sandbox_… (sandbox) and pllay_sk_live_… (production); the older pk_sandbox_ and
        pk_live_ prefixes are still accepted. A
        prefix alone never authenticates: the key is checked by the verify_partner_api_key_v2 RPC (hash, status,
        expiry, partner status, scope). GET needs scope outcomes:read; every POST needs outcomes:write. A key whose
        prefix says sandbox but which is stored as production (or the reverse) is refused. Failure returns
        401 unauthorized. Events are scoped to the key's partner and environment: another partner's event, or an
        event in the other environment, looks exactly like an unknown id.

        Sandbox keys are issued through the developer portal (the partner_portal_issue_sandbox_api_key RPC), not
        through a REST endpoint. Self-serve sandbox signup is dark (platform_config self_serve_signup_enabled is
        off by default); keys are arranged with the PLLAY team.
  parameters:
    EventId: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: Required on create. Stored per partner (two partners can use the same value without colliding). A missing header is refused. The same key and the same body within 24 hours returns 200 with the header Idempotent-Replay true. A reused key is not a 422.
      schema: { type: string }
  schemas:
    State: { type: string, description: "open, locked: not resolved. held: WAITING, not a success; not final, routed to human review, nobody is paid, later settled or voided. settled: final, outcome and settlement_id set. reversed: a settled event undone by a new entry. voided: closed with no outcome, nobody is paid.", enum: [open, locked, held, settled, reversed, voided] }
    Type: { type: string, description: The deployed service accepts exactly these three values on create. The same machine applies to all three., enum: [promo, contest, duel] }
    Path: { type: string, description: live settles only with a reviewer_id., enum: [vod, live] }
    EventCreate:
      type: object
      additionalProperties: false
      required: [type, path, spec]
      description: |
        Unknown keys are rejected with 422 validation_failed (details.unknown_keys); missing required keys with
        422 validation_failed (details.missing_keys). outcome, confidence, threshold, model_version, reviewer_id,
        evidence and evidence_uri are set by PLLAY. Clients must not send them. The server rejects them with
        422 server_locked_field, or in transitional mode ignores them and returns a warnings entry.
      properties:
        type: { $ref: '#/components/schemas/Type' }
        path: { $ref: '#/components/schemas/Path' }
        spec:
          type: object
          description: |
            Stored as given. spec.game_slug names the auto-settle title, such as fortnite.
            spec.pov_side is home or away and is required when game_slug is dota2 or rocketleague.
            spec.category is optional; absent means gaming; gaming is the only category accepted today, a known but
            not-offered category returns 422 category_not_offered, an unknown one 422 validation_failed.
            spec.corroboration is an optional policy, see x-pllay-settle-rule.
            A title that is not offered for auto-settlement is refused on settle with 403 certification_blocked
            and the message "Title not offered for auto-settlement".
          properties:
            title: { type: string }
            question: { type: string }
            game_slug: { type: string, description: "An auto-settle title, such as fortnite.", examples: [fortnite] }
            pov_side: { type: string, enum: [home, away], description: "Required when game_slug is dota2 or rocketleague." }
            category: { type: string }
            corroboration: { type: object, description: Optional policy. See x-pllay-settle-rule. }
        stake_ref: { type: [string, 'null'], maxLength: 200, description: Operator reference for operator contests. }
        notional_minor: { type: integer, minimum: 0, default: 0, description: Pool or stake value in minor units. Must be 0 on a sandbox key (422 validation_failed). }
    Event:
      type: object
      additionalProperties: true
      required: [event_id, type, path, state, spec, outcome, confidence, threshold, model_version, evidence_uri, settlement_id, reversal_settlement_id, reviewer_id, stake_ref, notional_minor, reason]
      description: |
        The shape for event responses, the sandbox fixture and webhook bodies. legacy_type is optional (see below).
        A response may also carry threshold_config_version, vision_run_id, reader_version, decided_by and warnings.
      properties:
        event_id: { type: string, format: uuid }
        type: { $ref: '#/components/schemas/Type' }
        path: { $ref: '#/components/schemas/Path' }
        state: { $ref: '#/components/schemas/State' }
        spec: { type: object }
        outcome: { type: [string, 'null'], enum: [yes, no, void, null], readOnly: true, description: "Set by PLLAY. yes, no or void. null while open, locked or voided. Clients must not send it." }
        confidence: { type: [number, 'null'], minimum: 0, maximum: 1, readOnly: true, description: "Set by PLLAY. May be non-null when state is held and when state is settled. null when PLLAY has not set a score. Clients must not send it." }
        threshold: { type: number, minimum: 0, maximum: 1, readOnly: true, description: "Set by PLLAY. Clients must not send it." }
        model_version: { type: [string, 'null'], readOnly: true, description: "Set by PLLAY. May be non-null when state is held and when state is settled. Clients must not send it." }
        evidence_uri: { type: [string, 'null'], format: uri, readOnly: true, description: "Set by PLLAY. Clients must not send it." }
        settlement_id: { type: [string, 'null'], format: uuid, description: "Set on settle only. null while held. Never rewritten, including after a reversal." }
        reversal_settlement_id: { type: [string, 'null'], format: uuid, description: Set only when state is reversed (the id of the reversal); null otherwise. }
        reviewer_id: { type: [string, 'null'], format: uuid, readOnly: true, description: "Set by PLLAY. Clients must not send it." }
        stake_ref: { type: [string, 'null'] }
        notional_minor: { type: integer, minimum: 0 }
        reason: { type: [string, 'null'], description: "Set by hold (default below_threshold), by a corroboration hold (source_conflict | corroboration_required), and by void." }
        threshold_config_version: { type: string, readOnly: true, description: Optional. The threshold configuration the server used. }
        vision_run_id: { type: string, format: uuid, readOnly: true, description: Optional. The Vision run. }
        reader_version: { type: string, readOnly: true }
        decided_by: { type: string, readOnly: true }
        warnings: { type: array, readOnly: true, description: "A warnings entry when transitional mode ignores a field the client must not send.", items: { type: object, additionalProperties: true } }
        legacy_type: { type: string, enum: [Head-to-Head, League, Tournament, Team], description: "Optional, read side only, never null. Present only on an event stored with a pre-contract type value: type is then the mapped contract value (Head-to-Head → duel; League, Tournament, Team → contest) and legacy_type is the value as stored. Absent (not null) when the stored type is already promo, contest or duel. Can appear on GET /v1/events/{id}, on lock, settle, hold, void and reverse, and in their webhook bodies; never on create or the sandbox fixture. Create still refuses these values (422)." }
    Settle:
      type: object
      additionalProperties: false
      description: |
        The working body is {}. The only optional field is vision_run_id.
        outcome, confidence, threshold, model_version, reviewer_id, evidence and evidence_uri are set by PLLAY.
        Clients must not send them. The server rejects them with 422 server_locked_field, or in transitional mode
        ignores them and returns a warnings entry. outcome, when PLLAY sets it, is yes, no or void.
        server_locked_field is { error: server_locked_field, message: "PLLAY sets outcome, confidence and threshold from its Vision run. Remove these fields.", details: { fields } }.
        details.fields lists the locked keys that were sent.
      properties:
        vision_run_id: { type: string, format: uuid, description: Optional Vision run id. }
    Reason:
      type: object
      properties:
        reason: { type: string, maxLength: 200 }
    EvidenceBundle:
      type: object
      additionalProperties: true
      required: [schema, state, path, environment, label, generated_at]
      description: |
        schema pllay.evidence.v1. The bundle stored at settle (or at a corroboration hold), or one built from the
        event row for events settled before bundles existed. It is not signed: oracle-settlement bundles carry no
        audit_hash and no kid. Signed evidence is the Vision evidence record; see POST /v1/evidence/verify.
      properties:
        schema: { type: string, const: pllay.evidence.v1 }
        event_id: { type: [string, 'null'], format: uuid, description: null on the sandbox fixture bundle. }
        settlement_id: { type: [string, 'null'], format: uuid }
        state: { $ref: '#/components/schemas/State' }
        path: { $ref: '#/components/schemas/Path' }
        outcome: { type: [string, 'null'], readOnly: true }
        confidence: { type: [number, 'null'], readOnly: true }
        threshold: { type: number, readOnly: true }
        margin: { type: [number, 'null'], readOnly: true, description: confidence minus threshold. }
        model_version: { type: [string, 'null'], readOnly: true }
        reviewer_id: { type: [string, 'null'] }
        window: { description: 'evidence.window as supplied, or null.' }
        signals: { description: 'evidence.signals as supplied, or an empty list.' }
        sources: { type: array }
        corroboration: { type: [object, 'null'] }
        attempted: { type: [object, 'null'], description: "On a corroboration hold, the outcome, confidence and model_version the caller tried to settle with." }
        supplied: { type: object, description: "The caller's evidence object, as given." }
        environment: { type: string, enum: [sandbox, production] }
        label: { type: string, description: "\"Sandbox fixture · not production proof\" for sandbox, \"Evidence bundle\" for production." }
        generated_at: { type: string, format: date-time }
    Receipt:
      type: object
      additionalProperties: true
      required: [event_id, anchoring_enabled, receipts]
      description: |
        event_id, anchoring_enabled and receipts. Hash anchoring can be off while receipts is non-empty:
        settle still writes rows with status stored. receipt_gap is issued_hash_not_stored when the event has a
        settlement_id and no stored row. A sandbox response adds synthetic, environment, synthetic_fields and note,
        and the header X-PLLAY-Synthetic.
      properties:
        event_id: { type: string, format: uuid }
        anchoring_enabled: { type: boolean }
        receipt_gap: { type: string, enum: [issued_hash_not_stored] }
        receipts:
          type: array
          items:
            type: object
            additionalProperties: true
            properties:
              status: { type: string, description: stored while anchoring is off. }
              explorer_url: { type: [string, 'null'] }
              receipt:
                type: object
                additionalProperties: true
                description: schema pllay.receipt.v1, plus the settlement fields.
                properties:
                  schema: { type: string, const: pllay.receipt.v1 }
                  kind: { type: string }
                  event_id: { type: string, format: uuid }
                  settlement_id: { type: [string, 'null'], format: uuid }
                  reversal_of: { type: [string, 'null'] }
                  evidence_digest: { type: [string, 'null'] }
        synthetic: { type: boolean, const: true, description: On a sandbox response. }
        environment: { type: string, const: sandbox, description: On a sandbox response. }
        synthetic_fields: { type: array, items: { type: string }, description: On a sandbox response. }
        note: { type: string, description: On a sandbox response. }
    EvidenceVerify:
      type: object
      required: [event_id, audit_hash]
      properties:
        event_id: { type: string, format: uuid, description: The partner-api resolution event id (the Vision verification job id). Not an oracle-settlement event_id. }
        audit_hash: { type: string, description: The audit_hash from the partner-api evidence bundle for that event. }
        signals: { type: object, additionalProperties: true, description: The bundle's signals as received. Omit to check against the stored signals. }
    PartnerApiError:
      type: object
      description: partner-api error envelope (used only by POST /v1/evidence/verify in this file).
      properties:
        error:
          type: object
          properties:
            code: { type: string, description: "missing_api_key, validation_error, not_found, not_resolved, invalid_json, payload_too_large, rate_limited, internal_error, …" }
            message: { type: string }
            request_id: { type: string }
            documentation_url: { type: string }
            retryable: { type: boolean }
            field_errors: { type: array, items: { type: object, properties: { field: { type: string }, message: { type: string } } } }
    Error:
      type: object
      required: [error, message]
      properties:
        error:
          type: string
          enum: [unauthorized, not_found, validation_failed, server_locked_field, category_not_offered, live_unreviewed, below_threshold, promo_stake, certification_review_required, illegal_transition, certification_blocked, reversal_requires_dispute, rate_limit_exceeded, certification_check_failed, invalid_body, missing_reason, spend_cap_reached, billing_suspended, daily_settle_cap_reached, notional_cap_exceeded, billing_check_failed]
        message: { type: string }
        details: { type: object, description: "On server_locked_field, fields lists the locked keys that were sent. On validation_failed, unknown_keys, missing_keys, reason or one entry per bad field.", properties: { fields: { type: array, items: { type: string } } } }
        reset_in_seconds: { type: integer, description: On rate_limit_exceeded. }
  responses:
    Event: { description: The event after the call. Read state; a 200 is not by itself a settlement., content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } } }
    Unauthorized: { description: 'unauthorized — missing, unknown, revoked or expired X-Partner-Key, or a key without the scope this method needs', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Unprocessable: { description: "Rule violation (validation_failed | server_locked_field | category_not_offered | below_threshold | live_unreviewed | certification_review_required | promo_stake). server_locked_field message is \"PLLAY sets outcome, confidence and threshold from its Vision run. Remove these fields.\" details.fields lists the locked keys that were sent. These fields are set by PLLAY; clients must not send them. The server rejects them with 422 server_locked_field, or in transitional mode ignores them and returns a warnings entry.", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Conflict: { description: "illegal_transition — the event exists and the move is not in the state map", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    NotFound: { description: 'not_found — missing or not-owned event. The body is { error: not_found, message: "Event not found" }.', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    BadBody: { description: "invalid_body — the request body is empty, not JSON, or not a JSON object", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    BillingRefused: { description: "spend_cap_reached | billing_suspended | daily_settle_cap_reached | notional_cap_exceeded — production billing refused a new settle. Not retryable as-is: spend_cap_reached clears next calendar month (UTC) or when the cap is raised; billing_suspended when the unpaid invoice is paid; daily_settle_cap_reached at 00:00 UTC; notional_cap_exceeded when the per-event cap is raised. Nothing was settled or billed. Applies only to production partners on the pay-per-settle plan while spend-cap enforcement is on (currently off).", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    BillingCheckFailed: { description: "billing_check_failed — the billing check could not be completed. Retryable: nothing was settled; retry shortly. Production settles only, on the same plan and switch as the 402 codes.", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
paths:
  /v1/events:
    post:
      tags: [events]
      operationId: createEvent
      summary: Create an event → open
      description: |
        Limited to 100 creates per 60 seconds per key, counted in the database across all instances (per instance only if that shared counter is unavailable). Over the limit returns 429 rate_limit_exceeded with X-RateLimit-Remaining and X-RateLimit-Reset headers. Emits no webhook.
        outcome, confidence, threshold, model_version, reviewer_id, evidence and evidence_uri are set by PLLAY. Clients must not send them. The server rejects them with 422 server_locked_field, or in transitional mode ignores them and returns a warnings entry.
        A same-body replay returns 200 with the header Idempotent-Replay true.
        Sandbox responses include the header X-PLLAY-Synthetic with the value true.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/EventCreate' } } } }
      responses:
        '201':
          description: The created event. Read state. A sandbox response includes X-PLLAY-Synthetic true.
          headers:
            X-PLLAY-Synthetic:
              description: On a sandbox response, the value is true.
              schema: { type: string, const: 'true' }
          content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } }
        '200':
          description: Idempotent replay of the same key and the same body. The body is the original event.
          headers:
            Idempotent-Replay:
              description: true on a replay.
              schema: { type: string, const: 'true' }
            X-PLLAY-Synthetic:
              description: On a sandbox response, the value is true.
              schema: { type: string, const: 'true' }
          content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '422': { $ref: '#/components/responses/Unprocessable' }
        '429': { description: rate_limit_exceeded, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
  /v1/events/{id}:
    get:
      tags: [events]
      operationId: getEvent
      summary: Read an event
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      responses:
        '200': { $ref: '#/components/responses/Event' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/events/{id}/lock:
    post:
      tags: [events]
      operationId: lockEvent
      summary: open → locked
      description: Emits no webhook.
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      responses:
        '200': { $ref: '#/components/responses/Event' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /v1/events/{id}/hold:
    post:
      tags: [events]
      operationId: holdEvent
      summary: locked → held (waiting for review; not a settlement)
      description: The event waits for a person. Nobody is paid. It later moves to settled (POST /settle) or voided (POST /void). outcome and settlement_id stay null. confidence and model_version may already be set. reason defaults to below_threshold. Emits event.held.
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/Reason' } } } }
      responses:
        '200': { description: "The event, now state held. This is a waiting state, not a success. confidence and model_version may be non-null.", content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { description: validation_failed — reason is not a non-empty string of up to 200 characters, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
  /v1/events/{id}/settle:
    post:
      tags: [events]
      operationId: settleEvent
      summary: locked | held → settled, or → held by the corroboration policy
      description: |
        The working body is {}. The only optional field is vision_run_id. outcome, confidence, threshold,
        model_version, reviewer_id, evidence and evidence_uri are set by PLLAY. Clients must not send them.
        The server rejects them with 422 server_locked_field, or in transitional mode ignores them and returns a
        warnings entry. The server_locked_field message is "PLLAY sets outcome, confidence and threshold from its Vision run. Remove these fields."
        details.fields lists the locked keys that were sent. outcome is yes, no or void.

        Checks, in order: body · a missing or not-owned event (404 not_found) · state (409) · title certification
        when the event has a title (500 certification_check_failed, 403 certification_blocked with message
        "Title not offered for auto-settlement", 422 certification_review_required) · spec.corroboration (422
        validation_failed) · the corroboration policy · on a production event that is about to settle, the billing
        gate (402 spend_cap_reached, billing_suspended, daily_settle_cap_reached or notional_cap_exceeded, not
        retryable; 503 billing_check_failed, retryable). Nothing is settled or billed on a refusal.

        The billing codes apply only to production partners on the pay-per-settle plan when spend-cap enforcement
        is on (platform_config self_serve_spend_cap_enforced; currently off, so today they are never returned).
        Sandbox events and corroboration holds are never gated. Only settle runs the gate; create and lock do not.

        The response is 200 in both outcomes below. Read state:
        - state settled: final. outcome, confidence and settlement_id are set. Emits event.settled.
        - state held: waiting, not a success. outcome and settlement_id stay null. confidence and model_version may be non-null. Nobody is paid. Emits event.held.
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Settle' } } } }
      responses:
        '200':
          description: The event after the call. state is settled (final) or held (waiting, not a success). A sandbox response includes X-PLLAY-Synthetic true.
          headers:
            X-PLLAY-Synthetic:
              description: On a sandbox response, the value is true.
              schema: { type: string, const: 'true' }
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Event' }
              examples:
                settled:
                  summary: Settled — final
                  value: { event_id: 5d0e8a14-3b7c-4f29-a6d1-9c2e47b0f385, type: duel, path: vod, state: settled, spec: { title: Sandbox Fixture, market: sandbox }, outcome: 'yes', confidence: 0.95, threshold: 0.8, model_version: sandbox-fixture-1, evidence_uri: 'https://gatwzvsfzlhqzisgqlye.supabase.co/functions/v1/oracle-settlement/v1/events/5d0e8a14-3b7c-4f29-a6d1-9c2e47b0f385/evidence', settlement_id: 7f3ac91e-2b4d-4e60-8a15-c0d9e3f1a762, reversal_settlement_id: null, reviewer_id: null, stake_ref: null, notional_minor: 0, reason: null }
                held_by_corroboration:
                  summary: Held by the corroboration policy — waiting, nobody is paid
                  value: { event_id: 5d0e8a14-3b7c-4f29-a6d1-9c2e47b0f385, type: duel, path: vod, state: held, spec: { title: Sandbox Fixture, market: sandbox, corroboration: { require_agreeing: 1 } }, outcome: null, confidence: 0.5, threshold: 0.8, model_version: sandbox-fixture-1, evidence_uri: null, settlement_id: null, reversal_settlement_id: null, reviewer_id: null, stake_ref: null, notional_minor: 0, reason: corroboration_required }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { description: 'certification_blocked — message "Title not offered for auto-settlement". The event is not settled.', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '402': { $ref: '#/components/responses/BillingRefused' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Unprocessable' }
        '500': { description: certification_check_failed, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        '503': { $ref: '#/components/responses/BillingCheckFailed' }
  /v1/events/{id}/void:
    post:
      tags: [events]
      operationId: voidEvent
      summary: open | locked | held → voided
      description: Closes the event with no outcome. Nobody is paid. Emits event.voided. Send a JSON object ({} is fine; reason is optional and is then null). An empty, non-JSON or non-object body returns 400 invalid_body.
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/Reason' } } } }
      responses:
        '200': { $ref: '#/components/responses/Event' }
        '400': { $ref: '#/components/responses/BadBody' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /v1/events/{id}/reverse:
    post:
      tags: [events]
      operationId: reverseEvent
      summary: Refused. A settled result changes only through a dispute.
      description: |
        Does not write a reversal. Returns 403 reversal_requires_dispute.
        The message is "Settled results change only through a dispute. File one at POST /v1/events/{id}/dispute within 72 hours of settlement."
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      responses:
        '403':
          description: reversal_requires_dispute. Nothing was written.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Error' }
              example:
                error: reversal_requires_dispute
                message: "Settled results change only through a dispute. File one at POST /v1/events/{id}/dispute within 72 hours of settlement."
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/events/{id}/evidence:
    get:
      tags: [evidence]
      operationId: getEventEvidence
      summary: The evidence bundle behind an event
      description: The default target of evidence_uri. Unsigned (see EvidenceBundle).
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      responses:
        '200': { description: Evidence bundle, content: { application/json: { schema: { $ref: '#/components/schemas/EvidenceBundle' } } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/events/{id}/receipt:
    get:
      tags: [evidence]
      operationId: getEventReceipt
      summary: Receipt rows for an event
      description: anchoring_enabled can be false while receipts is non-empty. Those rows have status stored. receipt_gap is issued_hash_not_stored when the event has a settlement_id and no stored row. A sandbox body adds synthetic, environment, synthetic_fields and note. A sandbox response includes the header X-PLLAY-Synthetic with the value true.
      parameters: [{ $ref: '#/components/parameters/EventId' }]
      responses:
        '200':
          description: Anchoring status. A sandbox response includes X-PLLAY-Synthetic true.
          headers:
            X-PLLAY-Synthetic:
              description: On a sandbox response, the value is true.
              schema: { type: string, const: 'true' }
          content: { application/json: { schema: { $ref: '#/components/schemas/Receipt' } } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '404': { $ref: '#/components/responses/NotFound' }
  /v1/evidence/verify:
    servers:
      - url: https://gatwzvsfzlhqzisgqlye.supabase.co/functions/v1/partner-api
        description: partner-api only. api.pllay.io does not forward this path (it sends it to oracle-settlement, which has no such route).
    post:
      tags: [evidence]
      operationId: verifyEvidence
      summary: Verify a Vision evidence audit_hash server-side
      description: |
        Live. Needs scope resolution:read. audit_hash is an HMAC-SHA256 under a key PLLAY holds, so it cannot be
        checked locally. PLLAY recomputes it over the stored Vision evidence record (subject id, model and adapter
        version, confidence) and the submitted signals (default: the stored ones), and compares in constant time.
        Returns only {valid}; never the key or the expected hash. valid is false when no signed record exists.

        Signing key id (kid): each evidence record stores the key id that signed it in audit_kid. New records are
        signed with the active kid, which is now v2. Older records keep their own kid (a record with no audit_kid is
        the legacy v1), and this route always verifies with the record's own kid, so evidence signed before the
        rotation still verifies. audit_kid is stored on the record; the evidence bundle and this response do not
        return it.
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/EvidenceVerify' } } } }
      responses:
        '200': { description: Verification result, content: { application/json: { schema: { type: object, required: [valid], properties: { valid: { type: boolean } } } } } }
        '400': { description: invalid_json, content: { application/json: { schema: { $ref: '#/components/schemas/PartnerApiError' } } } }
        '401': { description: missing or invalid key, content: { application/json: { schema: { $ref: '#/components/schemas/PartnerApiError' } } } }
        '404': { description: "not_found — unknown event, or another partner's or environment's", content: { application/json: { schema: { $ref: '#/components/schemas/PartnerApiError' } } } }
        '409': { description: not_resolved — the event has not resolved yet, content: { application/json: { schema: { $ref: '#/components/schemas/PartnerApiError' } } } }
        '413': { description: payload_too_large — body over 100000 bytes, content: { application/json: { schema: { $ref: '#/components/schemas/PartnerApiError' } } } }
        '422': { description: validation_error, content: { application/json: { schema: { $ref: '#/components/schemas/PartnerApiError' } } } }
  /v1/sandbox/fixture:
    post:
      tags: [sandbox]
      operationId: sandboxFixture
      summary: Run the public sandbox fixture; returns a settled or a held event
      description: |
        Public, no key, stateless: nothing is read or stored, and event_id and settlement_id are new random UUIDs on
        every call. Only {"hold": true} returns the held fixture; any other body, or none, returns the settled one.
        Responses carry Access-Control-Allow-Origin https://pllay.io, so browsers on other origins are blocked.
        Sandbox fixture, not production proof. The function root (POST /) answers the same way.
      security: []
      requestBody: { content: { application/json: { schema: { type: object, properties: { hold: { type: boolean } } } } } }
      responses:
        '200':
          description: A canned event. state settled, or state held (waiting, not a success; nobody is paid).
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Event' }
              examples:
                settled:
                  summary: '{"hold": false} — as returned by the deployed function'
                  value: { event_id: 5d0e8a14-3b7c-4f29-a6d1-9c2e47b0f385, type: duel, path: vod, state: settled, spec: { title: Sandbox Fixture, market: sandbox }, outcome: yes, confidence: 0.987, threshold: 0.9, model_version: sandbox-fixture-1, evidence_uri: 'https://gatwzvsfzlhqzisgqlye.supabase.co/functions/v1/oracle-settlement/v1/sandbox/fixture/evidence?hold=0', settlement_id: 7f3ac91e-2b4d-4e60-8a15-c0d9e3f1a762, reversal_settlement_id: null, reviewer_id: null, stake_ref: null, notional_minor: 0, reason: null }
                held:
                  summary: '{"hold": true} — waiting state, nobody is paid'
                  value: { event_id: c8a24e71-0b36-4f95-a1d2-6e9b5f3c7d04, type: duel, path: vod, state: held, spec: { title: Sandbox Fixture, market: sandbox }, outcome: null, confidence: null, threshold: 0.9, model_version: null, evidence_uri: null, settlement_id: null, reversal_settlement_id: null, reviewer_id: null, stake_ref: null, notional_minor: 0, reason: fixture_hold }
  /v1/sandbox/fixture/evidence:
    get:
      tags: [sandbox]
      operationId: sandboxFixtureEvidence
      summary: Evidence bundle for the sandbox fixture
      description: Public, no key, stateless and deterministic. hold=1 returns the held bundle; anything else the settled one.
      security: []
      parameters:
        - { name: hold, in: query, required: false, schema: { type: string, enum: ['0', '1'] } }
      responses:
        '200':
          description: Fixture evidence bundle
          content:
            application/json:
              schema: { $ref: '#/components/schemas/EvidenceBundle' }
              example: { schema: pllay.evidence.v1, event_id: null, settlement_id: null, state: settled, path: vod, outcome: 'yes', confidence: 0.987, threshold: 0.9, margin: 0.087, model_version: sandbox-fixture-1, reviewer_id: null, window: { start_s: 0, end_s: 30, note: illustrative fixture window }, signals: [{ name: hud_readable, value: true }, { name: result_banner, value: VICTORY, confidence: 0.95 }], environment: sandbox, label: 'Sandbox fixture · not production proof', generated_at: '2026-01-01T00:00:00.000Z' }
webhooks:
  event.settled: { post: { operationId: event_settled_webhook, summary: The event is settled (final)., description: See x-delivery. Sent on POST /settle when the result settles., requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } } }, responses: { '200': { description: Any 2xx is an ack } } } }
  event.held: { post: { operationId: event_held_webhook, summary: "The event is held: waiting for review, NOT a settlement.", description: "See x-delivery. Sent on POST /hold, and on POST /settle when the corroboration policy holds. Not final: outcome and settlement_id are null, nobody is paid, and event.settled or event.voided follows.", requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } } }, responses: { '200': { description: Any 2xx is an ack } } } }
  event.reversed: { post: { operationId: event_reversed_webhook, summary: A settled event was reversed., description: "See x-delivery. Sent when an overturned dispute reverses the result. POST /v1/events/{id}/reverse does not write a reversal. settlement_id is the original; reversal_settlement_id is the reversal.", requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } } }, responses: { '200': { description: Any 2xx is an ack } } } }
  event.voided: { post: { operationId: event_voided_webhook, summary: The event was voided with no outcome. Nobody is paid., description: See x-delivery. Sent on POST /void., requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/Event' } } } }, responses: { '200': { description: Any 2xx is an ack } } } }
x-delivery:
  events: [event.settled, event.held, event.reversed, event.voided]
  body: The Event object itself, with no envelope. The event name is in the X-Webhook-Event header. lock and create send nothing.
  targets: Every enabled webhook URL registered for your partner for that event name.
  headers:
    X-Webhook-Event: event.settled | event.held | event.reversed | event.voided
    X-Webhook-Signature: 'Deprecated. sha256=<hex> of the raw request body. It does not protect against replay; use X-Pllay-Signature.'
    X-Webhook-Timestamp: Unix seconds.
    X-Pllay-Timestamp: Unix seconds, the same value as t.
    X-Pllay-Delivery: Stable id for this delivery. Retries of the same delivery reuse it and reuse t. Save it before you act and ignore a repeat.
    X-Pllay-Event: The event name, the same value as X-Webhook-Event.
    X-Pllay-Signature: 't=<unix seconds>,v1=<hex>. v1 is the HMAC-SHA256 of "<t>.<raw body>" with the webhook secret. During a secret rotation the header carries two v1 values (current, then previous); accept the delivery when any v1 matches a secret you hold. Reject a t more than 300 seconds from your clock.'
  timeout_seconds: 30
  attempts: 3
  retry: Retried only on a 5xx response, a timeout or a network error, waiting 1 s then 4 s between attempts. Any other non-2xx (4xx, 3xx) is final and not retried. Any 2xx is an ack.
  timing: Delivery runs inside the API call that changed the state, so that call returns only after delivery finishes or gives up.
  after_failure: A failed delivery is recorded in the delivery log. There is no automatic re-delivery after the three attempts; replay is a separate partner-key route, not part of this contract.
x-pllay-state-machine:
  open: { meaning: Created. Not resolved., entered_by: POST /v1/events, next: [locked, voided], webhook: null }
  locked: { meaning: Closed to new positions. Not resolved., entered_by: 'POST /v1/events/{id}/lock', next: [held, settled, voided], webhook: null }
  held: { meaning: "WAITING. Not a success and not a settlement: not final, routed to human review, nobody is paid. Later becomes settled or voided.", entered_by: "POST /v1/events/{id}/hold, or POST /v1/events/{id}/settle when the corroboration policy holds", next: [settled, voided], webhook: event.held }
  settled: { meaning: Final. outcome and settlement_id are set., entered_by: 'POST /v1/events/{id}/settle', next: [reversed], webhook: event.settled }
  reversed: { meaning: Terminal. A settled event undone by a new entry; settlement_id is kept and reversal_settlement_id is added., entered_by: 'POST /v1/events/{id}/dispute', next: [], webhook: event.reversed }
  voided: { meaning: Terminal. Closed with no outcome. Nobody is paid., entered_by: 'POST /v1/events/{id}/void', next: [], webhook: event.voided }
x-pllay-settle-rule:
  threshold: "Set by PLLAY. The working settle body is {} plus an optional vision_run_id. Clients must not send outcome, confidence, threshold, model_version, reviewer_id, evidence or evidence_uri. The server rejects them with 422 server_locked_field, or in transitional mode ignores them and returns a warnings entry. outcome is yes, no or void."
  title_certification: "spec.game_slug names an auto-settle title, such as fortnite. spec.pov_side (home or away) is required when game_slug is dota2 or rocketleague. A title that is not offered for auto-settlement is refused with 403 certification_blocked and the message Title not offered for auto-settlement. When the event has a title, the title_effective_path RPC decides: not_offered → 403 certification_blocked; human_confirm → 422 certification_review_required (send hold); otherwise settle continues."
  live: reviewer_id is set by PLLAY. Clients must not send it.
  corroboration: "spec.corroboration {require_agreeing (default 0), max_disagreement (default 0.3), video_only_max_notional_minor (default null)}. With the defaults, the primary video read alone settles. Weighted disagreement above max_disagreement holds with reason source_conflict; fewer agreeing secondary sources than require_agreeing, or a video-only call above the notional cap, holds with reason corroboration_required. A hold here returns 200 with state held."
  vision_verify_review_gate: "Separate from this contract: partner-api Vision verification jobs (POST /v1/vision/verify). With platform_config settlement_qa_enabled on, a result is held for a person (shown to the partner as status processing, no completion sent) when its tier is CONFIRM, its confidence is missing or below settlement_qa_min_confidence (90 on a 0–100 scale), or it has no evidence record. The switch is off by default in the migration; its production value is configuration, not code."
x-pllay-not-live:
  hash_anchoring: Off. ORACLE_ANCHOR_ENABLED is not true, so nothing is anchored and nothing settles on-chain. Settle still writes receipt rows with status stored, so GET /v1/events/{id}/receipt can return anchoring_enabled false with a non-empty receipts list.
  demo: supabase/functions/demo ("Try it on a clip") is dark. Every route returns 503 demo_disabled, so it is not documented here.
  self_serve_signup: Dark. Done in the developer portal through RPCs, not a REST endpoint, and off unless platform_config self_serve_signup_enabled is true.
