docs/api-reference/sdk-rust.mdx
cargo add iii-sdk
Create and return a connected SDK instance. The WebSocket connection is established automatically in a background Tokio task.
use iii_sdk::{register_worker, InitOptions};
let iii = register_worker("ws://localhost:49134", InitOptions::default());
Shutdown the III client.
This stops the connection loop and sends a shutdown signal.
If the otel feature is enabled, this will spawn a background task
to flush telemetry data, but does NOT wait for it to complete.
For guaranteed telemetry flush, use shutdown_async() instead.
Signature
shutdown()
Shutdown the III client and flush all pending telemetry data.
This method stops the connection loop and sends a shutdown signal.
When the otel feature is enabled, it additionally awaits the
OpenTelemetry flush, ensuring all spans, metrics, and logs are
exported before returning.
Signature
async shutdown_async()
Register a function with the engine.
Pass a closure/async fn for local execution, or an [HttpInvocationConfig]
for HTTP-invoked functions (Lambda, Cloudflare Workers, etc.).
Signature
register_function(message: RegisterFunctionMessage, handler: H) -> FunctionRef
| Name | Type | Required | Description |
|---|---|---|---|
message | RegisterFunctionMessage | Yes | Function registration message with id and optional metadata. |
handler | H | Yes | Async handler or HTTP invocation config. |
use iii_sdk::{register_worker, InitOptions, RegisterFunctionMessage};
use serde_json::{json, Value};
let iii = register_worker("ws://localhost:49134", InitOptions::default());
iii.register_function(
RegisterFunctionMessage {
id: "greet".to_string(),
description: None,
request_format: None,
response_format: None,
metadata: None,
invocation: None,
},
|input: Value| async move {
Ok(json!({"message": format!("Hello, {}!", input["name"])}))
},
);
Register a service with the engine.
Signature
register_service(message: RegisterServiceMessage)
| Name | Type | Required | Description |
|---|---|---|---|
message | RegisterServiceMessage | Yes | Service registration message with id, name, and optional metadata. |
Register a custom trigger type with the engine.
Signature
register_trigger_type(id: impl Into<String>, description: impl Into<String>, handler: H)
| Name | Type | Required | Description |
|---|---|---|---|
id | impl Into<String> | Yes | Unique trigger type identifier. |
description | impl Into<String> | Yes | Human-readable description. |
handler | H | Yes | Handler implementing [TriggerHandler]. |
Unregister a previously registered trigger type.
Signature
unregister_trigger_type(id: impl Into<String>)
| Name | Type | Required | Description |
|---|---|---|---|
id | impl Into<String> | Yes | - |
Bind a trigger configuration to a registered function.
Signature
register_trigger(input: RegisterTriggerInput) -> Result<Trigger, IIIError>
| Name | Type | Required | Description |
|---|---|---|---|
input | RegisterTriggerInput | Yes | Trigger registration input with trigger_type, function_id, and config. |
let trigger = iii.register_trigger(RegisterTriggerInput {
trigger_type: "http".to_string(),
function_id: "greet".to_string(),
config: json!({ "api_path": "/greet", "http_method": "GET" }),
})?;
// Later...
trigger.unregister();
Invoke a remote function.
The routing behavior depends on the action field of the request:
TriggerAction::Enqueue] - async via named queue.TriggerAction::Void] — fire-and-forget.Signature
async trigger(request: impl Into<TriggerRequest>) -> Result<Value, IIIError>
| Name | Type | Required | Description |
|---|---|---|---|
request | impl Into<TriggerRequest> | Yes | - |
// Synchronous
let result = iii.trigger(TriggerRequest {
function_id: "greet".to_string(),
payload: json!({"name": "World"}),
action: None,
timeout_ms: None,
}).await?;
// Fire-and-forget
iii.trigger(TriggerRequest {
function_id: "notify".to_string(),
payload: json!({}),
action: Some(TriggerAction::Void),
timeout_ms: None,
}).await?;
// Enqueue
let receipt = iii.trigger(TriggerRequest {
function_id: "enqueue".to_string(),
payload: json!({"topic": "test"}),
action: Some(TriggerAction::Enqueue { queue: "test".to_string() }),
timeout_ms: None,
}).await?;
Get the current connection state.
Signature
get_connection_state() -> IIIConnectionState
List all registered functions from the engine
Signature
async list_functions() -> Result<Vec<FunctionInfo>, IIIError>
Subscribe to function availability events Returns a guard that will unsubscribe when dropped
Signature
on_functions_available(callback: F) -> FunctionsAvailableGuard
| Name | Type | Required | Description |
|---|---|---|---|
callback | F | Yes | - |
List all connected workers from the engine
Signature
async list_workers() -> Result<Vec<WorkerInfo>, IIIError>
List all registered triggers from the engine
Signature
async list_triggers(include_internal: bool) -> Result<Vec<TriggerInfo>, IIIError>
| Name | Type | Required | Description |
|---|---|---|---|
include_internal | bool | Yes | - |
Create a streaming channel pair for worker-to-worker data transfer.
Returns a Channel with writer, reader, and their serializable refs
that can be passed as fields in invocation data to other functions.
Signature
async create_channel(buffer_size: Option<usize>) -> Result<Channel, IIIError>
| Name | Type | Required | Description |
|---|---|---|---|
buffer_size | Option<usize> | No | - |
Structured logger that emits logs as OpenTelemetry LogRecords.
Every log call automatically captures the active trace and span context,
correlating your logs with distributed traces without any manual wiring.
When OTel is not initialized, Logger gracefully falls back to the tracing
crate.
Pass structured data as the second argument to any log method. Using a
serde_json::Value object of key-value pairs (instead of string
interpolation) lets you filter, aggregate, and build dashboards in your
observability backend.
Log an info-level message.
Signature
info(message: &str, data: Option<Value>)
| Name | Type | Required | Description |
|---|---|---|---|
message | &str | Yes | Human-readable log message. |
data | Option<Value> | No | Structured context attached as OTel log attributes. Use serde_json::json! objects to enable filtering and aggregation in your observability backend (e.g. Grafana, Datadog, New Relic). |
logger.info("Order processed", Some(json!({ "order_id": "ord_123", "status": "completed" })));
Log a warning-level message.
Signature
warn(message: &str, data: Option<Value>)
| Name | Type | Required | Description |
|---|---|---|---|
message | &str | Yes | Human-readable log message. |
data | Option<Value> | No | Structured context attached as OTel log attributes. Use serde_json::json! objects to enable filtering and aggregation in your observability backend (e.g. Grafana, Datadog, New Relic). |
logger.warn("Retry attempt", Some(json!({ "attempt": 3, "max_retries": 5, "endpoint": "/api/charge" })));
Log an error-level message.
Signature
error(message: &str, data: Option<Value>)
| Name | Type | Required | Description |
|---|---|---|---|
message | &str | Yes | Human-readable log message. |
data | Option<Value> | No | Structured context attached as OTel log attributes. Use serde_json::json! objects to enable filtering and aggregation in your observability backend (e.g. Grafana, Datadog, New Relic). |
logger.error("Payment failed", Some(json!({ "order_id": "ord_123", "gateway": "stripe", "error_code": "card_declined" })));
Log a debug-level message.
Signature
debug(message: &str, data: Option<Value>)
| Name | Type | Required | Description |
|---|---|---|---|
message | &str | Yes | Human-readable log message. |
data | Option<Value> | No | Structured context attached as OTel log attributes. Use serde_json::json! objects to enable filtering and aggregation in your observability backend (e.g. Grafana, Datadog, New Relic). |
logger.debug("Cache lookup", Some(json!({ "key": "user:42", "hit": false })));
InitOptions · IIIError · IIIConnectionState · TriggerRequest · TriggerAction · HttpInvocationConfig · HttpAuthConfig · HttpMethod · Channel · ChannelReader · ChannelWriter · ChannelDirection · StreamChannelRef · FunctionInfo · FunctionRef · TriggerInfo · WorkerInfo · WorkerMetadata · Trigger · RegisterFunctionMessage · RegisterServiceMessage · OtelConfig · ReconnectionConfig
Configuration options passed to [register_worker].
| Name | Type | Required | Description |
|---|---|---|---|
metadata | Option<WorkerMetadata> | No | Custom worker metadata. Auto-detected if None. |
otel | Option<OtelConfig> | No | OpenTelemetry configuration. Requires the otel feature. |
Errors returned by the III SDK.
| Name | Type | Required | Description |
|---|---|---|---|
NotConnected | unit | Yes | - |
Timeout | unit | Yes | - |
Runtime | (String) | Yes | - |
Remote | { code: String, message: String, stacktrace: Option<String> } | Yes | - |
Handler | (String) | Yes | - |
Serde | (String) | Yes | - |
WebSocket | (String) | Yes | - |
Connection state for the III WebSocket client
| Name | Type | Required | Description |
|---|---|---|---|
Disconnected | unit | Yes | - |
Connecting | unit | Yes | - |
Connected | unit | Yes | - |
Reconnecting | unit | Yes | - |
Failed | unit | Yes | - |
Request object for trigger(). Matches the Node/Python SDK signature:
trigger({ function_id, payload, action?, timeout_ms? })
| Name | Type | Required | Description |
|---|---|---|---|
function_id | String | Yes | - |
payload | Value | Yes | - |
action | Option<TriggerAction> | No | - |
timeout_ms | Option<u64> | No | - |
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.| Name | Type | Required | Description |
|---|---|---|---|
Enqueue | { queue: String } | Yes | Routes the invocation through a named queue. |
Void | unit | Yes | Fire-and-forget routing. |
Configuration for registering an HTTP-invoked function (Lambda, Cloudflare Workers, etc.) instead of a local handler.
| Name | Type | Required | Description |
|---|---|---|---|
url | String | Yes | - |
method | HttpMethod | Yes | - |
timeout_ms | Option<u64> | No | - |
headers | HashMap<String, String> | Yes | - |
auth | Option<HttpAuthConfig> | No | - |
Authentication configuration for HTTP-invoked functions.
Hmac -- HMAC signature verification using a shared secret.Bearer -- Bearer token authentication.ApiKey -- API key sent via a custom header.| Name | Type | Required | Description |
|---|---|---|---|
Hmac | { secret_key: String } | Yes | - |
Bearer | { token_key: String } | Yes | - |
ApiKey | { header: String, value_key: String } | Yes | - |
| Name | Type | Required | Description |
|---|---|---|---|
Get | unit | Yes | - |
Post | unit | Yes | - |
Put | unit | Yes | - |
Patch | unit | Yes | - |
Delete | unit | Yes | - |
A streaming channel pair for worker-to-worker data transfer.
| Name | Type | Required | Description |
|---|---|---|---|
writer | ChannelWriter | Yes | - |
reader | ChannelReader | Yes | - |
writer_ref | StreamChannelRef | Yes | - |
reader_ref | StreamChannelRef | Yes | - |
WebSocket-backed reader for streaming binary data and text messages.
| Name | Type | Required | Description |
|---|---|---|---|
on_message | async fn(callback: F) | Yes | Register a callback for text messages received on this channel. |
next_binary | async fn() -> Result<Option<Vec<u8>>, IIIError> | Yes | Read the next binary chunk from the channel. |
| Text messages are dispatched to registered callbacks. | |||
Returns None when the stream is closed. | |||
read_all | async fn() -> Result<Vec<u8>, IIIError> | Yes | Read the entire stream into a single Vec<u8>. |
close | async fn() -> Result<(), IIIError> | Yes | - |
WebSocket-backed writer for streaming binary data and text messages.
| Name | Type | Required | Description |
|---|---|---|---|
write | async fn(data: &[u8]) -> Result<(), IIIError> | Yes | - |
send_message | async fn(msg: &str) -> Result<(), IIIError> | Yes | - |
close | async fn() -> Result<(), IIIError> | Yes | - |
| Name | Type | Required | Description |
|---|---|---|---|
Read | unit | Yes | - |
Write | unit | Yes | - |
| Name | Type | Required | Description |
|---|---|---|---|
channel_id | String | Yes | - |
access_key | String | Yes | - |
direction | ChannelDirection | Yes | - |
Function information returned by engine::functions::list
| Name | Type | Required | Description |
|---|---|---|---|
function_id | String | Yes | - |
description | Option<String> | No | - |
request_format | Option<Value> | No | - |
response_format | Option<Value> | No | - |
metadata | Option<Value> | No | - |
| Name | Type | Required | Description |
|---|---|---|---|
id | String | Yes | - |
unregister | fn() | Yes | - |
Trigger information returned by engine::triggers::list
| Name | Type | Required | Description |
|---|---|---|---|
id | String | Yes | - |
trigger_type | String | Yes | - |
function_id | String | Yes | - |
config | Value | Yes | - |
Worker information returned by engine::workers::list
| Name | Type | Required | Description |
|---|---|---|---|
id | String | Yes | - |
name | Option<String> | No | - |
runtime | Option<String> | No | - |
version | Option<String> | No | - |
os | Option<String> | No | - |
ip_address | Option<String> | No | - |
status | String | Yes | - |
connected_at_ms | u64 | Yes | - |
function_count | usize | Yes | - |
functions | Vec<String> | Yes | - |
active_invocations | usize | Yes | - |
Worker metadata for auto-registration
| Name | Type | Required | Description |
|---|---|---|---|
runtime | String | Yes | - |
version | String | Yes | - |
name | String | Yes | - |
os | String | Yes | - |
pid | Option<u32> | No | - |
telemetry | Option<WorkerTelemetryMeta> | No | - |
Handle returned by III::register_trigger.
Call unregister to remove the trigger from the engine.
| Name | Type | Required | Description |
|---|---|---|---|
unregister | fn() | Yes | Remove this trigger from the engine. |
| Name | Type | Required | Description |
|---|---|---|---|
id | String | Yes | - |
description | Option<String> | No | - |
request_format | Option<Value> | No | - |
response_format | Option<Value> | No | - |
metadata | Option<Value> | No | - |
invocation | Option<HttpInvocationConfig> | No | - |
to_message | fn() -> Message | Yes | - |
| Name | Type | Required | Description |
|---|---|---|---|
id | String | Yes | - |
name | String | Yes | - |
description | Option<String> | No | - |
parent_service_id | Option<String> | No | - |
to_message | fn() -> Message | Yes | - |
Configuration for OpenTelemetry initialization
| Name | Type | Required | Description |
|---|---|---|---|
enabled | Option<bool> | No | - |
service_name | Option<String> | No | - |
service_version | Option<String> | No | - |
service_namespace | Option<String> | No | - |
service_instance_id | Option<String> | No | - |
engine_ws_url | Option<String> | No | - |
metrics_enabled | Option<bool> | No | - |
metrics_export_interval_ms | Option<u64> | No | - |
reconnection_config | Option<ReconnectionConfig> | No | - |
shutdown_timeout_ms | Option<u64> | No | Timeout in milliseconds for the shutdown sequence (default: 10,000) |
channel_capacity | Option<usize> | No | Capacity of the internal telemetry message channel (default: 10,000). |
| This controls the in-flight message buffer between exporters and the | |||
| WebSocket connection loop. Intentionally larger than | |||
ReconnectionConfig::max_pending_messages to absorb bursts during | |||
| normal operation while limiting stale data across reconnects. | |||
logs_enabled | Option<bool> | No | Whether to enable the log exporter (default: true) |
logs_flush_interval_ms | Option<u64> | No | Log processor flush delay in milliseconds. Defaults to 100ms when not set. |
logs_batch_size | Option<usize> | No | Maximum number of log records exported per batch. Defaults to 1 when not set. |
fetch_instrumentation_enabled | Option<bool> | No | Whether to auto-instrument outgoing HTTP calls. |
When Some(true) (default), execute_traced_request() can be used to | |||
create CLIENT spans for reqwest requests. Set Some(false) to opt out. | |||
None is treated as true. |
Configuration for WebSocket reconnection behavior
| Name | Type | Required | Description |
|---|---|---|---|
initial_delay_ms | u64 | Yes | - |
max_delay_ms | u64 | Yes | - |
backoff_multiplier | f64 | Yes | - |
jitter_factor | f64 | Yes | - |
max_retries | Option<u64> | No | - |
max_pending_messages | usize | Yes | Maximum messages preserved across reconnects. Messages beyond this limit |
| are dropped to prevent delivering stale data after a long disconnect. | |||
This is intentionally smaller than OtelConfig::channel_capacity (the | |||
| in-flight buffer between exporters and the WebSocket loop). | |||
effective_initial_delay_ms | fn() -> u64 | Yes | Returns initial_delay_ms, clamped to a minimum of 1ms to prevent division by zero. |