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

# Concatflow.init()

> Create an assistant on the page. Pass exactly one of session or siteToken.

```ts Per-user door theme={"system"}
const assistant = Concatflow.init({
  session: tokenFromYourServer,
  launcher: "bar",
  target: "#assistant",
  theme: "auto",
  accent: "#0E7C66",
  placeholder: "Ask about your accounts…",
  onSessionExpired: renewToken,
});
```

```ts Public door theme={"system"}
const assistant = Concatflow.init({
  siteToken: "st_YOUR_SITE_TOKEN",
  launcher: "bubble",
});
```

`Concatflow` is the object returned by [`loadConcatflow()`](https://docs.concatflow.com/reference/embed/load-concatflow), or `window.Concatflow` once `widget.js` has loaded.

## Door

Pass **exactly one** of these two.

**session** `string`

A session token opened by your server with [`sessions.create`](https://docs.concatflow.com/reference/node/sessions-create). Opens the per-user door.

**siteToken** `string`

The assistant's public site token, `st_…`. Opens the public door. See [Where to find your identifiers](https://docs.concatflow.com/identifiers.md).

## Options

**launcher** `"bubble" | "bar"` (default: bubble)

`"bubble"` floats in the bottom-right corner. `"bar"` is a search bar: inline with `target`, a ⌘K overlay without. See [Bar or bubble](https://docs.concatflow.com/guides/bar-or-bubble.md).

**target** `HTMLElement | string`

Where to render the bar: an element or a CSS selector. Only used with `launcher: "bar"`. Without it, the bar opens as a ⌘K overlay.

**theme** `"auto" | "light" | "dark"` (default: auto)

`"auto"` uses the dashboard's theme, then the visitor's system setting. See [Appearance](https://docs.concatflow.com/guides/appearance.md).

**accent** `string`

A CSS colour for the bar's magnifier and focus ring, such as `"#0E7C66"`.

**placeholder** `string` (default: Posez une question…)

The bar's placeholder text.

**onSessionExpired** `() =\> Promise\<string\>`

Per-user door only. Called when the token stops working. Resolve with a new token from your server. See [Session renewal](https://docs.concatflow.com/guides/session-renewal.md).

**base** `string`

The Concatflow origin of the iframe. With `@concatflow/embed`, defaults to the origin `loadConcatflow()` loaded from, and a trailing `/` is removed. With the script tag, defaults to `https://app.concatflow.com`.

## Returns

A [`ConcatflowInstance`](https://docs.concatflow.com/reference/embed/instance): `open()`, `close()`, `setSession()`, `destroy()`.

## Validation

With `@concatflow/embed`, `init` checks its options and throws a `TypeError` on the first problem, before anything renders:

| Message | Cause |
| - | - |
| ``Concatflow: pass exactly one of `session` or `siteToken`.`` | Both, or neither. |
| ``Concatflow: `session` must be a non-empty string.`` | Empty or not a string. Same for `siteToken`. |
| ``Concatflow: `launcher` must be one of bubble, bar.`` | Unknown launcher. |
| ``Concatflow: `theme` must be one of auto, light, dark.`` | Unknown theme. |
| ``Concatflow: `accent` must be a string.`` | Same for `placeholder`. |
| ``Concatflow: `onSessionExpired` only applies to `session`.`` | Passed with `siteToken`. |
| ``Concatflow: `onSessionExpired` must be a function returning Promise<string>.`` | Not a function. |
| ``Concatflow: `target` must be an HTMLElement or a CSS selector.`` | Wrong type. |

A `target` selector that matches nothing throws an `Error` from the hosted script.

## Types

```ts theme={"system"}
import type {
  ConcatflowOptions, // SessionOptions | SiteTokenOptions
  SessionOptions,
  SiteTokenOptions,
  Launcher, // "bubble" | "bar"
  Theme, // "auto" | "light" | "dark"
  ConcatflowInstance,
  ConcatflowGlobal,
} from "@concatflow/embed";
```

The two option types exclude each other: TypeScript rejects `session` and `siteToken` together, and `onSessionExpired` with `siteToken`.


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