---
title: Embed a session (preview)
summary: Show an Argus agent in your own web page: your backend mints a short-lived token for one end user, and the browser streams and posts to Argus directly.
section: build
order: 4
---
> **Preview, not yet available to customers.** Embedding is built and under test, but it is not enabled for invited projects yet. This page describes how it will work. It is not part of [Getting started](/docs/getting-started.md); for now, use the app or the [API](/docs/api.md).

An Argus session can live inside another product's page: a support panel, an in-app assistant, a guide beside a form. The page shows the conversation with Kurth Labs Design's chat components (`<ArgusEmbed>`), in the host's own skin and accent, and talks to Argus directly, so the host needs no streaming proxy of its own.

This works with a **client token**: a credential your backend mints for one end user and one session, valid for minutes, that can read and post to that session and to nothing else. Your app's own credential never reaches the browser.

```
your backend ──(1) mint a token with your Argus credential──▶ Argus
your page    ◀─(2) the token ────────── your backend
your page    ──(3) stream, post, approve with the token──────▶ Argus   (from an origin you listed)
```

## What you need

- A project, and an agent in it (`acme/helper`).
- A credential for your backend in that project: an app client (see [Your first token](/docs/api.md#your-first-token); creating the Tessera client for it is Planned), or, while you try this out, a project owner's token.
- The project's **allowed origins** list with your page's origin on it.
- An API address the end user's browser can reach: `https://api.kurthlabs.com/argus`, once embedding is enabled for your project.

## 1. Allow your page's origin

An owner adds the origins in the app under **Settings, Embedding**, or with the API:

```sh
curl -sS -X PUT https://api.kurthlabs.com/argus/v1/projects/acme/allowed-origins \
  -H "Authorization: Bearer $OWNER_TOKEN" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"origins": ["https://app.example.com"]}'
```

An origin is a scheme, a host and an optional port: `https://app.example.com`. No wildcards, no paths. `http` is accepted for `localhost`, `127.0.0.1` and `::1` so a dev server works. A project lists up to 20. Argus answers the browser's CORS preflight and adds CORS headers only for a listed origin, and only on the routes a client token can call; a client token used from any other origin is refused (`403 origin-not-allowed`).

## 2. Mint a token on your backend

Authenticate your own user first, then ask Argus for a token for them:

```ts
// POST /api/argus-token on your backend
const res = await fetch("https://api.kurthlabs.com/argus/v1/projects/acme/client-tokens", {
  method: "POST",
  headers: { Authorization: `Bearer ${ARGUS_CREDENTIAL}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    agent: "acme/helper",      // a new conversation; or `session: "<id>"` to reopen one
    end_user: user.id,         // your id for the person; Argus stores only a hash
    ttl_seconds: 900,          // 60 to 3600, default 900
    tools: "hidden",           // hidden (default), summary or full
  }),
});
const { token, expires_at } = await res.json();
return Response.json({ token, expires_at }); // give the browser these two, never your credential
```

The token is shown once and stored only as a hash. It is bound to:

- **one session**, or to **one agent**: an agent token may start exactly one session of that agent (as its end user, whatever the page sends) and is then bound to it;
- **one end user**: a session that already has an end user can only be minted for the same one (`409 end-user-mismatch`);
- **tools**: what the end user's browser sees of the agent's tool use. `hidden` (the default): tool calls and results are withheld, and the stream carries only a `tool.activity` marker (running or done, with the tool's title). `summary`: the call's name, title and state, never its arguments or results. `full`: the events as your team sees them. Approvals and questions always pass;
- **scopes**: by default `events:read` and `messages:write` (also when `scopes` is empty). Answering approvals or questions requires explicitly including `approvals:answer`. The others are `tool-results:write` (answer client-side tool calls) and `session:cancel` (stop a run). Ask for the fewest you need. This applies to new tokens in every `tools` mode; existing tokens keep their stored scopes until expiry or revocation. Hosts that previously relied on the default for human answers must now name `approvals:answer`.

Mint again for the same user when the page reloads or the token runs low; minting is cheap, limited to 300 a minute per project.

## 3. Render the session

```tsx
import "@kurthlabs/design/styles.css";
import { ArgusEmbed } from "@kurthlabs/argus-sdk/embed";

export function Assistant({ sessionId }: { sessionId?: string }) {
  return (
    <div style={{ height: 560 }}>
      <ArgusEmbed
        apiBase="https://api.kurthlabs.com/argus"
        project="acme"
        agent="acme/helper"            // the first message starts the session
        sessionId={sessionId}          // or open one the token was minted for
        getToken={() => fetch("/api/argus-token", { method: "POST" }).then((r) => r.json())}
        skin="inscribed"
        accent="lapis"
        placeholder="Ask about an order"
        onSessionStart={(id) => saveForReload(id)}
      />
    </div>
  );
}
```

`getToken` returns what your backend gave the page: the token string, or the `{ token, expires_at }` object. The component calls it when it needs a token, a minute before the token expires, and once more when Argus answers 401, and the conversation continues across the refresh. Open streams reconnect on their own, so a page left open past the token's lifetime keeps working. If your backend cannot give a token, the component says the conversation cannot be opened instead of retrying in silence.

It fills its container, so give the container a height. It needs React 18 or later and `@kurthlabs/design`; the SDK's main entry and `/react` do not need Kurth Labs Design.

| Prop | What it does |
| --- | --- |
| `apiBase`, `project` | Where Argus is and which project. |
| `getToken` or `token` | A function that returns a client token, or one you already have (not refreshed). |
| `sessionId` or `agent` | Show an existing session, or start a conversation with the agent on the first message. |
| `skin`, `accent`, `theme`, `density` | Kurth Labs Design theming, scoped to the component: your page and its `<html>` are left alone. Light or dark follows your page (`data-theme` or `color-scheme` on `<html>`, else the browser's preference) unless `theme` forces one. |
| `renderText` | Draws message text (pass Kurth Labs Design's `Markdown` for Markdown). |
| `emptyState`, `suggestions`, `placeholder`, `disclaimer`, `label` | The words around the thread. |
| `tools` | How much tool use the thread draws: `activity` (no rows, one quiet status line while a tool runs), `summary` (a row with the tool and its state) or `full`. It defaults to what the token allows (the `tools` of the mint, which `getToken` returns with the token) and never shows more than that: return the mint's answer, not just the string. Approvals and questions always show. |
| `hideTools`, `vars` | Hide tool calls by name; template variables sent with each message. |
| `composer` | Replaces the message box. It gets `send(string \| ContentPart[])`, so it can send images and files as well as text. |
| `onSessionStart`, `onError` | The conversation got its session; something failed. |

Tool calls that wait for approval show **Approve** and **Deny**; Deny sends the same answer as **Reject** in the app and the API (`rejected`), so the agent is told the call was declined and the run goes on. A free-text question the agent asks is answered in the message box (a "Replying to" line above it, with a cancel); a choice is answered with the buttons in the thread, and the box waits. `ConversationThread`, the thread itself, is exported too: it is what Ask Argus in the app renders.

Without the component, the SDK's `ArgusClient` takes the same token: `new ArgusClient({ baseUrl, project, token: () => mintedToken })`, and `session.events()` streams with reconnect.

## Revoking

```sh
curl -sS -X DELETE https://api.kurthlabs.com/argus/v1/projects/acme/client-tokens/$TOKEN_ID \
  -H "Authorization: Bearer $ARGUS_CREDENTIAL"

curl -sS -X POST https://api.kurthlabs.com/argus/v1/projects/acme/client-tokens/revoke \
  -H "Authorization: Bearer $ARGUS_CREDENTIAL" -H "Content-Type: application/json" \
  -d '{"end_user": "customer-42"}'
```

Revoking takes effect on the token's next request; an open stream closes within 15 seconds. Revoke on logout and when a person is removed. `GET /v1/projects/acme/client-tokens` lists a project's tokens (their ids, scopes, end user hash and times, never the token).

## What a client token can and cannot do

| It can | Scope |
| --- | --- |
| Read its session, its events and stream, its artifacts | `events:read` |
| Post messages to its session, with images it uploads first (an agent token: start the session) | `messages:write` |
| Answer approvals and questions in its session | `approvals:answer` |
| Answer client-side tool calls | `tool-results:write` |
| Stop a run | `session:cancel` |

It cannot reach another session or project (`404`), a route outside this list (agents, tool sources, keys, members, usage, the Admin area, deleting a session: `403`), or mint another token. Each token is limited to 600 requests and 30 writes a minute (`429 rate-limited`, with `Retry-After`), on top of the project's own quotas and budgets. Mints, session binds, revokes, changes of the allowed origins and attempts outside the token's scope are recorded with the token's id, never the token.

What the end user sees is the conversation: messages, approvals and questions, run progress, artifacts and errors, and the agent's tool use as far as the token's `tools` allows. With the default `hidden`, a tool's arguments and results never leave Argus for that browser, in the event pages or the stream. Model names, token and cost figures, budgets and judge or loop internals are not sent, and people in the project who acted in the session appear without a name. **What the agent writes in its answers, and what it saves as artifacts, is visible to the end user**, and so is everything a tool returns if you mint with `full`. Design an agent for embedding the way you would a public page: no secrets in its answers.

To give the status line words, add `titles` to a tool grant in the agent definition: `tools: [{ source: orders, allow: [lookup], titles: { lookup: "Looking up your order" } }]`. The model never reads titles; a `hidden` token's activity marker carries the title, and the component shows "Looking up your order…" while the tool runs, or "Working…" without one.

## Errors the page may see

| Status | `type` | Meaning |
| --- | --- | --- |
| 401 | `token-expired`, `token-revoked`, `invalid-token` | Get a new token. |
| 403 | `forbidden`, `origin-not-allowed` | Outside the token's scope, or the page's origin is not listed. |
| 404 | `not-found` | Not the token's session. |
| 409 | `token-bound` | The agent token already started its session. |
| 429 | `rate-limited` | Slow down; wait for `Retry-After`. |

## Try it

`sdk/ts/examples/embed` in the Argus repository is a host page and the small backend that mints the token. `bun run demo:embed` in `sdk/ts` starts a local stack with the page and the API on different origins, as in production. The [security overview](/docs/security.md) says what a token in the browser can and cannot do.

Not built yet: serving client-side tools from the component (the SDK's `useArgusSession` still does). Planned: the SDK package is not publicly available yet (see [Command line and SDK](/docs/command-line-and-sdk.md)), and embedding itself is not enabled for customer projects yet.

Session creation and detail responses to client tokens omit host `metadata`. The backend can still read it with its project credential; it is not removed from storage.
