#SDK API
The SDK receives one invocation, exposes its context, and lets your method call host-bound dependencies. Use the same handler API for a directly launched Flow and a Flow called by another method.
This page summarizes the current author interface. Run SDK/0 defines exact types and behavior, with Run/0 owning the wire protocol. For installation and a complete task, follow the build guides.
#Receive an invocation
TypeScript's handle(handler) returns a promise and receives an async handler:
Python's handle(handler) creates and owns the event loop:
These illustrative echo handlers require a host exchange on stdin and stdout. Python's synchronous entrypoint belongs outside an already-running asyncio loop. The host supplies the context and qualifies the execution runtime.
#Invocation context
Declarations name needed interfaces. The host supplies actual implementations, context, and authority. The SDK exposes the deadline, and the host enforces it.
#Call a dependency
Inside a handler, an illustrative call to a host-bound reviewer slot is:
The equivalent Python call is:
Declare the slot under uses in the package metadata.
The host binds and authorizes its target before invocation.
Your code supplies the operation identity according to Run/0 identity rules.
Optional call fields carry intent, channels, and attachments.
Intent is advisory metadata. Explicit channel and attachment mappings carry the rights the host checks.
See Run SDK/0 values and snapshots for optional-field and snapshot semantics.
#Results and errors
call returns a complete CallResult, including outcome, output, and optional held artifacts.
Inspect the outcome before consuming its output.
Declared domain outcomes remain data. Operational failures raise OperationError.
Branch on error codes rather than human messages.
Invalid handler results become INVALID_RESULT.
PROTOCOL_ERROR and CHANNEL_LOST are local-only classifications.
See results and errors for the complete rules.
#Cancellation and owned work
TypeScript accepts a call-specific AbortSignal as run.call's second argument.
Python uses ordinary task cancellation for an awaited call.
Both cancel the local wait and send protocol cancellation when the request reached the wire.
Await owned calls before returning the handler result. The SDK settles outstanding requests and rejects abandoned live work. Cancellation neither proves remote work stopped nor reverses an external effect. The host owns enforcement and final settlement.
#Channels and artifacts
run.channel(...) or context.channel(...) requests a direct pair or isolated broadcast channel.
The API exposes sender, receiver, and broadcast interfaces for sending, observing, subscribing, and closing.
Read the channel projection for exact types and ownership.
Artifacts are opaque held references outside domain JSON.
Forward selected references through artifactResults and explicit attachment mappings.
Ordinary cleanup releases live rights automatically.
Advanced early release uses release(...), when the host supports that operation.
Read immutable artifact handoff before transferring or releasing references.
#Protocol output
After entry, the SDK routes ordinary console or print diagnostics to stderr.
Keep import-time logging, raw stdout writes, and inherited child stdout off the protocol stream.
For exact logging and completion semantics, use Run SDK/0.