Documentation

modelriver websocket

Test real-time WebSocket connections to ModelRiver. Send requests and receive AI responses directly in your terminal.

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

Bash
# Test with workflow
modelriver websocket --workflow my_workflow --message "Hello from CLI"
 
# With custom payload
modelriver websocket --workflow my_workflow --payload '{"messages": [{"role": "user", "content": "Test"}]}'
 
# Connect to existing channel
modelriver websocket --channel-id abc-123 --project-id xyz-789
 
# Verbose output
modelriver websocket --workflow my_workflow --message "Test" --verbose

Example 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

OptionDescription
--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
--verboseShow 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:

Bash
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:

Bash
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_token hasn'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