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

# Quickstart

> Add AI chat to your JavaScript app in under 5 minutes using the @humain/kiosk-js SDK.

The `@humain/kiosk-js` SDK wraps the Humain Device API so you can open sessions, send messages, and
stream responses with one import and a handful of method calls — no raw HTTP required.

> [!TIP]
>
> During development, issue an **`hk_test_`** credential from the admin panel instead of a live
> `hk_live_` one. Sandbox is a property of the credential, not a different base URL — you call
> the same `https://api.humain.ai` host either way. Sandbox sessions don't consume production
> LLM credits and aren't billed. See [Sandbox mode](https://humain.mintlify.site/concepts/sandbox-mode.md).

**1. Install the package**

```bash npm theme={null}
npm install @humain/kiosk-js
```

```bash yarn theme={null}
yarn add @humain/kiosk-js
```

```bash pnpm theme={null}
pnpm add @humain/kiosk-js
```

**2. Open a session and send a message**

```typescript TypeScript theme={null}
import { HumainKioskClient } from "@humain/kiosk-js"

const kiosk = new HumainKioskClient({
  credential: "hk_test_your_credential_here", // hk_test_ = sandbox, hk_live_ = production
})

const session = await kiosk.openSession()
const { response } = await session.sendMessage("Hello, how can I help you today?")
console.log(response)
await session.close()
```

```javascript JavaScript theme={null}
import { HumainKioskClient } from "@humain/kiosk-js"

const kiosk = new HumainKioskClient({
  credential: "hk_test_your_credential_here", // hk_test_ = sandbox, hk_live_ = production
})

const session = await kiosk.openSession()
const { response } = await session.sendMessage("Hello, how can I help you today?")
console.log(response)
await session.close()
```

There is no separate sandbox URL or client mode — sandbox behavior comes entirely from
using an `hk_test_` credential. See [Sandbox mode](https://humain.mintlify.site/concepts/sandbox-mode.md).

**3. Add streaming**

Replace `sendMessage` with `session.stream()` to receive tokens as they are generated.
This uses an async iterator — `for await` works in any modern JavaScript runtime.

```typescript theme={null}
const session = await kiosk.openSession()

process.stdout.write("Assistant: ")
for await (const event of session.stream("What services do you offer?")) {
  if (event.type === "chunk") {
    process.stdout.write(event.content)
  }
}
console.log() // newline after stream completes

await session.close()
```

The iterator yields objects of these types:

| `type` | Extra fields | Description |
| - | - | - |
| `turn_start` | — | The AI has started generating |
| `chunk` | `content: string` | A token fragment — append to your UI |
| `tool_call` | `name`, `callId` | An action endpoint was invoked |
| `tool_result` | `callId`, `status` | Action endpoint returned |
| `turn_end` | `messageCount: number` | Generation complete |

> [!NOTE]
>
> The underlying WebSocket delivers one complete response per turn — see
> [WebSocket streaming](https://humain.mintlify.site/connections/websocket-streaming.md) for the wire protocol. `chunk`,
> `tool_call`, and `tool_result` events are a client-side reveal built by the SDK on top of
> that single response, not genuine incremental delivery from the network.

**4. Handle errors**

The client throws typed `KioskError` instances you can inspect:

```typescript theme={null}
import { HumainKioskClient, KioskError } from "@humain/kiosk-js"

try {
  const { response } = await session.sendMessage(userInput)
} catch (err) {
  if (err instanceof KioskError) {
    switch (err.code) {
      case "RATE_LIMITED":
        await sleep(err.retryAfterSeconds * 1000)
        break
      case "INPUT_REJECTED":
        showUserMessage("I can't help with that.")
        break
      default:
        console.error(err.code, err.message)
    }
  }
}
```

> [!WARNING]
>
> **Never expose live credentials in client-side code.** Your `hk_live_…` token is a long-lived
> secret. In browser environments, either proxy API calls through your own server or issue an
> `hk_test_…` (sandbox) credential instead for public-facing demos. Treat it like a password.

## What's next?

> [card] [Drop-in widget](https://humain.mintlify.site/web/drop-in-widget.md)
>
> Add a floating chat button to any webpage with a single `<script>` tag — no build step.

> [card] [React components](https://humain.mintlify.site/web/react.md)
>
> `<KioskChat>` and `useKioskSession` for React and Next.js applications.

> [card] [Streaming UI patterns](https://humain.mintlify.site/web/streaming-ui.md)
>
> Cursor animation, layout shift prevention, and abort/retry patterns.


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