Skip to Content
Nuance LabsDocs

How a conversation works

Your server, your page and Nuance, and what happens between them from the first API key to the end of a conversation.

Three places take part in every conversation:

  • Your page is what your user has open: a page in their browser, or your app on their phone.
  • Your server holds your secret API key and decides who may start a conversation.
  • Nuance runs the persona and the API that your server and your page call.

Setting up a conversation

Setup: your page asks your server for a session token, your server gets one from Nuance with its API key and passes it back, and your page creates the conversation with it.
  1. You create an API key on the platform and keep it on your server. It starts with nk_. Never send it to a browser or an app.
  2. Your user presses Start on your page. The page requests a session token from your server.
  3. Your server requests a session token from Nuance. It calls Nuance's POST /session-tokens with your API key and the conversation's settings (Configure the conversation): your prompt (Your own prompt), which character to use, and your tools (Tools). Nuance responds with a token that starts with st_. You don't build this route; it's Nuance's.
  4. Your server passes the token to the page. The token can start one conversation, with the settings your server chose. Anyone who has one can start a conversation on your account, so give tokens only to users you've signed in.
  5. Your page creates the conversation by calling Nuance's POST /conversation with the token. Nuance gets the persona ready, which can take up to about half a minute.

During the conversation

The call: audio, video and events go both ways between your page and Nuance. Your page calls your server when it needs it, and your server has no link to Nuance during the call.
  1. Your page joins the call. The user's microphone and camera go to Nuance, and the persona's video and voice come back.
  2. The conversation runs. The persona and your user speak with each other. Alongside the call, Nuance and your page exchange events, which are small JSON messages: Nuance tells the page what each side said, when a reply ends, and when the persona wants one of your tools run (Tools, Follow the conversation), and the page can tell the persona what is happening in your app, ask it to say something, or stop it (Direct the persona live). Your server never sees these events. If a tool needs your server, such as to look something up in your database, your page sends it a request and passes the result back. Treat that request like any other from your user: check who they are and what they're allowed to do.
  3. The conversation ends when the user hangs up, the persona ends it, or the time limit runs out (Limits, credits and capacity). Your server can end a conversation itself at any time, and fetch its transcript after it ends.

On a web page, the JavaScript SDK, @nuancelabs/js-sdk, does steps 5 to 7 for you. If you're building a native app, your app makes those calls itself (Native apps).

Terminology

  • Persona: the AI character your user has the conversation with. Its face and voice come from one of Nuance's characters, and who it is comes from your prompt.
  • Conversation: one call between your user and the persona, from Start to hang-up.
  • Event: a small JSON message between your page and the persona during a conversation. There are events your page sends and events it gets.
  • Tool: a function in your code that the persona can ask your page to run. See Tools.

On this page