Overview
@nuwa-ai/payment-kit implements Nuwa’s unidirectional payment channels (NIP-4) for HTTP and MCP. It manages channel lifecycle, SubRAV receipts, streaming, and settlement.
Install
HTTP Client
createHttpClient
Factory that builds a PaymentChannelHttpClient from an IdentityEnv. Inputs Creation optionsConfigured HTTP payer client
PaymentChannelHttpClient.requestWithPayment
Create a payable request and return both response and payment promises. InputsHTTP method
Relative URL or path
Headers, body, and signal
Correlation id
Raw fetch response promise
Resolved payment info (PaymentInfo or undefined)
Resolves to object with
data and paymentCancel the request
PaymentChannelHttpClient.request
Convenience wrapper returning only the HTTP response. InputsHTTP method
Relative URL or path
Request options
Raw fetch response promise
PaymentChannelHttpClient.requestAndWaitForPayment
Wait for both HTTP response and payment resolution. InputsHTTP method
Relative URL or path
Request options
Raw fetch response
Payment result (if billed)
PaymentChannelHttpClient.get/post/put/patch/delete
JSON helpers that parse the response and return{ data, payment }.
Inputs
Relative URL or path
JSON body for POST/PUT/PATCH
Request options
Parsed JSON payload
Payment result (if billed)
PaymentChannelHttpClient.getPendingSubRAV
Return the latest unsigned proposal (if any). InputsNo input parameters
Current pending SubRAV
PaymentChannelHttpClient.getPayerClient
Access the low-level payer client. InputsNo input parameters
Low-level client
PaymentChannelHttpClient.healthCheck
Check service health (free). InputsNo input parameters
Server health payload
PaymentChannelHttpClient.recoverFromService
Recover latest SubRAV from service after failures. InputsNo input parameters
Recovery payload
PaymentChannelHttpClient.logoutCleanup
Abort pending requests, reset state, and optionally clear persisted mapping. InputsDelete persisted mapping store
Optional note for logs
No return value
MCP Client
PaymentChannelMcpClient (constructor)
Create an MCP client with payment channels.PaymentChannelMcpClient.callTool
Call an MCP tool; payment handled internally.Tool params
Object containing
content: any[]PaymentChannelMcpClient.callToolWithPayment
Call a tool and return both business content and payment info.Tool params
Correlation id
Object with
content and optional paymentPaymentChannelMcpClient.listTools
List server tools with internal reserved params removed.Optional flags (e.g., includeBuiltinTools)
Map of tool name to definition
PaymentChannelMcpClient.tools
Return AI SDK compatible ToolSet.PaymentChannelMcpClient.listPrompts / loadPrompt
Prompt discovery helpers.For loadPrompt
Prompt args
PaymentChannelMcpClient.listResources / listResourceTemplates / readResource
Resource discovery helpers.For readResource (string or
uri object)PaymentChannelMcpClient.getPendingSubRAV / commitSubRAV
Inspect or commit pending SubRAV.For commitSubRAV
Signed subRAV or success marker or null

