{"slug": "in-browser-llm-router-without-exposing-api-keys-to-every-page", "title": "in-browser LLM router without exposing API keys to every page", "summary": "A developer built an in-browser LLM routing pattern using the MessageChannel API and entangled Port API, demonstrated through the side project port-authority.dev, to let client-side web apps call language models without exposing API keys to every page. The work responds to a previously highlighted problem that any browser-based app calling a language model must otherwise embed or expose its keys. The post details inter-frame communication patterns, including delegated discovery between apps that do not know about each other.", "body_md": "A forewarning, this is a really long post, but I think you will like it.\n\nI have a very soft spot for the [`MessageChannel`](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel) API. I think it’s magical, and I’ve been building a side-passion project [port-authority.dev](https://port-authority.dev) that aims to showcase some of the patterns for inter-site or inter-frame communication that is enabled by the entangled `Port` API. It enables some experiences that I think most web developers don’t know, including features like delegated discovery and subsequent communication between two apps that don’t know about each other. During the development of this project it enabled me to answer a problem that I found in “[calling apis from the browser shouldn’t mean exposing keys](https://aifoc.us/dangerous/)” which highlighted the problem for anyone building a client-side web app that calls a language model, you have to either:", "url": "https://wpnews.pro/news/in-browser-llm-router-without-exposing-api-keys-to-every-page", "canonical_source": "https://aifoc.us/in-browser-ai-router/", "published_at": "2026-12-03 22:00:00+00:00", "updated_at": "2026-12-04 00:13:56.147249+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models", "ai-agents"], "entities": ["MessageChannel", "port-authority.dev", "Port API"], "also_reported_by": [], "takeaway": "Route LLM calls through a MessageChannel-based broker frame so API keys stay in one trusted context instead of being embedded in every page that calls the model.", "recommendation": {"advice": "Keep model API keys in a single trusted broker frame and route requests from untrusted pages over MessageChannel ports rather than embedding credentials in each client-side app.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/in-browser-llm-router-without-exposing-api-keys-to-every-page", "markdown": "https://wpnews.pro/news/in-browser-llm-router-without-exposing-api-keys-to-every-page.md", "text": "https://wpnews.pro/news/in-browser-llm-router-without-exposing-api-keys-to-every-page.txt", "jsonld": "https://wpnews.pro/news/in-browser-llm-router-without-exposing-api-keys-to-every-page.jsonld"}}