The default path: a site embeds the router in a hidden iframe A browser window for aifoc.us contains a hidden iframe from llmchannel.dev. Inside the iframe sit a main worker (frame-worker.js), a single-endpoint call worker (call-worker/anthropic.js), and partitioned per-site IndexedDB storage. A separate popup window for llmchannel.dev/pick.html reads unpartitioned top-level storage holding saved accounts. Thirteen numbered hops trace opening a port to the iframe, locating the iframe through window.opener, re-encrypting the API key over Web Crypto, counting requests atomically in partitioned storage, sending prompts through the call worker to the model provider, and streaming tokens back. aifoc.us/in-browser-ai-router/ A site's page Holds one end of a port. Never sees the key. Hidden iframe: the router frame Reads the host origin from the browser. llmchannel.dev/frame.html In your browser, for this site Partitioned per host site. No server. the grant encrypted key Worker Holds the site's port. Counts every request against the limit. No network access. llmchannel.dev/frame-worker.js Call worker Decrypts key in memory. No DOM. Strict CSP allows one endpoint out, no other code in. llmchannel.dev/call-worker/anthropic.js CSP: only api.anthropic.com/v1/messages llmchannel.dev/pick.html Popup window: the router window Open only while you choose. In your browser: the router's storage Only a top-level router window can read it. your accounts keys, encrypted Model provider api.anthropic.com or another 1 2 3 4 5 6encrypts your key 7 8closes 9 10 11 12 13
All 13 hops visible

All 13 steps shown. Press Step through it or select any numbered marker to inspect each hop.

Solid boxes with address bars are browser windows; dashed boxes are iframes. Boxes with a cog are Dedicated Workers, shaded boxes are local browser storage, and the rounded box is the remote model API. When a host blocks third-party frames, the router keeps pick.html open and runs both workers inside the popup instead. If a browser fails to enforce Dedicated Worker CSP, the call worker falls back to a hidden /call/<provider> iframe.
Read all 13 steps as text

When the site loads

  1. The site appends a hidden llmchannel.dev/frame.html iframe and transfers one end of a MessageChannel into it, keeping the other end as its prompt port.
  2. The iframe spawns frame-worker.js (with connect-src 'none') and forwards the site's prompt port into it.

When you choose a model

  1. You click Connect / Choose a model, which opens llmchannel.dev/pick.html as a top-level popup that can read your saved accounts.
  2. pick.js loops through opener[i] frames and posts a fresh popup-to-iframe port with targetOrigin pinned to https://llmchannel.dev so the browser drops host decoys.
  3. The real router iframe replies on that port with the browser-stamped host origin (captured on step 1) and an ephemeral ECDH P-256 public key. The popup shows that origin for approval.
  4. You pick an account, model, and request/day cap. Web Crypto re-wraps your API key directly from top-level storage to the iframe's public key without exposing plaintext in popup JS.
  5. The popup sends the grant metadata and wrapped ciphertext across that port to the iframe, which stores them in partitioned IndexedDB alongside its non-extractable ["decrypt"] CryptoKey.
  6. The popup closes, leaving no router UI on screen.

On every prompt (or lent MessagePort / Pi turn)

  1. The host site posts a prompt and a fresh per-request reply port down the site-to-iframe port into frame-worker.js.
  2. frame-worker.js verifies expiry and cap in one readwrite IndexedDB transaction and increments the request counter atomically (deleting the grant if spent).
  3. The worker forwards the prompt, ciphertext, and ["decrypt"] handle to /call-worker/<provider>.js (a Dedicated Worker whose CSP allows outbound requests only to that provider's single URL).
  4. After verifying its own CSP via securitypolicyviolation, the call worker decrypts the API key in memory and sends the HTTPS request straight to the model provider.
  5. The provider streams chunks back through the call worker and frame-worker.js down the reply port to the host site.