Path Parameters
Run ID from POST /v1/run/
Connection
const ws = new WebSocket(
'wss://api.runtools.ai/v1/run/my-code-bot/stream/run_abc123',
{ headers: { 'X-API-Key': 'rt_live_xxx' } }
);
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data.type, data);
};
Event Types
thinking
Agent is reasoning:
{
"type": "thinking",
"content": "I'll start by creating the project structure..."
}
Agent is calling a tool:
{
"type": "tool_call",
"tool": "bash",
"input": {
"command": "npm create vite@latest my-app"
}
}
Tool execution result:
{
"type": "tool_result",
"tool": "bash",
"output": "Created project my-app"
}
file_edit
File was created or modified:
{
"type": "file_edit",
"path": "/src/App.tsx",
"action": "create",
"diff": "+import React..."
}
dev_url
Dev server URL available:
{
"type": "dev_url",
"url": "https://sandbox-abc123.sandboxes.runtools.ai",
"port": 3000
}
error
An error occurred:
{
"type": "error",
"message": "Tool execution failed",
"code": "tool_error"
}
complete
Run completed successfully:
{
"type": "complete",
"output": "Your app is ready!",
"files": ["/src/App.tsx"],
"devUrl": "https://sandbox-abc123.sandboxes.runtools.ai"
}
Client Commands
Send commands to control the run:
Pause
Resume
Cancel
{ "action": "input", "text": "yes, continue" }
SDK Usage
const run = await rt.agents.run('my-code-bot', {
message: 'Create a todo app',
stream: true,
});
for await (const event of run) {
switch (event.type) {
case 'thinking':
console.log('[thinking]', event.content);
break;
case 'tool_call':
console.log('[tool]', event.tool);
break;
case 'complete':
console.log('[result]', event.output);
break;
}
}