> ## Documentation Index
> Fetch the complete documentation index at: https://docs.atlaso.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Browser and phone apps

> Mint short-lived tokens on your server so a browser or phone can call the gateway without your secret key.

Keep your `sk-at-` key on your server. A browser token is bound to one signed-in app user, lasts 15 minutes by default (one hour maximum), and is read-only for memory unless you choose otherwise. A phone app uses the same token route. Store tokens in memory, and revoke them on logout. A stolen token can act as that user until it expires or is revoked.

## Mint in a signed-in server route

Your authentication layer must return your own stable user id. The route below is shaped like a Next.js route handler. It sends only the options you set and tells the browser when to refresh. Do not cache its response.

```typescript theme={null}
import { Atlaso } from "atlaso";

const atlaso = new Atlaso(); // ATLASO_KEY stays on the server

export async function POST(request: Request) {
  const userId = await requireUserId(request); // your sign-in check
  const token = await atlaso.forUser(userId).createBrowserToken({
    ttlSeconds: 900,
    limits: { models: ["openai/gpt-4o-mini"], dailySpendUsd: "0.50", memory: "read_only" },
  });
  return Response.json(
    { token: token.token, expiresIn: token.expiresIn },
    { headers: { "cache-control": "no-store" } },
  );
}
```

For Python servers, use the same signed-in user id:

```python theme={null}
from atlaso import Atlaso

def mint_for_signed_in_user(user_id: str) -> dict[str, object]:
    atlaso = Atlaso()  # ATLASO_KEY stays on the server
    token = atlaso.for_user(user_id).create_browser_token(
        ttl_seconds=900,
        limits={"models": ["openai/gpt-4o-mini"], "daily_spend_usd": "0.50", "memory": "read_only"},
    )
    return {"token": token.token, "expiresIn": token.expires_in}
```

Send `Cache-Control: no-store` on your Python response too. `AsyncAtlaso` has the same methods with `await`.

## Call from the browser

The SDK refreshes a function-supplied token after 80% of its reported lifetime. If the gateway says `browser_token_invalid`, it fetches a fresh token and retries that request once. A fixed token string cannot refresh.

```typescript theme={null}
import OpenAI from "openai";
import { Atlaso } from "atlaso";

const atlaso = new Atlaso({
  browserToken: async () => {
    const response = await fetch("/api/atlaso-token", { method: "POST" });
    if (!response.ok) throw new Error("Sign in again to continue.");
    return response.json() as Promise<{ token: string; expiresIn: number }>;
  },
});
const openai = new OpenAI(atlaso.clientOptions());

export async function answer(question: string) {
  return openai.chat.completions.create({
    model: "openai/gpt-4o-mini",
    messages: [{ role: "user", content: question }],
  });
}
```

`atlaso.memory.list()` reads this token's user; do not call `forUser()` in token mode. Read-only tokens cannot add or delete facts. Erasure and token management stay on your server.

On logout, call `atlaso.forUser(userId).revokeBrowserTokens()` on the server, or `atlaso.revokeBrowserToken(tokenId)` for one token. Do not send your `sk-at-` key to a phone or web worker.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.