Quickstart
Get a Convai character speaking in your app in under five minutes.
Prerequisites
Install
npm install @convai/web-sdkYour first conversation (React)
import { useConvaiClient } from '@convai/web-sdk';
export default function App() {
const client = useConvaiClient({
apiKey: 'YOUR_API_KEY',
characterId: 'YOUR_CHARACTER_ID',
// Recommended: a stable id per end user. It keys the character's
// long-term memory for that person across sessions.
endUserId: 'user-123',
});
const handleConnect = async () => {
try {
await client.connect();
} catch (err) {
// connect() rejects with a server reason — surface it, don't swallow it.
// e.g. "LTM speaker limit reached" means this API key hit its
// long-term-memory speaker cap for new endUserIds.
console.error('Connect failed:', err);
}
};
const handleSend = () => {
client.sendUserTextMessage('Hello! Who are you?');
};
return (
<div>
<p>Status: {client.activity}</p>
{!client.state.isConnected ? (
<button onClick={handleConnect}>Connect</button>
) : (
<button onClick={handleSend}>Say hello</button>
)}
<ul>
{client.chatMessages
.filter(m => m.type === 'bot-output' || m.type === 'user-llm-text')
.map(m => (
<li key={m.id}>
<strong>{m.type.startsWith('user') ? 'You' : 'Bot'}:</strong> {m.content}
</li>
))}
</ul>
</div>
);
}What this does
Drop-in widget
Add a talking 3D character
Troubleshooting first connects
Symptom
Cause / fix
Vanilla JavaScript
Next steps
Last updated
Was this helpful?