Skip to main content

Documentation Index

Fetch the complete documentation index at: https://motiadev-docs-phase-2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Channels move large or binary payloads between iii workers without putting the data in a JSON function payload. Use one when the payload is expected to be large (files, images, datasets), above roughly 16 MB, intended to be streamed (audio, video), or you want incremental progress updates during long-running work. For small JSON, stick with a regular worker.trigger(...) call.
For the underlying model (how channels are addressed, multiplexed, and torn down), see Channels architecture.

Payload size

iii itself doesn’t enforce a maximum trigger-payload size. The effective ceiling comes from whichever WebSocket library the engine and the calling SDK use, and each has its own defaults for the per-frame and per-message size. The smallest common per-frame default sits around 16 MB, which is the practical line at which you should switch to a channel. The libraries iii currently relies on: These are library defaults and can shift between dependency versions; iii doesn’t publish a hard guaranteed cap. 16 MB is a safe default to follow.

Using channels

A channel is created by one worker and has two local stream ends: writer and reader; plus two serializable refs (writerRef / readerRef) that can be handed to another function. The subsections below cover the local-end API: creating a channel, writing bytes into its writer, and reading bytes from its reader.

Create a channel

worker.createChannel() returns a channel with two local stream objects and two serializable refs: writer and reader are the local stream ends, and writerRef / readerRef are the tokens you pass to another function so it can read or write the other end.
const channel = await worker.createChannel();

// channel.writer
// channel.reader
// channel.writerRef
// channel.readerRef

Write to a channel

Write the payload to the local writer and close it when finished. The bytes flow through the engine to whichever worker holds the matching reader.
const channel = await worker.createChannel();

channel.writer.stream.end(Buffer.from("file contents"));

Read from a channel

Read the local reader until the other end closes. The bytes arrive in the order they were written by whichever worker holds the matching writer.
const channel = await worker.createChannel();

let bytes = 0;
for await (const chunk of channel.reader.stream) {
  bytes += Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk);
}

Using channels across functions

A channel only becomes useful once both ends are owned by different code paths. Typically one function that holds the local writer / reader and another that receives the matching ref in its payload. The two subsections below cover that handoff: first how to send a ref alongside a normal trigger call, then how the receiving function turns it back into a live stream to read or write.

Pass a channel ref to another function

Pass the readerRef (or writerRef) as part of a normal function invocation. The receiving function uses the ref to read from (or write to) the channel.
const result = await worker.trigger({
  function_id: "files::process",
  payload: {
    filename: "report.csv",
    reader: channel.readerRef,
  },
});
Node and Python deserialize incoming channel refs into live ChannelReader / ChannelWriter objects before the handler runs, so the ref arrives ready to iterate or write to. Rust receives the ref in JSON and reconstructs the reader or writer explicitly with ChannelReader::new(...) or ChannelWriter::new(...).

Read from a channel ref

import type { ChannelReader } from "iii-sdk";

worker.registerFunction("files::process", async (input: { reader: ChannelReader }) => {
  let bytes = 0;
  for await (const chunk of input.reader.stream) {
    bytes += Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk);
  }
  return { bytes };
});

Write to a channel ref

import type { ChannelWriter } from "iii-sdk";

worker.registerFunction("files::generate", async (input: { writer: ChannelWriter }) => {
  input.writer.stream.write(Buffer.from("hello "));
  input.writer.stream.end(Buffer.from("world"));
  return { ok: true };
});
For the per-language channel API surface, see the SDK reference: Node, Python, and Rust.