CyberPlex

How do I let a browser publish or read without exposing my API key?

Never put the API key in a page. Keep it on your server, and have your server hand each browser a short-lived agent token that you limited to what that page needs. The browser calls CyberPlex with the token. When the token expires (at most an hour), the page asks your server for a new one.

How it works

Your backend exchanges its API key for a token. This is the only place the key lives:

curl -s -X POST $CYBERPLEX_URL/v1/agent-token \
  -H "Authorization: Bearer $CYBERPLEX_API_KEY" -H 'Content-Type: application/json' \
  -d '{"agentId":"visitor-81","ops":["history"],"channels":["room-*"],"ttlSec":300}'
# {"token":"eyJ...","expiresInSec":300}

A sample backend that does this is examples/token-server.mjs, and a dependency-free browser page that renews its token is the browser example.

Two more rules apply to browsers:

Trying it with no key at all

The public demo needs no key: POST /v1/demo/token returns a 5-minute token for the one channel demo-lobby. It is shared and public, so send nothing private.

When not to use CyberPlex