OpenClaw API Control
Overview
Use the hosted OpenClaw API instead of the browser UI when an agent should operate an existing OpenClaw instance directly.
Required environment variables:
OPENCLAW_API_KEYOPENCLAW_API_BASE_URL
Optional environment variables:
OPENCLAW_INSTANCE_ID
Defaults:
- If
OPENCLAW_API_BASE_URLis missing, usehttps://openclaw-as-a-service.com/api - If
OPENCLAW_INSTANCE_IDis missing, discover a ready instance automatically
When To Use
- “Send this folder to my OpenClaw”
- “Upload these files into the OpenClaw workspace”
- “Ask my OpenClaw to continue this task”
- “Run this command on my hosted OpenClaw”
- “Read
/workspace/...from OpenClaw” - “Create an OpenClaw instance through the API”
Workflow
- Verify
OPENCLAW_API_KEYis present. - Use
scripts/openclaw_api_client.mjs rootorinstances listto confirm connectivity. - Resolve the target instance:
- Prefer
OPENCLAW_INSTANCE_ID - Otherwise pick the first
readyinstance frominstances list
- Prefer
- Choose the right action:
- Chat:
chat send - Recent history:
chat tail - Files or folders:
files read,files write,files upload-tree - Commands:
terminal exec
- Chat:
- Report the exact API action and result back to the user.
Commands
Discover API root
node scripts/openclaw_api_client.mjs root
List instances
node scripts/openclaw_api_client.mjs instances list
Create an instance
node scripts/openclaw_api_client.mjs instances create --invite-code YOUR_CODE
Send a chat message
node scripts/openclaw_api_client.mjs chat send --message "Continue the task in /workspace"
Stream a chat message
node scripts/openclaw_api_client.mjs chat send --stream --message "Narrate each step while you work"
Upload a folder into /workspace
node scripts/openclaw_api_client.mjs files upload-tree --src ./my-project --dest /workspace/my-project
Read a file
node scripts/openclaw_api_client.mjs files read --path /workspace/README.md
Run a command
node scripts/openclaw_api_client.mjs terminal exec --command "pwd && ls -la /workspace"
Notes
files upload-treeonly uploads text-like files and skips likely binary files.chat tailautomatically reuses the latest chat session when no session id is supplied.- The helper prints JSON for machine-friendly reuse.
Resources
scripts/openclaw_api_client.mjs- Minimal Node client for OpenClaw API operations