Skip to content

Set up AnyCable+ with a coding agent ​

This page is a prompt for coding agents. To use it, give your agent this line:

txt
Read https://docs.anycable.io/plus/agent-ready.md and set up AnyCable+ for this app.

You add realtime features (WebSockets) to this app with AnyCable+: managed AnyCable servers hosted at https://plus.anycable.io. The CLI is anycable-plus.

Each hosted server is a cable with its own WebSocket URL. The free plan has 2 cables: one for development, one for production.

1. Install the CLI and log in ​

sh
curl -LSs https://anycable-plus.terminalwire.sh/stable | bash

Open a new shell. Then log in:

sh
anycable-plus login

The human must approve the login in the browser. If the browser does not open, show the printed URL to the human. Wait for the command to return, then check with anycable-plus whoami.

2. Get a cable ​

List the cables first: anycable-plus cables. If the human gave you a cable ID, or a cable for this app exists, use it. Otherwise, create one:

sh
anycable-plus cable create <app-name> --framework <framework> --wait
  • <app-name>: a short name for the cable, for example the app's name.
  • --framework: rails for any Rails app, laravel for Laravel, js for Node.js, hotwire for Hotwire apps without Rails. Leave it out for other stacks.
  • Do not pass --public. It turns authentication off.
  • If you hit the cable quota, ask the human which cable to reuse.

--wait waits until the cable is ready and prints its ID.

3. Configure the app ​

Print the cable's settings as env vars:

sh
anycable-plus cable info <ID> --env

The output includes the secret. Do not repeat it in messages or logs. Put the lines where the app keeps its secrets: Rails credentials, a git-ignored .env, or the hosting platform's settings. If you are not sure, ask the human.

  • Rails, Node.js, Python, other: use the lines as they are. The SDKs and the guides below derive the broadcast key from ANYCABLE_SECRET.
  • Laravel: use the REVERB_* lines. Also set BROADCAST_CONNECTION=reverb.

Other lines, for example ANYCABLE_RPC_HOST or ANYCABLE_TURBO_STREAMS, show the cable's own configuration. The app does not need them.

Then wire the app:

  • Rails: install the skill with npx skills add anycable/anycable-rails and follow it. The cable exists, so skip the cable creation step in the skill.
    • No custom channels: run the generator with --rpc=none --development=skip. Development then uses the cable, with no local server.
    • Custom channels: run the generator with --rpc=http --development=puma. Do not use the cable in development. In production, give the cable the app's RPC URL: anycable-plus cable update <ID> --rpc-host <URL>.
  • Laravel: follow https://docs.anycable.io/guides/laravel.md. The cable speaks the Pusher protocol, so the app keeps its Reverb broadcaster with the REVERB_* values from the cable.
  • Node.js and serverless JavaScript: follow https://docs.anycable.io/guides/serverless.md.
  • Python: follow https://docs.anycable.io/guides/python.md.
  • Other backends: follow https://docs.anycable.io/quickstart.md (signed streams and JWT).

4. Verify ​

Confirm that the app reaches the cable before you report success.

First, ask the human to open the cable's live logs: the cable's page in the dashboard (https://plus.anycable.io/cables), then Troubleshooting, then Logs. Ask the human to tell you what shows up in the logs at each step.

Connect ​

Load the cable's settings into the shell first. This keeps the secret out of the output:

sh
set -a; eval "$(anycable-plus cable info <ID> --env)"; set +a
export ANYCABLE_BROADCAST_KEY=$(echo -n 'broadcast-cable' | openssl dgst -sha256 -hmac "$ANYCABLE_SECRET" | awk '{print $2}')

Do a WebSocket handshake with curl. curl does not accept wss://, so the command changes the scheme to https://:

sh
curl -sS -i -N --http1.1 --max-time 5 "${ANYCABLE_WEBSOCKET_URL/wss:/https:}" \
  -H "Connection: Upgrade" -H "Upgrade: websocket" \
  -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \
  -H "Sec-WebSocket-Protocol: actioncable-v1-json"

Expect 101 Switching Protocols, then the first message:

  • {"type":"disconnect","reason":"unauthorized",...}: the cable works and requires a token. This is correct for a cable with a secret.
  • {"type":"welcome",...}: the cable accepts the connection (a public cable).

blank argument from curl means that the variables are not loaded.

Then open a page of the app that subscribes. Check in the browser that its WebSocket gets a welcome message. The logs show the connection and the subscription.

Broadcast ​

Publish a broadcast with curl:

sh
curl -sS -i -X POST "$ANYCABLE_HTTP_BROADCAST_URL" \
  -H "Authorization: Bearer $ANYCABLE_BROADCAST_KEY" \
  -H "Content-Type: application/json" \
  -d '{"stream":"test","data":"{\"text\":\"Hello\"}"}'

Expect 201 Created. A 401 Unauthorized means a wrong broadcast key. The logs show the broadcast.

Then broadcast from the app. From Rails:

sh
bin/rails runner 'ActionCable.server.broadcast("test", {text: "Hello"}); AnyCable.broadcast_adapter.shutdown'

Without shutdown, runner exits before it sends the message.

If something fails ​

  • Rejected connections or subscriptions: the app and the cable have different secrets.
  • No connection at all: ask the human to click Start diagnostic on the Troubleshooting page. It checks the cable's status and its WebSocket endpoint.

Next steps ​