Bring your own brain
With verbatim speech, you decide what the avatar says. Your code writes the line and the avatar speaks it, in its own voice and with lip-sync, without its 2wai brain. Everything upstream of the line is yours: understanding the user, choosing a reply, retrieval and tools. You can use any language model, or none.
How it works
Section titled “How it works”- Your server creates the session with
"verbatim": true. - The response carries
"verbatim": true, and itschatobject gainssay_topic(lk.say) andsay_status_topic(lk.say.status). - The client that joined the room sends each line as a text stream on
lk.say. One stream is one line, from 1 to 2,000 characters. - 2wai checks the line (see Moderation and retention), then the avatar speaks it on its audio and video tracks. The text is echoed on
lk.transcription, like any reply. - The agent answers the sender on the data topic
lk.say.status:accepted, orrefusedwith areason, thendonewhen the line has finished playing.
The line goes from the client to the avatar over the room; there is no REST call per line. A server-side POST /v1/sessions/{id}/speak is planned and still answers 409 not_available_on_livekit today. If your model runs on your server, send its text to your own client (over your existing socket, for example) and let the client put it on lk.say.
Create the session
Section titled “Create the session”curl -X POST https://api.2wai.ai/v1/sessions \ -H "Authorization: Bearer $TWAI_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{ "avatar_id": "gen-xxxxxxxxxxxxxxxxxxxxxxxxxx", "mode": "video", "verbatim": true }'{ "session_id": "ses_...", "transport": "livekit", "livekit_url": "wss://...", "room_name": "ppstg-...", "participant_token": "eyJ...", "agent_identity": "viewer-...", "verbatim": true, "chat": { "send_topic": "lk.chat", "format": "text", "reply_topic": "lk.transcription", "say_topic": "lk.say", "say_status_topic": "lk.say.status" }, "expires_at": null}Send a line (client)
Section titled “Send a line (client)”import { Room, RoomEvent } from 'livekit-client';
const room = new Room();await room.connect(session.livekit_url, session.participant_token);
// Status for each line you send: accepted, refused (with a reason), then done.room.on(RoomEvent.DataReceived, (payload, participant, kind, topic) => { if (topic !== session.chat.say_status_topic) return; const status = JSON.parse(new TextDecoder().decode(payload)); console.log(status.id, status.status, status.reason ?? '');});
async function say(line) { // One text stream per line. `info.id` matches `status.id` above. const info = await room.localParticipant.sendText(line, { topic: session.chat.say_topic, }); return info.id;}
await say('Hi! I can say exactly what you tell me to.');Wait for the agent to join the room (the first remote participant) before you send the first line.
The pattern with your own model
Section titled “The pattern with your own model”// On your server: decide what to say, with any model or none.const completion = await openai.chat.completions.create({ model: '<your-model>', messages: [{ role: 'user', content: userMessage }],});const text = completion.choices[0].message.content;// ...send `text` to your client, which calls say(text) on the room.Streaming for lower latency
Section titled “Streaming for lower latency”If your model streams tokens, don’t wait for the whole reply. Cut it at sentence boundaries and send each sentence as its own line, so the avatar starts talking while the rest is still being written. Lines are spoken in the order you sent them.
let buffer = '';for await (const chunk of stream) { buffer += chunk.choices[0]?.delta?.content ?? ''; const match = buffer.match(/^(.*?[.!?])\s+/); if (match) { buffer = buffer.slice(match[0].length); await say(match[1]); }}if (buffer.trim()) await say(buffer.trim());Limits
Section titled “Limits”| Limit | Value | When you pass it |
|---|---|---|
| Line length | 1 to 2,000 characters | refused, too_long or empty |
| Lines per minute, per session | 20 | refused, rate_limited |
| Lines waiting or playing at once | 3 | refused, queue_full. Wait for a done before you send more. |
| Lines being received at once | 8 | refused, busy |
A verbatim line counts as activity, so a session in use is not reaped as idle.
Status messages
Section titled “Status messages”Each message on lk.say.status is JSON with a v (version, 1), the stream id, and a status:
status | Meaning |
|---|---|
accepted | The line passed its checks and is queued to speak. |
done | The line finished playing. interrupted is true if it was cut off. |
refused | The line will not be spoken. reason says why. |
reason | Meaning |
|---|---|
moderation | The moderation check flagged the line. |
moderation_unavailable | The moderation check could not run. The line is refused rather than spoken unchecked. Retry. |
not_enabled | Verbatim speech was turned off for this avatar during the session. |
too_long, empty | The line is over 2,000 characters, or blank. |
rate_limited, queue_full, busy | See Limits. |
read_timeout, read_error | The text stream did not arrive whole within 10 seconds. |
audit_unavailable, speak_failed | Something went wrong on our side. Retry. |
What “exact” means
Section titled “What “exact” means”No model rewrites your words. Two things still apply, as they do to every reply: Markdown and emoji are not read aloud, and the avatar’s pronunciation fixes, if it has any, are applied.
Mixing with the avatar’s own brain
Section titled “Mixing with the avatar’s own brain”lk.chat still works in a verbatim session: a user turn sent there gets a reply from the avatar’s own 2wai brain. That brain never sees your lk.say lines, so it will not remember them. A turn on lk.chat also interrupts the avatar, including a verbatim line it is speaking. There is no separate interrupt for verbatim lines yet.
Moderation and retention
Section titled “Moderation and retention”- Every line is checked before it is spoken, by an automated moderation service (OpenAI’s moderation API). A flagged line is refused, and so is a line the check could not run on.
- 2wai keeps the text of every checked line for at least 30 days, whether it was spoken or refused, for abuse review, and deletes it within about a day after that. Your avatar’s brain never sees it.
- On its way to the avatar, each line also passes through our service providers for that step: OpenAI (the moderation check), Soniox (speech synthesis) and LiveKit (the room).
- You remain responsible for what you make the avatar say, under the developer terms.
Errors
Section titled “Errors”| HTTP | error.code | Meaning |
|---|---|---|
| 403 | verbatim_not_enabled | This avatar is not enabled for verbatim speech for your account. |
| 422 | invalid_verbatim | verbatim is not true or false, or the transport is not LiveKit. |
| 503 | verbatim_unavailable | The session service could not grant verbatim speech right now. Retry, or create the session without it. |
- Sessions for the rest of the session lifecycle.
- Streaming into your app for joining the room and rendering the avatar.
- Latency for tuning time to first word.