> ## 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.

# loadConcatflow()

> Load widget.js once and get a typed Concatflow object.

```ts theme={"system"}
import { loadConcatflow } from "@concatflow/embed";

const Concatflow = await loadConcatflow();
const assistant = Concatflow.init({ siteToken: "st_YOUR_SITE_TOKEN", launcher: "bar", target: "#search" });
```

```ts Signature theme={"system"}
function loadConcatflow(options?: { base?: string }): Promise<ConcatflowGlobal>;

interface ConcatflowGlobal {
  init(options: ConcatflowOptions): ConcatflowInstance;
}
```

## Parameters

**base** `string` (default: [https://app.concatflow.com](https://app.concatflow.com))

The Concatflow origin to load `widget.js` from. A trailing `/` is removed. `init` uses the same origin unless you pass `base` to it too.

## Returns

A promise of `ConcatflowGlobal`. Its [`init`](https://docs.concatflow.com/reference/embed/init) validates options before handing them to the hosted script.

## Behaviour

* **Once.** The first call injects `<script src="…/widget.js" async>` in `<head>`. Every later call returns the same promise.
* **Reuses your tag.** If the page already has a `<script>` with the same `src`, it waits for that one instead of adding another.
* **Retryable.** If loading fails (offline, blocked), the promise rejects and the next call tries again.
* **Browser only.** On the server, it rejects. Import the package anywhere, call this function in the browser.

## Errors

| Message | Cause |
| - | - |
| `Concatflow: failed to load https://…/widget.js.` | Network error, CSP or blocker. |
| `Concatflow: https://…/widget.js loaded but did not define window.Concatflow.` | The URL served something else. Check `base`. |
| `Concatflow: widget.js is already loaded from https://….` | A second call asked for a different `base`. |
| `Concatflow: loadConcatflow() must run in the browser.` | Called during server-side rendering. |

## Constants

```ts theme={"system"}
import { DEFAULT_BASE, PROTOCOL_VERSION } from "@concatflow/embed";

DEFAULT_BASE; // "https://app.concatflow.com"
PROTOCOL_VERSION; // 1
```

**DEFAULT\_BASE** `string`

The default Concatflow origin.

**PROTOCOL\_VERSION** `number`

The version of the options contract this package speaks. Sent as `v` with every `init`. See [Versioning](https://docs.concatflow.com/guides/versioning.md).


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