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

# Run inference (optionally streaming via SSE)

> Execute inference through the LucidLayer execution gateway. Supports both streaming (SSE) and non-streaming responses. A cryptographic receipt is generated for each successful inference.




## OpenAPI

````yaml /openapi-spec.yaml post /v1/run/inference
openapi: 3.0.3
info:
  title: LucidLayer API
  version: 1.0.0
  description: >
    LucidLayer API — the verifiable AI execution layer.


    Blockchain-anchored infrastructure giving AI assets (models, agents, tools,
    compute, datasets)

    provable identity, cryptographic receipts, and reputation backed by real
    traffic data.


    **Open-source and self-hostable.** Run your own instance with `docker
    compose up`

    or `npm start` (port 3001). The SDK defaults to `http://localhost:3001` — no
    cloud

    account required.


    This OpenAPI spec is the source of truth for all backend routes and is used
    to

    generate SDK clients via [Speakeasy](https://speakeasy.com).


    ## Version Strategy


    | Prefix | Status | Description |

    |--------|--------|-------------|

    | `/v1/*` | **Stable** | Core API — passports, receipts, epochs, payouts,
    inference, agent deployment. Production-ready and covered by semver
    guarantees. |

    | `/v2/*` | **Stable** | Cross-chain and reputation APIs — EVM multi-chain,
    ERC-8004, pluggable reputation. Production-ready. |

    | `/api/agents/*` | **Deprecated** | Legacy agent MMR orchestration.
    Retained for SDK backward compatibility only. Migrate to `/v1/agents/*`
    (AgentDeploy, AgentMirror). Will be removed in a future major version. |

    | `/health/*` | **Stable** | System health probes — not versioned
    (infrastructure endpoints). |


    ### Migration Path (legacy `/api/agents/*` to `/v1/agents/*`)


    1. Replace `init_agent` + `process_agent_epoch` with `lucid_deploy_agent`
    (one-click deployment).

    2. Replace `generate_agent_proof` with `lucid_get_agent_proof` /
    `lucid_get_agent_run_proof` (AgentMirror).

    3. Replace `get_agent_stats` / `get_agent_history` with
    `lucid_get_agent_receipts` + `lucid_get_agent_epoch`.

    4. All legacy operationIds will be removed when the next major version
    ships.


    ## Route Groups


    - `/v1/*` — Passports, Match, Run, Receipts, Epochs, Payouts, Compute

    - `/v1/agents/*` — Agent Deployment, Wallet, Revenue, Mirror
    (receipts/proofs)

    - `/v1/a2a/*` — A2A Protocol (Agent-to-Agent)

    - `/v1/config/*` — Payment configuration and grants

    - `/v2/chains/*` — Cross-chain status and routing

    - `/v2/agents/*` — ERC-8004 agent registration and reputation

    - `/v2/reputation/*` — Pluggable reputation scoring, cross-chain aggregation

    - `/v2/payouts/*` — On-chain payout execution

    - `/health/*` — System health and dependency checks

    - `/api/agents/*` — Legacy agent MMR orchestration (deprecated)
servers:
  - url: http://localhost:3001
    description: Local / self-hosted (default for open-source users)
    x-speakeasy-server-id: local
  - url: https://{host}:{port}
    description: Self-hosted instance (custom host and port)
    x-speakeasy-server-id: self-hosted
    variables:
      host:
        default: localhost
        description: Hostname or IP of your Lucid instance
      port:
        default: '3001'
        description: Port your Lucid instance listens on
  - url: https://api.lucid.foundation
    description: Managed cloud (Raijin Labs hosted)
    x-speakeasy-server-id: cloud
security:
  - BearerAuth: []
  - {}
tags:
  - name: Passports
    description: >-
      AI asset identity — create, list, update, delete
      model/compute/tool/dataset/agent passports
  - name: Match
    description: Policy-based compute matching and route planning
  - name: Run
    description: OpenAI-compatible inference (chat completions) and model listing
  - name: Receipts
    description: Cryptographic receipts — create, verify, and generate MMR inclusion proofs
  - name: Epochs
    description: Epoch lifecycle — creation, finalization, on-chain anchoring, and retry
  - name: Payouts
    description: Revenue split calculation and payout execution (basis-point math)
  - name: Compute
    description: Compute node heartbeat registration and health monitoring
  - name: Health
    description: System health — liveness, readiness, and per-dependency status checks
  - name: Agents
    description: >-
      DEPRECATED: Legacy agent MMR orchestration (use AgentDeploy, AgentMirror
      instead)
  - name: Shares
    description: Share token launch and revenue airdrop for fractional AI asset ownership
  - name: Escrow
    description: Cross-chain escrow lifecycle — create, release, dispute, and query
  - name: Disputes
    description: Escrow dispute resolution — open, submit evidence, resolve, appeal
  - name: Paymaster
    description: >-
      ERC-4337 gas sponsorship — sponsor transactions, estimate fees, check
      rates
  - name: Identity
    description: >-
      Cross-chain identity bridging — CAIP-10 linking, resolution, and chain
      discovery
  - name: TBA
    description: ERC-6551 Token Bound Accounts — create and query agent wallets
  - name: Modules
    description: >-
      ERC-7579 module management — install, uninstall, and configure
      policy/payout modules
  - name: zkML
    description: >-
      Zero-knowledge ML — prove inference, verify proofs, register models
      on-chain
  - name: Payments
    description: >-
      x402 payment configuration — pricing, facilitators, grants, and
      subscription
  - name: AgentDeploy
    description: >-
      Agent deployment lifecycle — deploy, status, logs, scale, terminate across
      6 targets
  - name: AgentWallet
    description: Agent PDA wallet — balance, send, policy limits, and transaction history
  - name: AgentRevenue
    description: >-
      Agent revenue pools — earnings tracking, airdrop triggers, and pool
      queries
  - name: A2A
    description: Google A2A protocol — agent cards, task submission, and task lifecycle
  - name: Reputation
    description: >-
      Pluggable reputation scoring — algorithms, compute scores, and composite
      aggregation
  - name: CrossChain
    description: >-
      EVM multi-chain operations — chain status, ERC-8004 registration,
      cross-chain reputation and payouts
  - name: AgentMirror
    description: >-
      Read-only agent proof endpoints — receipts, epochs, and MMR proofs (admin
      auth required)
  - name: Memory
    description: >-
      Agent memory — episodic, semantic, procedural, entity, trust-weighted,
      temporal types with hash-chain provenance
  - name: Anchoring
    description: >-
      DePIN anchoring control plane — query, verify, and trace artifact anchor
      records
  - name: AgentLaunch
    description: >-
      Agent activation — launch via image or base runtime, blue-green rollout,
      promotion, and rollback
  - name: Webhooks
    description: >-
      Deployment webhook receivers — normalizes provider-specific callbacks into
      deployment events
paths:
  /v1/run/inference:
    post:
      tags:
        - Run
      summary: Run inference (optionally streaming via SSE)
      description: >
        Execute inference through the LucidLayer execution gateway. Supports
        both streaming (SSE) and non-streaming responses. A cryptographic
        receipt is generated for each successful inference.
      operationId: lucid_run_inference
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InferenceRequest'
      responses:
        '200':
          description: Non-streaming inference result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InferenceResult'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { RaijinLabsLucidAi } from "raijin-labs-lucid-ai";

            const raijinLabsLucidAi = new RaijinLabsLucidAi();

            async function run() {
              const result = await raijinLabsLucidAi.run.inference({});

              console.log(result);
            }

            run();
components:
  schemas:
    InferenceRequest:
      type: object
      properties:
        model_passport_id:
          type: string
        model:
          type: string
        prompt:
          type: string
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
        max_tokens:
          type: integer
        temperature:
          type: number
        top_p:
          type: number
        top_k:
          type: integer
        stop:
          type: array
          items:
            type: string
        stream:
          type: boolean
        policy:
          $ref: '#/components/schemas/Policy'
        compute_passport_id:
          type: string
        trace_id:
          type: string
        request_id:
          type: string
    InferenceResult:
      type: object
      required:
        - success
        - run_id
        - tokens_in
        - tokens_out
        - ttft_ms
        - total_latency_ms
        - model_passport_id
        - compute_passport_id
        - runtime
      properties:
        success:
          type: boolean
        run_id:
          type: string
        request_id:
          type: string
        trace_id:
          type: string
        text:
          type: string
        finish_reason:
          type: string
        tokens_in:
          type: integer
        tokens_out:
          type: integer
        ttft_ms:
          type: integer
        total_latency_ms:
          type: integer
        model_passport_id:
          type: string
        compute_passport_id:
          type: string
        runtime:
          type: string
        policy_hash:
          type: string
        receipt_id:
          type: string
        used_fallback:
          type: boolean
        fallback_reason:
          type: string
        error:
          type: string
        error_code:
          type: string
    ChatMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - function
        content:
          type: string
        name:
          type: string
        function_call:
          type: object
          properties:
            name:
              type: string
            arguments:
              type: string
    Policy:
      type: object
      required:
        - policy_version
      additionalProperties: false
      properties:
        policy_version:
          type: string
          description: Policy schema version, e.g. '1.0'
        allow_regions:
          type: array
          items:
            type: string
        residency_required:
          type: boolean
        attestation:
          type: object
          additionalProperties: false
          properties:
            attestation_required:
              type: boolean
            require_cc_on:
              type: boolean
            fallback_allowed:
              type: boolean
        latency:
          type: object
          additionalProperties: false
          properties:
            p95_ms_budget:
              type: integer
            hard_timeout_ms:
              type: integer
        cost:
          type: object
          additionalProperties: false
          properties:
            max_price_per_1k_tokens_usd:
              type: number
            spot_only:
              type: boolean
        privacy:
          type: object
          additionalProperties: false
          properties:
            store_inputs:
              type: boolean
            redact_pii:
              type: boolean
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
        error:
          type: string
        message:
          type: string
        error_code:
          type: string
        details: {}
  responses:
    UnprocessableEntity:
      description: Unprocessable Entity
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: Internal Server Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ServiceUnavailable:
      description: Service Unavailable
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Lucid API key (lk_live_... or lk_test_...)

````