@nevermined-io/payments
    Preparing search index...

    Class MppAPI

    Machine Payments Protocol (MPP) module.

    Hierarchy

    • BasePaymentsAPI
      • MppAPI
    Index

    Constructors

    Properties

    accountAddress: string
    appId?: string
    currentOrganizationId: string | null
    environment: EnvironmentInfo
    environmentName: EnvironmentName
    heliconeApiKey: string
    isBrowserInstance: boolean = true
    nvmApiKey: string
    returnUrl: string
    scheme: "nvm"
    version?: string

    Backend API version (MAJOR.MINOR) pinned by this instance, set from options.version. When unset, every request defaults to LOCKED_API_VERSION.

    Methods

    • Performs an HTTP request, paying an MPP challenge if the endpoint returns one.

      The buyer needs no new plan, delegation or credential: the delegation that works for x402 works here unchanged.

      init.body, if set, must be replayable if the endpoint may challenge the request: a ReadableStream throws a typed PaymentsError once a 402 challenge actually requires a retry, since the stream cannot be resent. A request that is never challenged sends a stream body exactly once, exactly like plain fetch — the paid: false / untouched-response guarantee still holds. A string, Buffer/ArrayBuffer/typed array, URLSearchParams, FormData or Blob body all work unchanged either way.

      options.delegationConfig must carry a delegationId — this call refuses the deprecated inline create-on-the-fly shape (no delegationId) that X402TokenAPI.getX402AccessToken otherwise tolerates with a warning: the retry loop here can mint an access token twice per call, so that shape could silently create two delegations as a side effect of paying.

      Parameters

      Returns Promise<MppFetchResult>

      const { response, receipt } = await payments.mpp.fetch(
      'https://agent.example/ask',
      { method: 'POST', body: JSON.stringify({ q: 'hello' }) },
      { delegationConfig: { delegationId }, planId },
      )
    • It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.

      Returns string | undefined

      The account address extracted from the NVM API Key

    • Internal

      Returns the HTTP options required to query the backend.

      Parameters

      • method: string

        HTTP method.

      • Optionalbody: any

        Optional request body.

      • OptionalextraHeaders: Record<string, string>

        Optional per-call header overrides. Use { 'X-Current-Org-Id': orgId } to target a specific workspace for one call without mutating the instance-level pin.

      Returns any

      HTTP options object.

    • Mints an access token signed under the Nevermined-MPP EIP-712 domain.

      Same inputs and same settlement rail as X402TokenAPI.getX402AccessToken minus tokenVersion; the token verifies only on the MPP routes, which is what keeps the two protocols isolated.

      MPP carries no token version (nvm-monorepo#3266): its single-use unit is the challenge, not the token, so one MPP token is presented across many challenges by design. The parameter type says so, and a JavaScript caller that sends one anyway is refused before the request — the backend answers BCK.MPP.0007 for any value, 2 included.

      Parameters

      Returns Promise<{ accessToken: string }>

    • Returns the current organization context applied to every authenticated backend request via the X-Current-Org-Id header.

      null means "no pinned workspace" — the backend falls back to the caller's API-key tag or most-recent active membership.

      Returns string | null

    • Internal

      Get HTTP options for public backend requests (no authorization header). Converts body keys from snake_case to camelCase for consistency.

      Parameters

      • method: string

        HTTP method

      • Optionalbody: any

        Optional request body (keys will be converted to camelCase)

      Returns { body?: string; headers: Record<string, string>; method: string }

      HTTP options object

    • Mints the challenge a plan-protected endpoint returns with its 402.

      Each call returns a distinct challenge even for identical inputs — the id doubles as the burn idempotency key, so two requests sharing one would settle as a single burn.

      Parameters

      Returns Promise<{ challenge: string; id: string }>

    • Parses the NVM API Key to extract the account address.

      Returns { accountAddress: string; heliconeApiKey: string }

      PaymentsError if the API key is invalid.

    • Sets the organization context applied to every subsequent authenticated backend request via the X-Current-Org-Id header.

      Pass null to clear the pin and fall back to the backend default.

      Parameters

      • organizationId: string | null

        Org ID (e.g. org-…) or null to clear.

      Returns void