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

# JavaScript API

> Configure the embed widget programmatically with EkaMedAssist.init()

Once the loader script has run, it exposes a global `window.EkaMedAssist` object. Use it to set or override configuration before the user opens the widget — handy when your values are dynamic (a logged-in user's auth token, runtime context, etc.).

## EkaMedAssist.init()

Call `init()` with a config object. Values passed here take precedence over both the agent config and any HTML attributes.

```html theme={null}
<eka-medassist-widget agent-id="YOUR_AGENT_ID"></eka-medassist-widget>
<script
  src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget-embed@latest/dist/index.js"
  async
></script>

<script>
  window.EkaMedAssist.init({
    agentId: "YOUR_AGENT_ID",
    authToken: "USER_AUTH_TOKEN",
    title: "MedAssist",
    context: { intent: "book_appointment", userId: "123" },
    theme: {
      primary: "#09FBD3",
      mode: "dark",
      textColor: "white",
    },
  });
</script>
```

### Config options

These are the camelCase equivalents of the [HTML attributes](https://developer.eka.care/docs/agents/medassist/synapse/embed/customization.md#html-attributes), plus a couple of init-only fields.

**agentId** `string`

Your MedAssist agent identifier.

**authToken** `string`

Authentication token sent with the session.

**auth** `string`

Alternative auth header / bearer token.

**title** `string`

Widget header title.

**iconUrl** `string`

Launcher button icon URL.

**baseUrl** `string`

Base URL for the agent-config and nudge endpoints.

**displayMode** `"full" | "widget"`

Fullscreen overlay or floating launcher.

**context** `Record\<string, unknown\>`

Context object merged into the session. **Merged** with any `context` set via the HTML attribute, not replaced.

**customLauncherStyles** `string`

CSS injected into the launcher Shadow DOM. See [Custom launcher styling](https://developer.eka.care/docs/agents/medassist/synapse/embed/customization.md#custom-launcher-styling).

**redirectUrl** `string`

URL to redirect to when the widget closes.

**resize** `boolean`

Allow the widget to be resized when open.

**showCloseButton** `boolean` (default: false)

Force-show the close button. (Automatically shown when `redirectUrl` is set.)

**theme** `object`

Theme overrides — `backgroundImage`, `primary`, `textColor`, `mode`, `headerTinted`, `titleImg`, `tagline`. See [Theme object](https://developer.eka.care/docs/agents/medassist/synapse/embed/customization.md#theme-object).

## onClose callback

Run code when the user closes the widget — for analytics, cleanup, or your own navigation:

```js theme={null}
window.EkaMedAssist.onClose = function () {
  console.log("MedAssist widget closed");
};
```

## Self-hosting widget assets

By default, the loader fetches the widget's JS and CSS from the CDN on first open. To serve your own build, point the loader at your asset directory with the `data-widget-assets` attribute on the script tag:

```html theme={null}
<script
  src="/path/to/widget-embed/index.js"
  data-widget-assets="/path/to/widget-assets/"
  async
></script>
```

Ensure `medassist-widget.js` and `medassist-widget.css` are served at that path.

> [!TIP]
>
> If you're building a fully custom interface rather than configuring the prebuilt widget, drop down to the [Core SDK](https://developer.eka.care/docs/agents/medassist/synapse/core/quickstart.md).


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