Overview
The websocket command sends an async request and immediately connects via WebSocket to receive the real-time response. It's the fastest way to test your workflow end-to-end from the command line.
Usage
# Test with workflowmodelriver websocket --workflow my_workflow --message "Hello from CLI" # With custom payloadmodelriver websocket --workflow my_workflow --payload '{"messages": [{"role": "user", "content": "Test"}]}' # Connect to existing channelmodelriver websocket --channel-id abc-123 --project-id xyz-789 # Verbose outputmodelriver websocket --workflow my_workflow --message "Test" --verboseExample output
✓ Making async request...✓ Request queued: abc-123-def > Channel ID: abc-123-def> Project ID: xyz-789 ✓ Connecting to WebSocket...✓ WebSocket connected✓ Channel joined > Waiting for response... ✅ Response received:{ "status": "success", "data": { ... }, "meta": { ... }}Options
| Option | Description |
|---|---|
--workflow <name> | Workflow to test |
--message <text> | Simple text message |
--payload <json> | Custom JSON payload |
--channel-id <id> | Existing channel ID |
--project-id <id> | Project ID |
--end-user <id> | Send "end_user": {"id": "<id>"} with the request, unless the payload already has an end_user. Workflows with hosted tools need one |
--cli-session <cts_id> | Send "tool_route": {"cli_session": "<cts_id>"} with the request, unless the payload already has a tool_route, so its tool calls go to a modelriver tools session |
--verbose | Show detailed logs |
Hosted tools
For a workflow with hosted tools, say who the request is for, and send its tool calls to your machine if modelriver tools is running:
modelriver websocket --workflow my_workflow --message "Cancel order 1041" \ --end-user user_812 --cli-session cts_...When a call to a tool that changes something waits for approval, the command prints the tool, its approval prompt, the arguments shown to the end user and the commands that decide it (modelriver tools approve and reject), then each decision. It waits 5 minutes for a response, and while calls wait for approval, until the last one expires plus 5 minutes.
The command exits with 1 if the wait ends or the connection closes before a response arrives. To follow the request again, use --channel-id and --project-id.
Backend pipeline workflows
For backend pipeline workflows, websocket first receives status: "ai_generated" and keeps waiting. Complete the flow with:
modelriver callback --channel-id CHANNEL_ID --data '{"summary":"..."}'Then the CLI prints the final completed response.
Troubleshooting
"WebSocket connection failed"
- Verify the API URL is correct
- Check that the
ws_tokenhasn't expired (24-hour limit for CLI tokens) - Check that the API key hasn't been revoked: revoking a key closes its CLI connections, and its token can't reconnect
- Check network connectivity
- If using production, ensure you're using
wss://(secure WebSocket)
Connecting is refused with 403 cli_access_ended
The API key was created by someone who is no longer in the organization. If the key was kept, it still works for API requests, but it can't open a CLI connection. Create a new API key and use that one.
Timeout waiting for response
- For backend pipeline workflows, send a callback within 10 minutes
- Check server logs if the workflow failed before broadcasting
Next steps
- Listen: Monitor webhook events via WebSocket
- Trigger: Send requests without WebSocket monitoring
- Callback: Complete backend pipeline flows
- Client SDK: Frontend WebSocket integration