Adding a Reactive Rive Avatar to Vapi and Deepgram Voice Agent UIs
By the Charmotion team · Updated · How we write guides

Map the voice agent's events to a mood number in a Rive file to animate the avatar live. Vapi and Deepgram both report call and agent activity your code can map to listening, thinking and talking states. The events covered here do not document mouth-shape data, so mouth motion follows the state, not the words.
Key takeaways
- Vapi's Web SDK and Deepgram's Voice Agent API both report call and agent activity that you can map to Rive moods.
- Use one mood table for every event: listening is 6, thinking is 3, loading is 5, talking is 7 and idle is 0.
- Neither event set documented here includes mouth-shape data, so mouth motion should follow the mood rather than the words.
- Keep API keys on your server and give the browser only a short-lived token.
- Test with a real call and a forced error before release.
Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.
What does a reactive avatar need from a voice agent?
This guide covers how to add a reactive Rive avatar to a Vapi or Deepgram voice agent UI, from the events you map to the file that plays on screen. A reactive avatar needs three parts: a voice agent that reports what it is doing, a Rive file with a state your code can set, and a small mapping layer between the two.
Vapi is a developer platform for building voice AI agents that can make and receive phone calls and run in web apps. Its Web SDK, installed from the npm package @vapi-ai/web, starts a voice call from the browser and emits events while the call runs.
Deepgram's Voice Agent API runs speech-to-text, LLM orchestration and text-to-speech over one real-time WebSocket connection. You can use a Deepgram-managed model, your own provider or a custom endpoint, and Deepgram bills by connection time.
The avatar side is a .riv file played by a Rive runtime. Rive's runtimes are open source and play any .riv file, so the browser code that plays the avatar carries no runtime fee. What the file needs is a mood value that code can change while the call runs. For a Next.js setup, see how to use Rive in React and Next.js.
Which events do Vapi and Deepgram send to the browser?
Both platforms report state, but not in the same shape. Vapi's Web SDK emits speech-start, speech-end, call-start, call-end, volume-level, audio, message and error events. Its message event carries the full assistant turn text, a turn number and a source value of model, force-say or custom-voice.
Deepgram sends typed JSON event messages and raw binary audio frames over the same connection. The event types named in its reference include Welcome, SettingsApplied, UserStartedSpeaking, AgentThinking, PromptUpdated and FunctionCallRequest.
| Signal | Vapi Web SDK | Deepgram Voice Agent |
|---|---|---|
| Call starts | call-start | Welcome |
| User starts speaking | speech-start or speech-end (confirm which speaker) | UserStartedSpeaking |
| Agent is working on a reply | No dedicated event in the documented list | AgentThinking |
| Agent audio plays | audio event, then getAudioPlayer() | Raw binary audio frames |
| Tool call runs | None in the documented list | FunctionCallRequest |
| Turn text | message (full assistant turn) | Conversation history messages for past turns |
| Call ends or fails | call-end and error | Socket close or error in your handler |
Neither event set documented here includes mouth-shape data. Vapi's docs do not confirm viseme or phoneme events, so drive the mouth through the talking state and do not expect word-level timing. For that trade-off, see lip-sync vs amplitude for a talking avatar.
How do you map agent events to Rive mood states?
Charmotion's Rive export is one example of a file you can drive this way. It has a CharacterViewModelMachine with a number property named mood, and a CharacterStateMachine with a number input named mood. The mood numbers are fixed: idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8 and attention 9. Moods blend into each other.
| Agent situation | Mood | Number |
|---|---|---|
| Call connecting or a tool is running | loading | 5 |
| User is speaking | listening | 6 |
| Agent is working out a reply | thinking | 3 |
| Assistant audio is playing | talking | 7 |
| Task succeeded | happy | 1 |
| Error from the agent or your backend | sad | 4 |
| Call ended | idle | 0 |
| Long silence after the user's turn | attention | 9 |
Characters have no one-shot triggers for success or error, so show a success with happy and an error with sad, as the table does. Some moods show small accents such as thinking dots or the exclamation mark for attention. The boolean accents hides them.
Keep the mapping in one place so the UI, the logs and any future mood changes read the same table:
const MOOD = {
idle: 0,
happy: 1,
thinking: 3,
sad: 4,
loading: 5,
listening: 6,
talking: 7,
sleeping: 8,
attention: 9
};
function setMood(name) {
const value = MOOD[name];
// write value to the mood property of the avatar (see the React section)
}Agent platforms differ in their callbacks, so the same idea applies beyond these two. For a comparable pattern with another provider, see ElevenLabs agent avatar with onModeChange.
How do you connect Vapi's Web SDK to the avatar?
Create the SDK with a public key or with a short-lived public JWT that your server signs. The JWT option keeps a long-lived key out of the browser. Vapi's quickstart documents both options.
Subscribe to the events before you start the call, so the first state change is not missed:
import Vapi from '@vapi-ai/web';
const vapi = new Vapi(publicToken);
vapi.on('call-start', function () { setMood('loading'); });
vapi.on('speech-start', function () { setMood('talking'); }); // confirm which speaker this describes
vapi.on('speech-end', function () { setMood('listening'); });
vapi.on('call-end', function () { setMood('idle'); });
vapi.on('error', function () { setMood('sad'); });
function startCall(assistantId) {
return vapi.start(assistantId);
}Two details need a live test. The payload fields of each event are not fully documented, so log one real call before you rely on them. Also confirm which speaker speech-start describes, since the mapping above assumes the assistant.
The audio event passes the player element once the assistant's audio is attached, and getAudioPlayer() returns that element, or null until the track arrives. Wait for the event before you read it. Use message events for captions or a log, not for timing, because each message carries the whole turn.
Budget Vapi as usage. As of December 2026, its pricing page lists a $0.05 per minute hosting fee on the pay-as-you-go option, with speech, model and voice costs passed through.
How do you connect Deepgram's Voice Agent to the avatar?
The Voice Agent API uses one WebSocket at wss://agent.deepgram.com/v1/agent/converse. The reference lists two ways to authenticate: an API key in the Authorization header, or a temporary JWT sent as a Bearer token.
Keep the API key on your server. A browser cannot set custom headers when it opens a WebSocket, so have your backend mint a temporary token and check the reference for how a browser client passes it. Never ship the long-lived key in front-end code.
Audio goes up and comes back on the same connection. Incoming messages fall into two groups: binary audio, and JSON event messages with a type field. Route them like this:
const socket = new WebSocket(agentUrl);
socket.binaryType = 'arraybuffer';
socket.onmessage = function (event) {
if (typeof event.data !== 'string') {
playAgentAudio(event.data);
setMood('talking');
return;
}
const msg = JSON.parse(event.data);
if (msg.type === 'UserStartedSpeaking') {
setMood('listening');
} else if (msg.type === 'AgentThinking') {
setMood('thinking');
} else if (msg.type === 'FunctionCallRequest') {
setMood('loading');
}
};Confirm the field name against the reference before you ship, since this sketch assumes type. When a function call arrives, your application runs the function and returns the result, and Deepgram produces the next reply. Keep loading on while that runs.
Binary frames keep arriving while the agent speaks. Set talking on the first frame, then return to listening or idle when your audio player reports that playback ended. Deepgram bills by WebSocket connection time. Third-party pricing articles list the Standard tier near $0.075 per connected minute on Pay As You Go, so check Deepgram's own pricing page before you budget, as of December 2026.
How do you render the Rive avatar in React and test it?
In React, the @rive-app/react-canvas package wraps Rive's Canvas2D web runtime. It exposes a useRive hook that returns a Rive instance and a component to render. Rive recommends this package for most apps unless you need a WebGL renderer.
import { useRive } from '@rive-app/react-canvas';
export function Avatar() {
const { RiveComponent } = useRive({
src: '/avatar.riv',
stateMachines: 'CharacterStateMachine',
autoplay: true
});
return <RiveComponent />;
}The useStateMachineInput hook in this package is marked deprecated in favor of newer data binding hooks. Write the mood through the data-bound view model instance rather than a legacy input. Rive's runtime documentation describes the view model API for each platform. For the broader data binding picture, see Rive data binding vs state machine inputs.
Test with a real call and a headset, not a typed prompt. Check four things: the avatar leaves idle when the call starts, listening appears when you speak, talking appears when audio plays, and the avatar returns to idle when the call ends. Then force an error and confirm that sad appears.
Charmotion can supply the .riv with the mood property already in place. Its exports include the CharacterViewModelMachine and CharacterStateMachine, along with web, React and SwiftUI code, so the setup above needs only a file path.
How to add a reactive Rive avatar to a Vapi or Deepgram voice agent UI
- Prepare the avatar file. Use a .riv file with a number property or input named mood, and note the state machine name shown in the Rive editor.
- Define one mood table. Create a MOOD map with the nine numbers and a single setMood function that every event handler calls.
- Connect the agent. For Vapi, create the Web SDK with a public key or a short-lived JWT and subscribe to call and speech events. For Deepgram, open the WebSocket with a temporary token and route binary audio and JSON events.
- Map events to moods. Set loading when a call connects or a tool runs, listening when the user speaks, thinking while the agent works, talking while audio plays, and idle when the call ends.
- Render in React. Mount the file with useRive from @rive-app/react-canvas and write the mood through the data-bound view model instance.
- Test with a live call. Confirm idle, listening, talking and idle at call end on a real call, then force an error and check that sad appears.
Frequently asked questions
Can the avatar lip-sync to the agent's exact words?
Not from the events covered here. Vapi's docs do not confirm viseme or phoneme data, and the Deepgram messages in this guide carry audio and typed state, not mouth shapes. Drive the talking mood while audio plays and keep any mouth animation inside the Rive file. The lip-sync guide on this site compares the approaches in more detail.
Do I need a Rive license to ship this?
The Rive runtimes are open source, so the browser code that plays a .riv file has no runtime fee. Editor plans affect what you can export. On Rive's free plan, exported files play a Rive splash screen, while paid plans export without it. Check Rive's pricing page for current plan details, as of December 2026.
Can one avatar serve both Vapi and Deepgram?
Yes, if both event paths call the same setMood function and the same mood table. Only the event listeners differ, so the .riv file and its mood numbers stay the same when you switch providers or run both during a migration. Keep provider-specific code in one module so the UI never needs to know which agent is speaking.
Why does the avatar stay in talking after the agent stops?
The events covered here do not include a playback-end signal for agent audio, so the avatar keeps talking until your code changes it. Listen to your audio player's ended event, then set listening or idle. Also set idle on call-end or socket close, so a dropped connection never leaves the avatar speaking.
Sources
- Vapi Web quickstart, Vapi
- Vapi client-sdk-web README, Vapi (GitHub)
- Vapi pricing, Vapi
- Deepgram Voice Agent, Deepgram
- Deepgram Voice Agent API reference, Deepgram
- Rive React runtime, Rive