The OpenClaw App SDK is the public client API for apps outside the OpenClaw process. UseDocumentation Index
Fetch the complete documentation index at: https://docs.openclaw.ai/llms.txt
Use this file to discover all available pages before exploring further.
@openclaw/sdk when a script, dashboard, CI job, IDE
extension, or other external app wants to connect to the Gateway, start agent
runs, stream events, wait for results, cancel work, or inspect Gateway
resources.
The App SDK is different from the Plugin SDK.
@openclaw/sdk talks to the Gateway from outside OpenClaw.
openclaw/plugin-sdk/* is only for plugins that run inside OpenClaw and
register providers, channels, tools, hooks, or trusted runtimes.What Ships Today
@openclaw/sdk ships with:
| Surface | Status | What it does |
|---|---|---|
OpenClaw | Ready | Main client entry point. Owns transport, connection, requests, and events. |
GatewayClientTransport | Ready | WebSocket transport backed by the Gateway client. |
oc.agents | Ready | Lists, creates, updates, deletes, and gets agent handles. |
Agent.run() | Ready | Starts a Gateway agent run and returns a Run. |
oc.runs | Ready | Creates, gets, waits for, cancels, and streams runs. |
Run.events() | Ready | Streams normalized per-run events with replay for fast runs. |
Run.wait() | Ready | Calls agent.wait and returns a stable RunResult. |
Run.cancel() | Ready | Calls sessions.abort by run id, with session key when available. |
oc.sessions | Ready | Creates, resolves, sends to, patches, compacts, and gets session handles. |
Session.send() | Ready | Calls sessions.send and returns a Run. |
oc.models | Ready | Calls models.list and the current models.authStatus status RPC. |
oc.tools | Partial | Lists tool catalog and effective tools; direct tool invocation is not wired. |
oc.approvals | Ready | Lists and resolves exec approvals through Gateway approval RPCs. |
oc.rawEvents() | Ready | Exposes raw Gateway events for advanced consumers. |
normalizeGatewayEvent() | Ready | Converts raw Gateway events into the stable SDK event shape. |
AgentRunParams, RunResult, RunStatus, OpenClawEvent,
OpenClawEventType, GatewayEvent, OpenClawTransport,
GatewayRequestOptions, SessionCreateParams, SessionSendParams,
RuntimeSelection, EnvironmentSelection, WorkspaceSelection,
ApprovalMode, and related result types.
Connect To A Gateway
Create a client with an explicit Gateway URL, or inject a custom transport for tests and embedded app runtimes.new OpenClaw({ gateway: "ws://..." }) is equivalent to url. The
gateway: "auto" option is accepted by the constructor, but automatic Gateway
discovery is not a separate SDK feature yet; pass url when the app does not
already know how to discover the Gateway.
For tests, pass an object that implements OpenClawTransport:
Run An Agent
Useoc.agents.get(id) when the app wants an agent handle, then call
agent.run().
openai/gpt-5.5 are split into Gateway
provider and model overrides. timeoutMs stays milliseconds in the SDK and
is converted to Gateway timeout seconds for the agent RPC.
run.wait() uses the Gateway agent.wait RPC. A wait deadline that expires
while the run is still active returns status: "accepted" instead of pretending
the run itself timed out. Runtime timeouts, aborted runs, and cancelled runs are
normalized into timed_out or cancelled.
Create And Reuse Sessions
Use sessions when the app wants durable transcript state.Session.send() calls sessions.send and returns a Run. Session handles also
support:
Stream Events
The SDK normalizes raw Gateway events into a stableOpenClawEvent envelope:
| Event type | Source Gateway event |
|---|---|
run.started | agent lifecycle start |
run.completed | agent lifecycle end |
run.failed | agent lifecycle error |
run.cancelled | Aborted/cancelled lifecycle end |
run.timed_out | Timeout lifecycle end |
assistant.delta | Assistant streaming delta |
assistant.message | Assistant message |
thinking.delta | Thinking or plan stream |
tool.call.started | Tool/item/command start |
tool.call.delta | Tool/item/command update |
tool.call.completed | Tool/item/command completion |
tool.call.failed | Tool/item/command failure or blocked status |
approval.requested | Exec or plugin approval request |
approval.resolved | Exec or plugin approval resolution |
session.created | sessions.changed create |
session.updated | sessions.changed update |
session.compacted | sessions.changed compaction |
task.updated | Task update events |
artifact.updated | Patch stream events |
raw | Any event without a stable SDK mapping yet |
Run.events() filters events to one run id and replays already-seen events for
fast runs. That means the documented flow is safe:
oc.events(). For raw Gateway frames, use
oc.rawEvents().
Models, Tools, And Approvals
Model helpers map to current Gateway methods:Explicitly Unsupported Today
The SDK includes names for the product model we want, but it does not silently pretend Gateway RPCs exist. These calls currently throw explicit unsupported errors:workspace, runtime, environment, and approvals fields are typed
as future shape, but the current Gateway does not support those overrides on
the agent RPC. If callers pass them, the SDK throws before submitting the run
so work does not accidentally execute with default workspace, runtime,
environment, or approval behavior.
App SDK Versus Plugin SDK
Use the App SDK when code lives outside OpenClaw:- Node scripts that start or observe agent runs
- CI jobs that call a Gateway
- dashboards and admin panels
- IDE extensions
- external bridges that do not need to become channel plugins
- integration tests with fake or real Gateway transports
- provider plugins
- channel plugins
- tool or lifecycle hooks
- agent harness plugins
- trusted runtime helpers
@openclaw/sdk. Plugin code should import from
documented openclaw/plugin-sdk/* subpaths. Do not mix the two contracts.