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

# Preview a source

> Fetches and evaluates a source the way a node would, without signing anything, and returns each input's response, the decoded fields and the 32 bytes nodes would sign. The source is run twice, one second apart, and `stable` says whether both gave the same value: a field that moves between fetches can keep nodes from agreeing. A failure at a stage (fetch, decode, transform, assertion, encoding) is a 200 with `error`, so the response it failed on can be shown.

A source whose inputs are all chain reads (evm, starknet, svm) is run on a node instead, as a dry-run, twice a second apart: each input reports the block or slot it read and its decoded fields (no body), `secondInputs` where the second run read, and a `keccak256` output its `preimage`. A chain the gateway does not serve is 422, a source that mixes http and chain inputs is 422, and 503 with `Retry-After` when no node can run it now. A private source with `{{secret.NAME}}` placeholders is 422, and a provider host paid per fetch (x402) is 422. A source on a sponsored provider route is fetched with the gateway's key, which never appears in the response. Requests that reach a non-public address are refused by the fetcher. Rate-limited per client address (429 with `Retry-After`); the gateway answers 503 with `Retry-After` when previews are at capacity. Nothing is signed, charged or recorded.

Fetches and evaluates a source the way a node would, without signing anything, and returns each input's response, the decoded fields and the 32 bytes nodes would sign. Use it to check a source before you pay for a round. It is served when [`GET /v1/info`](https://docs.molpha.io/gateways/api/info) reports `preview: true`, and it backs the Playground in the web app.

Send `{"source": {...}}`, the same document as the `source` of an execute request.

* **Two runs.** The source runs twice, one second apart. `stable` is `false` when the second run gave a different value or failed, and `second` says what it gave. A value that moves between fetches can keep nodes from agreeing in exact mode.
* **Failures are answers.** A failure at a stage (fetch, decode, transform, assertion, encoding, policy) is a `200` with `error` (`stage`, `input`, `message`), and the response it failed on is still in `inputs`.
* **Policies.** For a source with a `policy`, `policy` shows each candidate, whether it qualified, the combined value and the outcome of the first run.
* **Chain sources.** A source whose inputs are all chain reads (`evm`, `starknet`, `svm`) runs on a node as a dry-run instead: each input reports the block or slot it read and its decoded fields, with no body. Only the chains in `previewChains` are run.

Refused with `422`: a chain the gateway does not serve, a source that mixes http and chain inputs, a private source (`{{secret.NAME}}`), and a provider host paid per fetch (x402). The fetcher refuses loopback, private and other non-public addresses. Requests are limited per client address (`429` with `Retry-After`); at capacity, or when no node can run a chain source, the answer is `503` with `Retry-After`. A body over 64 KiB is `413`.

Nothing is signed, charged or recorded, and a preview never pays a source.


## OpenAPI

````yaml gateway-openapi.yaml POST /v1/source/preview
openapi: 3.1.0
info:
  contact: {}
  description: >-
    HTTP entry point to the Molpha oracle protocol. The gateway dispatches
    oracle rounds to nodes over libp2p, waits for threshold Schnorr signatures
    delivered directly by the nodes, and returns signed payloads. The x402
    endpoints (`/v1/x402/*`) are always served and require a configured trusted
    facilitator.
  title: Molpha Gateway API
  version: '1.0'
  x-mint:
    metadata:
      description: >-
        Run oracle rounds, sign in, preview sources and read the node set of a
        Molpha gateway.
servers:
  - url: https://gateway.molpha.io
    description: Devnet
security: []
tags:
  - name: health
    description: Liveness
  - name: gateway
    description: Gateway identity, program and authentication settings
  - name: nodes
    description: The on-chain node set
  - name: providers
    description: Integrated data providers
  - name: round
    description: Subscription and delegate rounds
  - name: session
    description: Sign-in sessions (served when `GET /v1/info` reports `sessionAuth` true)
  - name: source
    description: Unsigned source preview and simulation
  - name: x402
    description: x402 pay-per-request rounds
paths:
  /v1/source/preview:
    post:
      tags:
        - source
      summary: Preview a source
      description: >-
        Fetches and evaluates a source the way a node would, without signing
        anything, and returns each input's response, the decoded fields and the
        32 bytes nodes would sign. The source is run twice, one second apart,
        and `stable` says whether both gave the same value: a field that moves
        between fetches can keep nodes from agreeing. A failure at a stage
        (fetch, decode, transform, assertion, encoding) is a 200 with `error`,
        so the response it failed on can be shown.


        A source whose inputs are all chain reads (evm, starknet, svm) is run on
        a node instead, as a dry-run, twice a second apart: each input reports
        the block or slot it read and its decoded fields (no body),
        `secondInputs` where the second run read, and a `keccak256` output its
        `preimage`. A chain the gateway does not serve is 422, a source that
        mixes http and chain inputs is 422, and 503 with `Retry-After` when no
        node can run it now. A private source with `{{secret.NAME}}`
        placeholders is 422, and a provider host paid per fetch (x402) is 422. A
        source on a sponsored provider route is fetched with the gateway's key,
        which never appears in the response. Requests that reach a non-public
        address are refused by the fetcher. Rate-limited per client address (429
        with `Retry-After`); the gateway answers 503 with `Retry-After` when
        previews are at capacity. Nothing is signed, charged or recorded.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PreviewRequest'
        description: Source to preview
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PreviewResponse'
        '400':
          description: Malformed body or source
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: A source the preview does not run
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: >-
            Too many previews from this address, or the sponsored call budget is
            spent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Previews at capacity, or no node can run a chain source now
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    PreviewRequest:
      properties:
        source:
          description: Source is a source document, as the `source` of an execute request.
          type: object
      type: object
    PreviewResponse:
      properties:
        data:
          $ref: '#/components/schemas/PreviewData'
        status:
          example: ok
          type: string
      type: object
    ErrorResponse:
      properties:
        error:
          example: validation failed
          type: string
      type: object
    PreviewData:
      properties:
        error:
          allOf:
            - $ref: '#/components/schemas/PreviewError'
          description: >-
            Error is the stage the first fetch failed at; absent when it gave a
            value.
        inputs:
          items:
            $ref: '#/components/schemas/PreviewInput'
          type: array
        policy:
          allOf:
            - $ref: '#/components/schemas/PreviewPolicy'
          description: >-
            Policy is what the source's policy concluded; absent for a source
            without a policy. It is set

            also when the run failed, for want of a fallback (error.stage
            "policy inconclusive") or otherwise.
        second:
          description: >-
            Second says what the second fetch gave when it was not the same
            value.
          type: string
        secondInputs:
          description: >-
            SecondInputs say where the second run of a chain source read each
            input; absent for http sources.
          items:
            $ref: '#/components/schemas/PreviewInputRead'
          type: array
        source:
          description: >-
            Source is the source in canonical form: what was run, and what an
            execute request sends.
          type: object
        sourceId:
          description: SourceID is the keccak256 of the canonical source, hex without 0x.
          type: string
        stable:
          description: >-
            Stable is true when a second fetch a second later encoded the same
            value.
          type: boolean
        timestampMs:
          description: >-
            TimestampMs is the round timestamp the first fetch was evaluated at
            (unix ms on the 100 ms grid):

            what $ts, $tsMs and freshness rules read. Absent for a chain source,
            run on a node at its own time.
          example: 1795000000500
          type: integer
        value:
          allOf:
            - $ref: '#/components/schemas/PreviewValue'
          description: >-
            Value is what nodes would sign, from the first fetch; absent when it
            failed.
      type: object
    PreviewError:
      properties:
        input:
          type: string
        message:
          type: string
        stage:
          example: fetching data
          type: string
      type: object
    PreviewInput:
      properties:
        block:
          description: >-
            Block is the block (evm, starknet) or slot (svm) a chain input was
            read at.
          type: integer
        body:
          description: >-
            Body is the response, or the upstream's error text, as text, or hex
            when bodyHex is set.
          type: string
        bodyHex:
          type: boolean
        durationMs:
          type: integer
        error:
          description: Error is a chain input's own failure.
          type: string
        fields:
          items:
            $ref: '#/components/schemas/PreviewField'
          type: array
        kind:
          enum:
            - http
            - evm
            - starknet
            - svm
          type: string
        method:
          type: string
        name:
          type: string
        observedAtMs:
          description: >-
            ObservedAtMs is when a chain input's state was observed, unix
            milliseconds.
          type: integer
        status:
          description: the upstream's HTTP status when it refused
          type: integer
        truncated:
          type: boolean
        url:
          type: string
      type: object
    PreviewPolicy:
      properties:
        agg:
          description: Agg is the combined value; absent when the combine step failed.
          example: '65000.12'
          type: string
        candidates:
          items:
            $ref: '#/components/schemas/PreviewPolicyCandidate'
          type: array
        'n':
          description: N is the number of qualifying candidates.
          type: integer
        outcome:
          description: >-
            Outcome is conclusive or inconclusive; absent when the policy
            refused before reaching one.
          enum:
            - conclusive
            - inconclusive
          type: string
        reason:
          description: >-
            Reason is the INCONCLUSIVE reason code (0x01 insufficient sources,
            0x02 spread, 0x03 primary

            disagrees, 0x10 and up an inconclusiveIf entry); absent when
            conclusive.
          example: '0x01'
          type: string
        signed:
          description: >-
            Signed is true when the outcome was inconclusive and the fallback
            was signed: value is then the fallback.
          type: boolean
      type: object
    PreviewInputRead:
      properties:
        block:
          type: integer
        name:
          type: string
        observedAtMs:
          type: integer
      type: object
    PreviewValue:
      properties:
        decimals:
          example: 8
          type: integer
        display:
          example: '67412.18'
          type: string
        encoded:
          example: '0x000000000000000000000000000000000000000000000000000006219ec58280'
          type: string
        preimage:
          description: >-
            Preimage is what a keccak256 output hashed, 0x hex; absent for other
            outputs.
          type: string
        type:
          example: int256
          type: string
      type: object
    PreviewField:
      properties:
        name:
          type: string
        type:
          enum:
            - decimal
            - string
            - bool
            - bytes
            - 'null'
          type: string
        value:
          type: string
      type: object
    PreviewPolicyCandidate:
      properties:
        error:
          description: Error is fetch or eval when an error disqualified the candidate.
          enum:
            - fetch
            - eval
          type: string
        errorMessage:
          type: string
        name:
          type: string
        qualified:
          type: boolean
        rule:
          description: >-
            Rule is the index of the first rule that was false; absent when none
            was.
          type: integer
        value:
          description: Value is a qualified candidate's value; absent for a chain source.
          type: string
      type: object

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.