Skip to main content

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 options
object
required
Returns
PaymentChannelHttpClient
Configured HTTP payer client

PaymentChannelHttpClient.requestWithPayment

Create a payable request and return both response and payment promises. Inputs
"GET"|"POST"|"PUT"|"DELETE"|"PATCH"
required
HTTP method
string
required
Relative URL or path
RequestInit?
Headers, body, and signal
Returns
string
Correlation id
Promise
Raw fetch response promise
Promise
Resolved payment info (PaymentInfo or undefined)
Promise
Resolves to object with data and payment
function
Cancel the request

PaymentChannelHttpClient.request

Convenience wrapper returning only the HTTP response. Inputs
"GET"|"POST"|"PUT"|"DELETE"|"PATCH"
required
HTTP method
string
required
Relative URL or path
RequestInit?
Request options
Returns
Promise
Raw fetch response promise

PaymentChannelHttpClient.requestAndWaitForPayment

Wait for both HTTP response and payment resolution. Inputs
"GET"|"POST"|"PUT"|"DELETE"|"PATCH"
required
HTTP method
string
required
Relative URL or path
RequestInit?
Request options
Returns
Response
Raw fetch response
PaymentInfo | undefined
Payment result (if billed)

PaymentChannelHttpClient.get/post/put/patch/delete

JSON helpers that parse the response and return { data, payment }. Inputs
string
required
Relative URL or path
any?
JSON body for POST/PUT/PATCH
RequestInit?
Request options
Returns
any
Parsed JSON payload
PaymentInfo | undefined
Payment result (if billed)

PaymentChannelHttpClient.getPendingSubRAV

Return the latest unsigned proposal (if any). Inputs
void
No input parameters
Returns
SubRAV | null
Current pending SubRAV

PaymentChannelHttpClient.getPayerClient

Access the low-level payer client. Inputs
void
No input parameters
Returns
PaymentChannelPayerClient
Low-level client

PaymentChannelHttpClient.healthCheck

Check service health (free). Inputs
void
No input parameters
Returns
HealthResponse
Server health payload

PaymentChannelHttpClient.recoverFromService

Recover latest SubRAV from service after failures. Inputs
void
No input parameters
Returns
RecoveryResponse
Recovery payload

PaymentChannelHttpClient.logoutCleanup

Abort pending requests, reset state, and optionally clear persisted mapping. Inputs
boolean?
default:"true"
Delete persisted mapping store
string?
Optional note for logs
Returns
void
No return value

MCP Client

PaymentChannelMcpClient (constructor)

Create an MCP client with payment channels.
object
required
PaymentChannelMcpClient

PaymentChannelMcpClient.callTool

Call an MCP tool; payment handled internally.
string
required
any?
Tool params
object
Object containing content: any[]

PaymentChannelMcpClient.callToolWithPayment

Call a tool and return both business content and payment info.
string
required
any?
Tool params
string?
Correlation id
object
Object with content and optional payment

PaymentChannelMcpClient.listTools

List server tools with internal reserved params removed.
object?
Optional flags (e.g., includeBuiltinTools)
record
Map of tool name to definition

PaymentChannelMcpClient.tools

Return AI SDK compatible ToolSet.
ToolSet

PaymentChannelMcpClient.listPrompts / loadPrompt

Prompt discovery helpers.
string?
For loadPrompt
any?
Prompt args
any | string

PaymentChannelMcpClient.listResources / listResourceTemplates / readResource

Resource discovery helpers.
string | object?
For readResource (string or uri object)
any[] | any

PaymentChannelMcpClient.getPendingSubRAV / commitSubRAV

Inspect or commit pending SubRAV.
SignedSubRAV
For commitSubRAV
SubRAV | object | null
Signed subRAV or success marker or null

PaymentChannelMcpClient.healthCheck / recoverFromService

Free endpoints for health and recovery.
HealthResponse | RecoveryResponse

PaymentChannelMcpClient.close / clearPersistedState / getPayerClient / getTransactionStore

Lifecycle and accessors.
void | PaymentChannelPayerClient | TransactionStore

Streaming

SSE/NDJSON responses include a payment frame that the client extracts and removes transparently. Use the same code paths for streaming and non-streaming.