Sealed AI
यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।
An AI chat that nobody but the user can read. Not you, not Geometer, not the cloud company. Before it sends anything, the browser checks that the AI server is a sealed, hardware-protected machine running code the provider has published and signed. Then it encrypts the chat to that machine only.
Sealed AI uses open models at one provider today: Tinfoil (provider: "tinfoil"). It works with the openai client: chat completions and responses.
What this does not protect
- Your app’s own code. The code that makes the call runs inside your app. If you ship changed code, it can read the chat before it is sealed.
- The sealed server itself. The chat is readable inside the sealed machine, which answers it. You trust the chip maker (AMD) and the code the provider publishes.
- The GPU. Tinfoil checks the GPU when the machine starts. The user’s device does not. The receipt says so.
- Closed models. GPT, Claude and Gemini are not available here. Use Masked AI for those, and read what it does not protect.
- Anything outside the chat. What you save about a chat in your own database is not covered. Use Vault for that.
The full list: limits and threat model.
Never put the AI provider’s key in the browser. The browser calls your own server route. The route holds the key.
How it works
Section titled “How it works”Browser Your server route Sealed server 1. asks for evidence -----> forwards -------------------> sends evidence 2. checks the evidence 3. encrypts the chat -----> adds the key, forwards sealed -> opens it, answers 4. decrypts the answer <---- forwards <------------------- sends sealed answerWhat the browser checks before it trusts the server’s key:
| Check | What it means |
|---|---|
| Chip signature | The evidence is signed by a genuine AMD chip, through AMD’s certificate chain. |
| Code measurement | The server started with exactly the code of the provider’s latest signed release. The browser checks the release signature itself. |
| Key binding | The encryption key belongs to that machine: it sits inside the signed evidence. |
| Policy | Debug mode and the migration agent are off. |
Your route forwards evidence requests and sealed bodies only. It refuses a plain body with sealed-ai/plain-body. A wrongly wired app cannot leak plain text through this route.
If the check fails, the call fails. It does not retry as Masked AI or as a plain call.
Release checks and the floor
Section titled “Release checks and the floor”A signed release stays valid forever. So the SDK has a floor, MIN_RELEASE: the oldest provider release it accepts. A release below the floor fails with sealed-ai/release-too-old. You can only raise the floor, with minRelease. Updating @geometer/trust raises it too.
While the provider rolls out a new release, some servers still run the one before. The SDK then checks that one release back, once, and accepts it only if it is at or above the floor. The receipt notes this.
The verified key is kept in memory for 5 minutes. After that, or when the server’s key changes, the browser checks again.
Make the first message fast: prewarmSealedAI
Section titled “Make the first message fast: prewarmSealedAI”The check takes a few round trips to AMD, GitHub and the provider (about three in a row, and about 6 seconds on a slow first visit before the pre-warm existed). Start it while the user is still reading the page. Call prewarmSealedAI when the chat page or component mounts:
import { prewarmSealedAI } from "@geometer/trust/sealed-ai";
useEffect(() => { void prewarmSealedAI({ baseURL: `${window.location.origin}/api/trust/sealed-ai/v1` });}, []);It runs the same check the first chat would run and stores the verified key where sealedFetch looks for it, so the first message goes straight out. It sends no chat and no user text, never throws (it returns { ok: true } or { ok: false, code }), and is safe to call as often as you like: calls at the same moment share one check. If it fails, do nothing: the first message repeats the check and shows the real error. Pass headers with the same sign-in your client sends if your route’s authorize reads a token instead of a cookie. It warms the default settings; a sealedFetch with its own expectedMeasurement, minRelease, release: false or keyLifetimeMs keeps a separate check.
What is kept on the device, and why that is safe
Section titled “What is kept on the device, and why that is safe”To save the network on the next visit, the browser keeps the PUBLIC documents it fetched for the check in IndexedDB (database geometer-trust-sealed-cache; memory only where IndexedDB is missing): AMD’s certificate chain (24 hours), the chip’s certificate (it never changes for that chip and firmware level), AMD’s revocation list (24 hours at most, or until its own next-update date if that is sooner), the release record and its signature record (they never change for a release), the latest release tag (5 minutes), and the provider’s evidence and key file (5 minutes, only so a quick reload does not ask again). At most 50 entries are kept, least recently used first.
This is safe because the cache holds raw documents, never an answer. The checker runs again on every page load, on every document, cached or fresh: the chip signature, the AMD chain, the release signature, the key binding and the clock. Changing a stored byte can only make the check fail; it cannot make it pass. A stored document that makes the check fail is deleted and fetched again once. If the check fails again, the call fails as before. A verdict, a verified key or a receipt is never stored across page loads. An entry past its time is never used again, not even when AMD or GitHub is busy; a still-valid entry is used when they are busy, so a rate limit does not stop a returning visitor. If the device clock moves back, stored entries count as expired.
One full example: Next.js
Section titled “One full example: Next.js”1. The server route, app/api/trust/sealed-ai/[...path]/route.ts:
import { sealedRoute } from "@geometer/trust/sealed-ai/server";import { isSignedIn } from "@/lib/authorize"; // your own check of the session: see the Next.js recipe
const handler = sealedRoute({ provider: "tinfoil", apiKey: process.env.SEALED_AI_KEY!, authorize: (request) => isSignedIn(request), // required: only signed-in users may use your key});
export const GET = handler;export const POST = handler;authorize is required, and it guards the evidence calls too. If it is missing, sealedRoute throws sealed-ai/no-authorize when your server starts. If it returns false, the route answers 401 with sealed-ai/not-authorized. Never use authorize: () => true unless you are building a public demo.
Add SEALED_AI_KEY=... to .env.local and to your host’s environment settings. Do not prefix it with NEXT_PUBLIC_. That prefix sends the value to the browser.
2. The browser, src/privateChat.ts:
import OpenAI from "openai";import { findTrustError, sealedFetch } from "@geometer/trust/sealed-ai";
const ai = new OpenAI({ baseURL: `${window.location.origin}/api/trust/sealed-ai/v1`, apiKey: "not-used", // the real key lives only on the server dangerouslyAllowBrowser: true, maxRetries: 0, // see "Handle a failure" below fetch: sealedFetch({ app: "my-app", // the receipt ledger's owner onReceipt: (receipt) => { // Keep it if you want to show a badge or let the user export proof. console.log("Sealed AI receipt", receipt.id); }, }),});
export async function privateChat(question: string) { const reply = await ai.chat.completions.create({ model: "<model>", // an open model that Tinfoil offers messages: [{ role: "user", content: question }], }); return reply.choices[0]?.message.content;}
/** The Sealed AI error inside whatever the client threw, or undefined. */export function sealedFailure(err: unknown) { const problem = findTrustError(err); return problem?.mode === "sealed-ai" ? problem : undefined;}dangerouslyAllowBrowser: true is a flag of the openai package. It is safe here because the browser holds no real key.
The browser must be Chrome 133 or later, Firefox 130 or later, or Safari 17 or later, with WebAssembly on. Otherwise the call fails with sealed-ai/not-verified and says so.
Handle a failure
Section titled “Handle a failure”The openai client wraps any error from a custom fetch: you catch APIConnectionError("Connection error."), and the Trust error sits in .cause. The client also retries it twice by default. A failed Sealed AI call must not be repeated blindly. So:
- Create the client with
maxRetries: 0. - Read the error with
findTrustError(err), notinstanceof.
try { const answer = await privateChat("Summarise my medical notes."); show(answer);} catch (err) { const problem = sealedFailure(err); if (problem) { // Say so in plain words. Do not send the chat another way. showMessage(problem.message); } else { throw err; }}Never catch a sealed-ai/... error and send the same text through Masked AI. That breaks the promise you made to the user. The codes are in errors.
Options of sealedFetch
Section titled “Options of sealedFetch”| Option | Meaning |
|---|---|
onReceipt, onReceiptError, app, user, receiptStore |
Receipts. See proof and the badge. Pass user so people who share a browser do not share receipts. |
onEvidence(report) |
Called after each successful check with the checked result, the documents, the release tag and the time. Errors in it are ignored. |
minRelease |
Raise the oldest provider release you accept, for example "v0.0.185". It cannot lower the floor. |
expectedMeasurement with release: false |
Advanced. You pin the code measurement (96 hex characters) and the SDK makes no release calls. release: false without expectedMeasurement throws sealed-ai/no-expected-measurement. |
keyLifetimeMs |
How long a verified key is trusted. Default 5 minutes. |
Options of prewarmSealedAI: baseURL (required), provider, headers, credentials, fetch, signal, evidenceTimeoutMs. An option it does not know returns { ok: false, code: "sealed-ai/bad-option" }.
Options of sealedRoute: provider ("tinfoil"), apiKey, authorize, limits, allowedOrigins, baseURL (default https://inference.tinfoil.sh), maxBodyBytes (default 4 MB) and fetch (tests and custom runtimes).
Limits and other sites
Section titled “Limits and other sites”Set limits on every route. Without it, one signed-in user in a loop can spend as much of your key as the provider allows.
sealedRoute({ provider: "tinfoil", apiKey: process.env.SEALED_AI_KEY!, authorize: async (request) => { const id = await getUserId(request); // your own check of the user's session return id ? { user: id } : false; // { user } names the user, so limits count per user }, limits: { perUser: { requestsPerMinute: 10, requestsPerDay: 200 }, perRoute: { requestsPerMinute: 120 } },});authorize may return true or { user }; or give limits.key(request) to return the user id. Over the limit the route answers 429 sealed-ai/rate-limited with Retry-After. Only calls that spend your key are counted: sealed chats and the models list. The public evidence calls (attestation, key file, AMD certificates, release records) are not. Count requests only: sealed bodies are encrypted, so the route cannot read or cap the size of an answer, and limits.maxOutputTokens is refused at setup (sealed-ai/bad-limits). Ask the model for short answers in your own prompt and use perUser.requestsPerDay as the ceiling.
Counters live in this process’s memory by default: fine for one server, wrong for serverless hosts, where you pass a shared store (Redis, Upstash, Supabase). The LimitStore interface and a Redis example are in Masked AI; it is the same for both routes.
A route answers its own site only: a call a browser marks as coming from another website is refused with 403 sealed-ai/cross-origin before authorize runs. Calls without browser headers still go to authorize. For a front end on another origin, set allowedOrigins: ["https://app.example.com"]; the route then answers that origin’s preflight and sends CORS headers for it only. Add export const OPTIONS = handler; in Next.js. A Supabase Edge Function is another origin than your app’s page, so it needs allowedOrigins.
Where the route can run
Section titled “Where the route can run”The route works under any path that contains /sealed-ai/. Next.js and Supabase Edge Functions work as in the recipes; Express needs toNodeHandler from @geometer/trust/sealed-ai/server.
What the route calls, and nothing else:
| Call | Method |
|---|---|
| The provider’s evidence and key file | GET |
| AMD certificate paths, in exact shapes, from one fixed AMD host | GET |
| The provider’s signed release records from one fixed GitHub repository (cached) | GET |
| The models list | GET (adds your key) |
| Chat completions and responses, sealed bodies only | POST (adds your key) |
Everything else answers 403 sealed-ai/path-not-allowed. The route drops your user’s Authorization, x-api-key and Cookie, follows no redirects and logs nothing. It cannot cap the cost of sealed calls, because it cannot read the model or the length. Set a spending limit at the provider.
The browser client refuses these on purpose:
| Case | Error |
|---|---|
| A real-looking provider key in a header | sealed-ai/key-in-browser |
A baseURL that does not go through /sealed-ai/ |
sealed-ai/not-via-route |
| Anything except a POST to chat completions or responses | sealed-ai/unsupported-path |
Common mistakes
Section titled “Common mistakes”| Mistake | What goes wrong | Do this instead |
|---|---|---|
Writing authorize: () => true |
Anyone who finds the route can spend your key. | Check the user’s real session. |
Putting the provider key in the browser (a VITE_ or NEXT_PUBLIC_ variable, or in apiKey) |
Anyone can read it and run up your bill. | Keep it in the server route’s environment. Keep apiKey: "not-used" in the browser. |
Leaving maxRetries at its default |
The client retries a failed check. | Set maxRetries: 0. |
Checking err instanceof TrustError |
The client wrapped the error, so the check is false. | Use findTrustError(err). |
| Retrying a failed Sealed AI call as Masked AI or a plain call | The chat is no longer sealed. The user was told it was. | Show the error. Let the user try again. |
| Calling the provider directly from the browser | No evidence check. No seal. | Always call your own route. |
| Sending plain JSON to the sealed route | The route refuses it (sealed-ai/plain-body). |
Use sealedFetch() on the browser client. |
Using a closed model name such as gpt-4o |
The provider does not host it. | Use an open model Tinfoil offers. |
| Showing the badge as if the badge were proof | Anyone can draw a badge. | Link to the receipt. See proof and badge. |
See also: API reference, errors, recipes.