Skip to main content

call

Call an RPC method on a MOD service via the engine's HTTP API. Works in both browser (WebView) and Node.js environments.

Signature

rpc.call<T = unknown>(options: RpcCallOptions): Promise<T>

Parameters

ParameterTypeDescription
options.modNamestringName of the target MOD
options.methodstringRPC method name to invoke
options.bodyunknownOptional request body passed to the method handler

Returns

Promise<T> — The parsed JSON response from the MOD method handler.

Error Responses

The engine proxy may return the following errors:

StatusCondition
404Method not found on the target MOD
502MOD service unreachable
503MOD not registered (service not running)
504Request timed out

Example

import { rpc } from "@hmcs/sdk/rpc";

// Call with a request body
const result = await rpc.call<{ greeting: string }>({
modName: "voicevox",
method: "speak",
body: { text: "Hello!" },
});
console.log(result.greeting);

// Call without a body
const status = await rpc.call<{ running: boolean }>({
modName: "voicevox",
method: "status",
});