Skip to content
Limited timeStarter is now $9 a month instead of $20.See plans
charmotion

Binding Vercel AI SDK useChat Status to a Reactive Rive Mascot

By the Charmotion team · Updated · How we write guides

Cover illustration for the guide: Binding Vercel AI SDK useChat Status to a Reactive Rive Mascot, with Charmotion demo characters

Read the status value from useChat in React, then set one number input on the Rive state machine to a matching mood: submitted to thinking, streaming to talking, ready to idle and error to sad. The mascot never calls the API. It only receives a mood number that changes with the chat.

Key takeaways

  • Map the four useChat status values (submitted, streaming, ready, error) to one number mood input.
  • Use a number input for the current state and keep triggers for true one-off events.
  • Find the input by name with stateMachineInputs, then set its value from a React effect.
  • stop() returns status to ready, so a stopped reply shows idle rather than an error.
  • The mood numbers here match Charmotion's generated characters; other rigs need their own state numbers.

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 do the useChat status values mean?

This guide shows how to bind Vercel AI SDK useChat status to a Rive mascot state machine, so the character reacts to each stage of a reply. The mapping starts with the four values the hook reports.

The chatbot docs describe submitted as the period after a message is sent and before the response stream begins. streaming applies while the response is actively receiving data chunks. ready means the full response has been processed and a new message can be sent. error means an error interrupted the API request before it could complete.

useChat statusWhat it meansMood to set
submittedMessage sent, stream not started3 (thinking)
streamingChunks arriving7 (talking)
readyReply complete, input open0 (idle)
errorRequest interrupted4 (sad)

These mood numbers match the map used by Charmotion's generated characters. If your rig uses other state numbers, keep the same logic and change only the numbers.

Should the mascot use a number, boolean or trigger input?

Rive state machine inputs come in three types: number (a decimal value), boolean (true or false) and trigger (a one-shot signal). Booleans suit two-state flags such as isActive. Triggers suit single events such as a tap.

A chat status is a value that stays in place until it changes. That makes a number input the better fit: the mascot holds its mood for as long as the status lasts. The state machine then handles the blend between moods, so a change from streaming to ready eases rather than cutting.

Reserve triggers for moments that have no lasting state. Avoid firing a trigger every time a chunk arrives, because each chunk would restart the same animation. For the underlying concepts, read Rive state machine inputs, triggers and moods, and compare the design choice in Lottie vs Rive state machines and data binding.

How do you read and set a state machine input from React?

Load the file with Rive's React runtime, ask the Rive instance for the state machine's inputs, and find yours by name. Rive's React runtime provides useRive, which returns a Rive instance and a component to render.

The web runtime lists a state machine's inputs with stateMachineInputs and the state machine name. Number and boolean inputs expose a value property you can read and set directly. Trigger inputs are fired by calling a method on them.

const mood = rive
  .stateMachineInputs('CharacterStateMachine')
  ?.find((input) => input.name === 'mood');
if (mood) mood.value = 3; // thinking

The React runtime page marks the older useStateMachineInput hook as deprecated in favor of data binding hooks (as of December 2026). The lookup above uses the instance API, which avoids that hook. Check the React runtime page for the current option list before you copy code.

How do you connect useChat status to the mascot?

Put the status-to-mood map in one object, so product changes stay in one place. The effect runs whenever the status changes. It also waits for the Rive instance, because the instance is empty until the file has loaded, and it runs again once the file is ready.

'use client';
import { useEffect } from 'react';
import { useChat } from '@ai-sdk/react';
import { useRive } from '@rive-app/react-canvas';

const MOOD_FOR_STATUS = { submitted: 3, streaming: 7, ready: 0, error: 4 };

export function ChatMascot() {
  const { status } = useChat();
  const { rive, RiveComponent } = useRive({
    src: '/mascot.riv',
    stateMachines: 'CharacterStateMachine',
    autoplay: true,
  });

  useEffect(() => {
    if (!rive) return;
    const mood = rive
      .stateMachineInputs('CharacterStateMachine')
      ?.find((input) => input.name === 'mood');
    if (mood) mood.value = MOOD_FOR_STATUS[status] ?? 0;
  }, [rive, status]);

  return <RiveComponent />;
}

Render your message list and input next to the mascot. The messages and sendMessage function come from the same useChat call. Size the canvas wrapper in your own stylesheet. Keep the status map as the only place where API states become moods, so a designer can change a mood without touching chat logic.

Once the file is wired, a character with a sad state shows a failed request, and a character with a thinking state shows the gap before the first token. For a full chat layout, see animating a chat avatar from streaming events.

What happens when a user stops a reply or the request fails?

The docs say that calling stop() aborts the browser fetch, keeps the text already received and returns the status to ready. The mascot therefore moves from talking to idle while the partial reply stays on screen. The map above handles this without extra code, because ready maps to idle.

An error status means the request was interrupted before it could finish. Setting mood 4 shows a sad character. Keep the error text in your interface, because the mascot only signals the state and does not explain it.

Vercel does not document AI SDK or AI Gateway pricing on the pages cited here (as of December 2026), and the same is true of rate limits, token limits and size limits. Check Vercel's own pricing and limits pages before you estimate cost or set quotas for a public chat.

Does the same mapping work outside React?

The logic is the same in other runtimes: read the status, find the mood input, and set its value. The names change, not the steps.

In Flutter, a state machine controller is created from an artboard and a state machine name, and the inputs are read from controller.stateMachine.inputs, according to a Very Good Ventures walkthrough of Rive in Flutter. Rive's Android runtime lists a separate method for each input type, called through the view. For Swift, check the current Apple runtime documentation before writing code.

If your app is built with a no-code or AI builder, the wiring is still the same idea. See adding a Rive mascot to a Lovable app or adding a Rive mascot in Bolt.new, v0 and Replit for the setup steps in those tools.

Where does a generated character fit in this setup?

If you do not have a Rive file yet, Charmotion can produce one from a single front-facing character image. The output is one .riv file with CharacterViewModelMachine (a number property named mood), CharacterStateMachine (a number input named mood) and, when launch is picked, LaunchStateMachine. The package also includes paste-ready web, React and SwiftUI code, a README and an AI_README for coding assistants. Pick the states you need, such as thinking, talking and sad, and keep the mood numbers from the table above. You can see the states in a chat UI on the AI chatbot avatar animation page, and the MCP server lets assistants such as Claude or Cursor create the character from a prompt.

How to bind Vercel AI SDK useChat status to a Rive mascot state machine

  1. Map the status values. List the four useChat statuses (submitted, streaming, ready, error) and choose one mood number for each, such as 3, 7, 0 and 4.
  2. Create or pick a number input. Use a number input named mood on the state machine, and keep triggers for one-off events only.
  3. Load the Rive file in React. Call useRive with the file path and the state machine name, then keep the returned Rive instance and component.
  4. Find the input by name. Call stateMachineInputs with the state machine name and select the input whose name is mood.
  5. Set the mood from status. In a useEffect that depends on rive and status, set mood.value from the map, with a fallback to idle.
  6. Test each status. Send a message, watch the mascot move through thinking and talking, press stop to confirm it returns to idle, and force an error to confirm sad.

Frequently asked questions

Can I use a trigger input instead of a number input?

You can, if the state machine has a trigger for the event. For a chat status, a number input is usually better because the mood should stay in place until the status changes. A trigger fires once and then the animation moves on, so a long stream would need repeated triggers. Triggers still suit one-off moments, such as a single celebration after a successful reply.

Does this work in SwiftUI or Flutter instead of React?

The steps are the same: read the status, find the mood input and set its value. Flutter creates a state machine controller from an artboard and a state machine name, then reads its inputs. For SwiftUI, the Rive Apple runtime is the place to check the current API, since the names differ from the web runtime.

What should the mascot show when a user presses stop?

Map ready to idle, as this guide does. Calling stop() keeps the partial reply and returns the status to ready, so the mascot settles into idle without showing an error. If you want a short acknowledgement, set mood 1 for a moment and then return to idle with a timer.

Sources

Related guides