Skip to main content

Installation

Initialization

register_worker

Register the worker with a iii instance, returns a connected worker client. The WebSocket connection is established automatically in a dedicated background thread with its own tokio runtime. Call IIIClient::shutdown before the end of main to cleanly stop the connection and join the background thread. In Rust the process exits when main returns, terminating all threads, so shutdown() must be called while main is still running. Signature
address
&str
required
WebSocket URL of the III engine (e.g. ws://localhost:49134).
options
InitOptions
required
Configuration for worker metadata and OTel.

Methods

register_trigger

Bind a trigger configuration to a registered function. Signature
input
RegisterTriggerInput
required
Trigger registration input with trigger_type, function_id, and config.

register_function

Register a function with the engine. Argument order matches the Node and Python SDKs: (id, registration). Signature
id
impl Into<String>
required
Unique identifier for the function.
registration
RegisterFunction
required
Built via [RegisterFunction::new], [RegisterFunction::new_async], or [RegisterFunction::http]. Chain .description(...), .metadata(...), .request_format(...), .response_format(...) as needed.

trigger

Invoke a remote function. The routing behavior depends on the action field of the request:
  • No action: synchronous, waits for the function to return.
  • TriggerAction::Enqueue: async via named queue.
  • TriggerAction::Void: fire-and-forget.
Signature
request
impl Into<TriggerRequestWithMetadata>
required

register_trigger_type

Register a custom trigger type with the engine. Returns a TriggerTypeRef handle that can register triggers and functions with compile-time validated types. Signature
trigger_type
RegisterTriggerType<H, C, R>
required

unregister_trigger_type

Unregister a previously registered trigger type. Signature
id
impl Into<String>
required

get_connection_state

Get the current connection state. Signature

Example


shutdown

Shutdown the III client and wait for the connection thread to finish. This stops the connection loop, sends a shutdown signal, and joins the background connection thread. OpenTelemetry is flushed inside the connection thread before it exits. Signature

Example


shutdown_async

Shutdown the III client. This stops the connection loop and sends a shutdown signal, but it does not join connection_thread. This method returns without waiting for run_connection() to finish, making it safe to call from an async context without stalling the executor; shutdown blocks and joins the thread. The OpenTelemetry flush (telemetry::shutdown_otel()) still runs inside the connection thread after run_connection() returns, so it may not complete unless shutdown is used to join the thread. Signature

Example

Types

iii_sdk

EnqueueResult · InitOptions · RegisterFunction · RegisterTriggerType · TelemetryOptions

EnqueueResult

Result returned when a function is invoked with TriggerAction.Enqueue.
NameTypeRequiredDescription
message_receipt_idStringYesUnique receipt ID for the enqueued message.

InitOptions

Configuration options passed to register_worker.
NameTypeRequiredDescription
metadataOption<iii::WorkerMetadata>NoCustom worker metadata. Auto-detected if None.
headersOption<HashMap<String, String>>NoCustom HTTP headers sent during the WebSocket handshake.
otelOption<iii_helpers::observability::OtelConfig>NoOpenTelemetry configuration.

RegisterFunction

Function registration builder. The function ID is supplied separately at registration time via IIIClient::register_function, RegisterFunction only carries the handler and optional metadata. Constructors:
  • RegisterFunction::new: sync function. Accepts both typed handlers (schemas auto-extracted via schemars) and Fn(Value, Option<Value>) -> Result<Value, Error> closures. The second argument is the per-invocation metadata sidecar and is None when absent.
  • RegisterFunction::new_async: async equivalent of new.
  • RegisterFunction::http: function invoked over HTTP (Lambda, Cloudflare Workers, etc.).
Builder methods (all consume self):
  • description
  • metadata
  • request_format: overrides any auto-extracted schema.
  • response_format: overrides any auto-extracted schema.
NameTypeRequiredDescription
descriptionfn(desc: impl Into<String>) -> SelfYesSet the function description.
httpfn(config: HttpInvocationConfig) -> SelfYesCreate a registration for an HTTP-invoked function (Lambda, Cloudflare Workers, etc.). No local handler runs.
metadatafn(meta: Value) -> SelfYesSet function metadata.
newfn(f: F) -> SelfYesCreate a registration for a sync typed function.
new_asyncfn(f: F) -> SelfYesCreate a registration for an async typed function.
request_formatfn(schema: Value) -> SelfYesSet the request format schema. Overrides any auto-extracted schema.
response_formatfn(schema: Value) -> SelfYesSet the response format schema. Overrides any auto-extracted schema.

RegisterTriggerType

Builder for registering a custom trigger type with optional format schemas. Type parameters:
  • C tracks the trigger registration type (set via .trigger_request_format::<T>())
  • R tracks the call request type (set via .call_request_format::<T>())
Both default to Value (untyped) and change when the respective builder method is called. This allows IIIClient::register_trigger_type to return a TriggerTypeRef<C, R> with compile-time safety for both config and function input types.
NameTypeRequiredDescription
call_request_formatfn() -> RegisterTriggerType<H, C, T>YesSet the call request format schema from a type. Changes R, enabling compile-time validation on TriggerTypeRef::register_function.
newfn(id: impl Into<String>, description: impl Into<String>, handler: H) -> SelfYes-
trigger_request_formatfn() -> RegisterTriggerType<H, T, R>YesSet the trigger request format schema from a type. Changes C, enabling compile-time validation on TriggerTypeRef::register_trigger.

TelemetryOptions

Worker metadata reported to the engine (language, framework, project).
NameTypeRequiredDescription
languageOption<String>NoProgramming language of the worker.
project_nameOption<String>NoName of the project this worker belongs to.
frameworkOption<String>NoFramework name, if applicable.
amplitude_api_keyOption<String>NoAmplitude API key for product analytics.

iii_sdk::builtin_triggers

CronCallRequest · CronTriggerConfig · HttpCallRequest · HttpMethod · HttpTriggerConfig · LogCallRequest · LogLevel · LogTriggerConfig · QueueTriggerConfig · StateCallRequest · StateEventType · StateTriggerConfig · SubscribeTriggerConfig

CronCallRequest

NameTypeRequiredDescription
triggerStringYes-
job_idStringYes-
scheduled_timeStringYes-
actual_timeStringYes-

CronTriggerConfig

NameTypeRequiredDescription
expressionStringYesCron expression (6-field format: sec min hour day month weekday)
condition_function_idOption<String>NoOptional function ID to evaluate before invoking handler

HttpCallRequest

NameTypeRequiredDescription
query_paramsHashMap<String, String>Yes-
path_paramsHashMap<String, String>Yes-
headersHashMap<String, String>Yes-
pathStringYes-
methodStringYes-
bodyValueYes-

HttpMethod

NameTypeRequiredDescription
GetunitYes-
PostunitYes-
PutunitYes-
DeleteunitYes-
PatchunitYes-
HeadunitYes-
OptionsunitYes-

HttpTriggerConfig

NameTypeRequiredDescription
api_pathStringYesHTTP endpoint path (e.g. /users/:id)
http_methodOption<HttpMethod>NoHTTP method (defaults to GET)
condition_function_idOption<String>NoOptional function ID to evaluate before invoking handler

LogCallRequest

NameTypeRequiredDescription
timestamp_unix_nanou64Yes-
observed_timestamp_unix_nanou64Yes-
severity_numberu32Yes-
severity_textStringYes-
bodyStringYes-
attributesValueYes-
trace_idStringYes-
span_idStringYes-
resourceValueYes-
service_nameStringYes-
instrumentation_scope_nameStringYes-
instrumentation_scope_versionStringYes-

LogLevel

NameTypeRequiredDescription
AllunitYes-
DebugunitYes-
InfounitYes-
WarnunitYes-
ErrorunitYes-

LogTriggerConfig

NameTypeRequiredDescription
levelOption<LogLevel>NoMinimum log level to trigger on

QueueTriggerConfig

NameTypeRequiredDescription
topicStringYesQueue topic to subscribe to
condition_function_idOption<String>NoOptional function ID to evaluate before invoking handler
queue_configOption<Value>NoQueue-specific subscriber configuration
queue_configfn(config: impl Serialize) -> Result<Self, serde_json::Error>Yes-

StateCallRequest

NameTypeRequiredDescription
message_typeStringYes-
event_typeStateEventTypeYes-
scopeStringYes-
keyStringYes-
old_valueOption<Value>No-
new_valueValueYes-

StateEventType

NameTypeRequiredDescription
CreatedunitYes-
UpdatedunitYes-
DeletedunitYes-

StateTriggerConfig

NameTypeRequiredDescription
scopeOption<String>NoState scope to watch (exact match filter)
keyOption<String>NoState key to watch (exact match filter)
condition_function_idOption<String>NoOptional function ID to evaluate before invoking handler

SubscribeTriggerConfig

NameTypeRequiredDescription
topicStringYesTopic to subscribe to
condition_function_idOption<String>NoOptional function ID to evaluate before invoking handler

iii_sdk::channel

Channel · ChannelReader · ChannelWriter · StreamChannelRef

Channel

A streaming channel pair for worker-to-worker data transfer.
NameTypeRequiredDescription
writerChannelWriterYes-
readerChannelReaderYes-
writer_refStreamChannelRefYes-
reader_refStreamChannelRefYes-

ChannelReader

WebSocket-backed reader for streaming binary data and text messages.
NameTypeRequiredDescription
closeasync fn() -> Result<(), Error>Yes-
newfn(engine_ws_base: &str, channel_ref: &StreamChannelRef) -> SelfYes-
next_binaryasync fn() -> Result<Option<Vec<u8>>, Error>YesRead the next binary chunk from the channel. Text messages are dispatched to registered callbacks. Returns None when the stream is closed.
on_messageasync fn(callback: F)YesRegister a callback for text messages received on this channel.
read_allasync fn() -> Result<Vec<u8>, Error>YesRead the entire stream into a single Vec<u8>.

ChannelWriter

WebSocket-backed writer for streaming binary data and text messages.
NameTypeRequiredDescription
closeasync fn() -> Result<(), Error>Yes-
newfn(engine_ws_base: &str, channel_ref: &StreamChannelRef) -> SelfYes-
send_messageasync fn(msg: &str) -> Result<(), Error>Yes-
writeasync fn(data: &[u8]) -> Result<(), Error>Yes-

StreamChannelRef

NameTypeRequiredDescription
channel_idStringYes-
access_keyStringYes-
directionChannelDirectionYes-

iii_sdk::channels

ChannelDirection · ChannelItem

ChannelDirection

NameTypeRequiredDescription
ReadunitYes-
WriteunitYes-

ChannelItem

NameTypeRequiredDescription
Text(String)Yes-
Binary(Vec<u8>)Yes-

iii_sdk::engine

EngineFunctions · EngineTriggers

EngineFunctions

Engine function ids for internal operations.

EngineTriggers

Engine trigger ids.

iii_sdk::errors

Error · InvocationError

Error

Errors returned by the III SDK.
NameTypeRequiredDescription
NotConnectedunitYes-
TimeoutunitYes-
Runtime(String)Yes-
Remote{ code: String, message: String, stacktrace: Option<String> }Yes-
Handler(String)Yes-
Serde(String)Yes-
WebSocket(String)Yes-
invocation_errorfn() -> Option<InvocationError>YesIf this is a remote invocation failure (Error::Remote), return its structured form. Returns None for transport/serde/handler errors.

InvocationError

Structured invocation failure, mirroring the Node and Python InvocationError. Produced from the Error::Remote variant via Error::invocation_error. function_id is None from that accessor because the wire Remote payload does not carry it.
NameTypeRequiredDescription
codeStringYes-
messageStringYes-
function_idOption<String>No-
stacktraceOption<String>No-

iii_sdk::protocol

ErrorBody · FunctionMessage · Message · RegisterFunctionMessage · RegisterTriggerInput · RegisterTriggerMessage · RegisterTriggerTypeMessage · TriggerAction · TriggerRequest · TriggerRequestWithMetadata · UnregisterTriggerMessage · UnregisterTriggerTypeMessage

ErrorBody

NameTypeRequiredDescription
codeStringYes-
messageStringYes-
stacktraceOption<String>No-

FunctionMessage

NameTypeRequiredDescription
function_idStringYes-
descriptionOption<String>No-
request_formatOption<Value>No-
response_formatOption<Value>No-
metadataOption<Value>No-

Message

NameTypeRequiredDescription
RegisterTriggerType{ id: String, description: String, trigger_request_format: Option<Value>, call_request_format: Option<Value> }Yes-
RegisterTrigger{ id: String, trigger_type: String, function_id: String, config: Value, metadata: Option<Value> }Yes-
TriggerRegistrationResult{ id: String, trigger_type: String, function_id: String, error: Option<ErrorBody> }Yes-
UnregisterTrigger{ id: String, trigger_type: String }Yes-
UnregisterTriggerType{ id: String }Yes-
RegisterFunction{ id: String, description: Option<String>, request_format: Option<Value>, response_format: Option<Value>, metadata: Option<Value>, invocation: Option<iii_helpers::http::HttpInvocationConfig> }Yes-
UnregisterFunction{ id: String }Yes-
InvokeFunction{ invocation_id: Option<uuid::Uuid>, function_id: String, data: Value, traceparent: Option<String>, baggage: Option<String>, action: Option<TriggerAction>, metadata: Option<Value> }Yes-
InvocationResult{ invocation_id: uuid::Uuid, function_id: String, result: Option<Value>, error: Option<ErrorBody>, traceparent: Option<String>, baggage: Option<String> }Yes-
PingunitYes-
PongunitYes-
WorkerRegistered{ worker_id: String }Yes-

RegisterFunctionMessage

NameTypeRequiredDescription
idStringYes-
descriptionOption<String>No-
request_formatOption<Value>No-
response_formatOption<Value>No-
metadataOption<Value>No-
invocationOption<iii_helpers::http::HttpInvocationConfig>No-
to_messagefn() -> MessageYes-

RegisterTriggerInput

Input for IIIClient::register_trigger. The id is auto-generated internally.
NameTypeRequiredDescription
trigger_typeStringYesIdentifier of the registered trigger type this trigger uses (e.g. storage::object-created, http).
function_idStringYesID of the function this trigger invokes when it fires.
configValueYesTrigger-type-specific configuration, matching the shape the trigger type expects.
metadataOption<Value>NoArbitrary user-specifiable metadata supplied to the triggered handler function on every invocation.

RegisterTriggerMessage

NameTypeRequiredDescription
idStringYes-
trigger_typeStringYes-
function_idStringYes-
configValueYes-
metadataOption<Value>No-
to_messagefn() -> MessageYes-

RegisterTriggerTypeMessage

NameTypeRequiredDescription
idStringYesUnique identifier for the trigger type (e.g. state, durable:subscriber).
descriptionStringYesHuman-readable description of what this trigger type does.
trigger_request_formatOption<Value>No-
call_request_formatOption<Value>No-
to_messagefn() -> MessageYes-

TriggerAction

Routing action for TriggerRequest. Determines how the engine handles the invocation.
  • Enqueue: Routes through a named queue for async processing.
  • Void: Fire-and-forget, no response.
NameTypeRequiredDescription
Enqueue{ queue: String }YesRoutes the invocation through a named queue.
VoidunitYesFire-and-forget routing.

TriggerRequest

Request object for trigger().
NameTypeRequiredDescription
function_idStringYesID of the function to invoke.
payloadValueYesInput data passed to the function.
actionOption<TriggerAction>NoSets how the trigger is routed. None for a synchronous request/response.
Set a routing scheme otherwise (e.g. TriggerAction::Enqueue { .. }, TriggerAction::Void).
timeout_msOption<u64>NoOverride the default invocation timeout, in milliseconds.
metadatafn(metadata: Value) -> TriggerRequestWithMetadataYesAttach per-invocation metadata without adding a required field to TriggerRequest struct literals.

TriggerRequestWithMetadata

Trigger request plus optional per-invocation metadata.

UnregisterTriggerMessage

NameTypeRequiredDescription
idStringYes-
trigger_typeStringYes-
to_messagefn() -> MessageYes-

UnregisterTriggerTypeMessage

NameTypeRequiredDescription
idStringYes-
to_messagefn() -> MessageYes-

iii_sdk::runtime

FunctionInfo · FunctionRef · IIIConnectionState · TriggerInfo · TriggerTypeRef · WorkerInfo · WorkerMetadata

FunctionInfo

Function information returned by engine::functions::list
NameTypeRequiredDescription
function_idStringYes-
descriptionOption<String>No-
request_formatOption<Value>No-
response_formatOption<Value>No-
metadataOption<Value>No-

FunctionRef

NameTypeRequiredDescription
idStringYes-
unregisterfn()Yes-

IIIConnectionState

Connection state for the III WebSocket client
NameTypeRequiredDescription
DisconnectedunitYes-
ConnectingunitYes-
ConnectedunitYes-
ReconnectingunitYes-
FailedunitYes-

TriggerInfo

Trigger information returned by engine::triggers::list
NameTypeRequiredDescription
idStringYes-
trigger_typeStringYes-
function_idStringYes-
configValueYes-
metadataOption<Value>No-

TriggerTypeRef

Typed handle returned by IIIClient::register_trigger_type. Type parameters:
  • C: trigger registration type for register_trigger
  • R: call request type for register_function
NameTypeRequiredDescription
register_functionfn(id: impl Into<String>, f: F) -> FunctionRefYesRegister a sync function whose input type must match the call request format R.
register_function_asyncfn(id: impl Into<String>, f: F) -> FunctionRefYesRegister an async function whose input type must match the call request format R.
register_triggerfn(function_id: impl Into<String>, config: C) -> Result<Trigger, Error>YesRegister a trigger with compile-time validated trigger config.
register_trigger_with_metadatafn(function_id: impl Into<String>, config: C, metadata: Option<Value>) -> Result<Trigger, Error>YesRegister a trigger with compile-time validated trigger config and optional metadata.

WorkerInfo

Worker information returned by engine::workers::list
NameTypeRequiredDescription
idStringYes-
nameOption<String>No-
runtimeOption<String>No-
versionOption<String>No-
osOption<String>No-
ip_addressOption<String>No-
statusStringYes-
connected_at_msu64Yes-
function_countusizeYes-
functionsVec<String>Yes-
active_invocationsusizeYes-
isolationOption<String>No-

WorkerMetadata

Worker metadata for auto-registration
NameTypeRequiredDescription
runtimeStringYes-
versionStringYes-
nameStringYes-
osStringYes-
descriptionOption<String>NoOne-line, human/LLM-readable summary of what this worker does.
Surfaces in engine::workers::list / engine::workers::info.
pidOption<u32>No-
telemetryOption<TelemetryOptions>No-
isolationOption<String>No-

iii_sdk::stream_provider

IStream

IStream

Custom stream-provider trait. Implementors override the engine’s built-in stream storage for a specific stream name when registered through create_stream in the helpers submodule.
NameTypeRequiredDescription
getfn(input: StreamGetInput) -> Pin<Box<dyn Future + Send>>Yes-
setfn(input: StreamSetInput) -> Pin<Box<dyn Future + Send>>Yes-
deletefn(input: StreamDeleteInput) -> Pin<Box<dyn Future + Send>>Yes-
listfn(input: StreamListInput) -> Pin<Box<dyn Future + Send>>Yes-
list_groupsfn(input: StreamListGroupsInput) -> Pin<Box<dyn Future + Send>>Yes-
updatefn(input: StreamUpdateInput) -> Pin<Box<dyn Future + Send>>Yes-

iii_sdk::structs

MiddlewareFunctionInput

MiddlewareFunctionInput

Input passed to the RBAC middleware function on every function invocation through the RBAC port. The middleware can inspect, modify, or reject the call before it reaches the target function.
NameTypeRequiredDescription
function_idStringYesID of the function being invoked.
payloadValueYesPayload sent by the caller.
actionOption<TriggerAction>NoRouting action, if any.
contextValueYesAuth context returned by the auth function for this session.

iii_sdk::trigger

IIITrigger · Trigger · TriggerConfig · TriggerHandler

IIITrigger

Enum of all built-in trigger types with typed configuration. Use .for_function() to create a RegisterTriggerInput:
NameTypeRequiredDescription
Http(HttpTriggerConfig)Yes-
Cron(CronTriggerConfig)Yes-
Queue(QueueTriggerConfig)Yes-
Subscribe(SubscribeTriggerConfig)Yes-
State(StateTriggerConfig)Yes-
Stream(iii_helpers::stream::StreamTriggerConfig)Yes-
StreamJoin(iii_helpers::stream::StreamJoinLeaveTriggerConfig)Yes-
StreamLeave(iii_helpers::stream::StreamJoinLeaveTriggerConfig)Yes-
Log(LogTriggerConfig)Yes-
for_functionfn(function_id: impl Into<String>) -> RegisterTriggerInputYesCreate a RegisterTriggerInput binding this trigger to a function.

Trigger

Handle returned by IIIClient::register_trigger. Call unregister to remove the trigger from the engine.
NameTypeRequiredDescription
newfn(unregister_fn: Arc<dyn Fn() + Send + Sync>) -> SelfYes-
unregisterfn()YesRemove this trigger from the engine.

TriggerConfig

Configuration passed to a TriggerHandler when a trigger instance is registered or unregistered.
NameTypeRequiredDescription
idStringYesTrigger instance ID.
function_idStringYesFunction to invoke when the trigger fires.
configValueYesTrigger-specific configuration.
metadataOption<Value>NoArbitrary user-specifiable metadata supplied to the triggered handler function on every invocation.

TriggerHandler

Handler trait for custom trigger types. Implement this and pass to IIIClient::register_trigger_type.
NameTypeRequiredDescription
register_triggerfn(config: TriggerConfig) -> Pin<Box<dyn Future + Send>>YesCalled when a trigger instance is registered.
unregister_triggerfn(config: TriggerConfig) -> Pin<Box<dyn Future + Send>>YesCalled when a trigger instance is unregistered.

iii_sdk::types

RemoteFunctionData · RemoteFunctionHandler · RemoteTriggerTypeData · StreamRequest · StreamResponse

RemoteFunctionData

NameTypeRequiredDescription
messageRegisterFunctionMessageYes-
handlerOption<RemoteFunctionHandlerWithMetadata>No-

RemoteFunctionHandler

A dispatchable function handler. Receives the invocation payload. Handlers that also want the optional per-invocation metadata sidecar use RemoteFunctionHandlerWithMetadata; this single-argument shape is kept for backward compatibility.

RemoteTriggerTypeData

NameTypeRequiredDescription
messageRegisterTriggerTypeMessageYes-
handlerArc<dyn TriggerHandler>Yes-

StreamRequest

Incoming streaming request received by a function registered with a stream trigger. Alias of iii_helpers::http::HttpRequest.

StreamResponse

Streaming response type, mirroring the Node and Python StreamResponse. Alias of iii_helpers::http::HttpResponse; added for cross-language parity.