Open, close, inject prompts

Programmatic control

Go beyond the floating button. The useYak hook gives you full control to open the chat, inject context-aware prompts, and subscribe to tool events—build help buttons, onboarding flows, or error assistance.

Works withChat & voiceAll SDKsTool-event subscriptionsVanilla JS embed
useYak hook
// Control from anywhere
const { open, openWithPrompt } = useYak();
// Context-aware help
openWithPrompt("Help me with billing");
Full TypeScript support

What you get

  • open(), close(), and openWithPrompt() methods
  • Read widget state with isOpen, isReady, and chatLoading
  • Subscribe to tool-completion events for cache invalidation
  • Build context-sensitive help buttons
  • Create keyboard shortcuts and help menus

How it works

1

Wrap your app and grab the handle

Mount the Yak provider, then call useYak() (or your framework's equivalent composable or service) anywhere to get open(), close(), openWithPrompt(prompt), state flags, and subscribeToToolEvents().

2

Wire it to your own UI

Drive your own buttons, keyboard shortcuts, and error boundaries—openWithPrompt() opens the panel and sends a tailored prompt, queuing it automatically if the iframe isn't ready yet.

3

React to what the assistant does

Subscribe to tool-call completion events (name, args, ok, result or error) to invalidate caches or refresh the page after the assistant modifies data on the user's behalf.

Frequently asked questions

Related features

Ship programmatic control with yak

Add an AI assistant that matches your product—then turn on the features your users need.