AI router: use your own model account on any site
A site asks for an AI model. A window from the router opens and you pick one of your own accounts. The site gets a MessagePort to send prompts on. It never sees your API key, and you can stop it at any time.
Try it on this page
This page is a site like any other. It has no AI account. Press the button, pick the practice model (no API key needed) or an account of your own, then send a prompt.
Nothing yet.
- Nothing yet.
Two other sites use the same router. Each has to ask you separately, and each gets its own limit.
What it is for
Today a site that wants to use a model has two choices. It can pay for the model itself and run a server that hides its key. Or it can ask you to paste your API key into its page, where its scripts can read it and send it anywhere.
With the router you give your key to one place that you choose to trust. Every other site asks that place for access and gets a port. A site can use the port, but there is no key in it to copy.
- You add each key once, at the router's address.
- A site asks. You see its address, pick an account and a model, and set a limit in requests and days.
- The site sends prompts and reads answers. It is told the model's name and how many requests are left.
- The router's page lists every site you allowed and what it has used. Stop takes effect on the site's next request.
The code a site writes
A site can pass its access on. lend() returns a second port into the same grant. Post it to a worker or to an iframe from another site, and wrap it there with fromPort(). With a limit, the port stops after that many requests. A lent port cannot lend again.
// on the page const port = await ai.lend({ requests: 3 }); worker.postMessage({ job: "summarise" }, [port]); // in the worker import { fromPort } from "/router.js"; onmessage = async (event) => { const ai = fromPort(event.ports[0]); const text = await ai.prompt("Summarise this in one line: ...").text(); };
How it works
The first time a site asks
- The site's script adds a hidden iframe from the router's address and posts it one end of a
MessageChannel. The site keeps the other end. - The frame starts a worker and posts that port on to it. From here the site's page talks to the worker directly. The frame only keeps the grant in storage, because a worker has no
localStorage. - On a click, the script opens the picker window. The picker is a normal top-level window at the router's address, so it can read the accounts you saved there.
- The picker has to find the router frame inside the page that opened it. It posts a message to each of that page's frames with the router's address as the required target origin. The browser drops the message for any frame that is not a router page. The message carries a port, so the picker and the frame now have a line the site cannot listen to.
- The frame tells the picker which site it is inside. The frame learned that from the browser when the site said hello, not from anything the site wrote. The picker shows you that address.
- You choose. The picker records the grant on the router server and gets back an unlock key. It encrypts your API key with it and posts the grant and the encrypted key to the frame over the private port. The frame stores them and passes them to the worker. The picker closes.
Every prompt
- The site posts the prompt on its port, with a new port for the answer. It arrives in the worker.
- The worker asks the router server whether the grant is still good. The server counts the request and returns the unlock key, or refuses.
- The worker decrypts the API key in memory, calls the provider directly from the browser, and posts each piece of the answer to the reply port. Your prompt and the answer go to the provider and nowhere else.
- The site can post
cancelon the reply port to stop the request.
Where the ports end up
Every port leads to the same worker. The site's page holds one. A worker the site starts can hold another, and so can an iframe from a third site that the page chooses to lend to. None of them can open the router window, and none holds a key. The browser's built-in model cannot be used from a worker, so for that one the frame lends the worker a port and answers on it.
After a reload
The frame stored the grant under the site's address, so the site has its model again with no window. If you pressed Stop in the router, the server has deleted the unlock key. The encrypted key left inside that site can no longer be opened, and the frame deletes it the next time it checks.
Who holds what
| Part | Can read your API key | Can read your prompts | What it holds |
|---|---|---|---|
| The site | No | Yes, it wrote them | A port |
| Router frame inside the site | No, it stores an encrypted copy | No | The grant and an encrypted key |
| Worker inside the router frame | Only while a request runs | Yes, it sends them | Every port, and the grant in memory |
| Picker window and router page | Yes | No | Your accounts, in the browser's storage for the router's address |
| Router server | No | No | For each grant: the site's address, the account name and model name, request and token counts, and an unlock key |
| Model provider | Yes, it issued it | Yes | Your prompt and answer while processing (per its retention policy) |
What does not work yet, and what to know
- You are trusting the router's code. The frame and the picker are pages from the router's address, and they handle your key. A site is kept away from the key by the browser's rule that a page cannot read a frame from another origin.
- The router's pages and its worker are served with a Content-Security-Policy. They can run only the router's own scripts and can connect only to the router and to Anthropic, OpenAI, OpenRouter, Google Gemini and an Ollama on your own computer. A changed or injected script could not send your key anywhere else.
- There is one small server, and it exists because browsers give a frame separate storage inside each site. The list of grants is the only thing that has to be seen from everywhere, so that Stop works and the router page can show usage. It holds no keys and sees no prompts or answers.
- It only works for providers that accept calls from a browser. Anthropic does when the request carries the
anthropic-dangerous-direct-browser-accessheader. A provider that sends no CORS headers cannot be used. - Your key is visible in your own browser's network tools when the frame calls the provider. Other sites still can't see it.
- Limits are counted in requests and days, not money. A site with 20 requests can still send 20 long prompts.
- The site sees every answer. The router controls who pays and how much. It does not control what the site does with the text.
- The Anthropic path was tested against a stand-in server, not with a real key. The OpenAI, OpenRouter, Gemini and Ollama paths have not been run at all yet. Only Chromium has been tested.
- There is no tool calling and no images yet. Prompts and answers are text.