Skip to main content

Install

Or load directly in a browser with an import map or CDN:
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.

Streaming chat — complete example

This is a self-contained example that runs in a browser’s <script type="module"> block. No build tools needed.

Key patterns

Streaming tokens into the DOM

The critical loop: create a DOM node before the stream starts, then mutate it in place as chunks arrive. This avoids layout shift from re-rendering.

Handling rate limits

Cleaning up sessions

Always close the session when the user leaves:
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.