Socket
Book a DemoInstallSign in
Socket

@vapi-ai/client-sdk-react

Package Overview
Dependencies
Maintainers
10
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vapi-ai/client-sdk-react

Vapi Client React SDK

0.0.12
latest
Source
npmnpm
Version published
Maintainers
10
Created
Source

VAPI React Client SDK

⚠️ Beta Version: This library is currently in beta. APIs may change and some features might be unstable. Use with caution in production environments.

A modern React component library with embeddable voice and chat widgets built with Vite, TypeScript, and Tailwind CSS. Featuring seamless VAPI AI integration for voice conversations.

Features

  • 🎙️ Voice Conversations: Real-time voice calls with VAPI AI assistants
  • 💬 Chat Interface: Text-based conversations with markdown support
  • 🔀 Hybrid Mode: Seamlessly switch between voice and chat
  • 🎨 Highly Customizable: Themes, colors, sizes, and positions
  • 🔒 Consent Management: Built-in consent form for compliance
  • Easy Integration: Use as React component or embed in any HTML page
  • 📘 TypeScript: Full type safety and IntelliSense support

Installation

npm install @vapi-ai/client-sdk-react @vapi-ai/web

Note: @vapi-ai/web is a peer dependency that must be installed separately to avoid WebRTC connection conflicts.

Quick Start

The simplest way to add the widget to your website:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/@vapi-ai/client-sdk-react/dist/embed/widget.umd.js"></script>
  </head>
  <body>
    <vapi-widget
      public-key="your-vapi-public-key"
      assistant-id="your-assistant-id"
      mode="chat"
      theme="light"
      size="full"
      color-accent="#3B82F6"
      cta-button-color="#1F2937"
      cta-button-text-color="#FFFFFF"
      title="AI Assistant"
      cta-title="Chat with us"
      cta-subtitle="24/7 Support"
      chat-placeholder="How can I help you today?"
    ></vapi-widget>
  </body>
</html>

VapiWidget Props

Required Props

PropTypeDescription
publicKeystringYour VAPI public API key

VAPI Configuration Props

PropTypeDescription
assistantIdstringVAPI assistant ID (supported by both voice and chat)
assistantobjectFull assistant configuration object (voice only)
assistantOverridesobjectAssistant overrides (supported by both voice and chat)

Note: You must provide at least one of assistantId, assistant, or both assistantId and assistantOverrides.

Optional Props

PropTypeDefaultDescription
mode'voice' | 'chat' | 'hybrid''chat'Widget interaction mode
theme'light' | 'dark''light'Color theme
position'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'bottom-center''bottom-right'Screen position
size'tiny' | 'compact' | 'full''full'Widget size
borderRadius'none' | 'small' | 'medium' | 'large''medium'Corner radius style
apiUrlstring-Custom API endpoint for chat mode
Colors
baseBgColorstring-Main background color
accentColorstring'#14B8A6'Primary accent color
ctaButtonColorstring'#000000'CTA button background color
ctaButtonTextColorstring'#FFFFFF'CTA button text/icon color
Text Labels
titlestring'Talk with AI'Main widget title
startButtonTextstring'Start'Voice call start button text
endButtonTextstring'End Call'Voice call end button text
ctaTitlestring(uses title)Floating button main text
ctaSubtitlestring-Floating button subtitle text
Empty States
voiceEmptyMessagestring-Message when voice mode is empty
voiceActiveEmptyMessagestring-Message during active voice call
chatEmptyMessagestring-Message when chat is empty
hybridEmptyMessagestring-Message for hybrid mode
Chat Configuration
chatFirstMessagestring-Initial assistant message in chat
chatPlaceholderstring'Type your message...'Chat input placeholder text
Voice Configuration
voiceShowTranscriptbooleanfalseShow/hide voice transcript
Consent Configuration
consentRequiredbooleanfalseShow consent form before first use
consentTitlestring"Terms and conditions"Consent form title
consentContentstring(default message)Terms & conditions content
consentStorageKeystring"vapi_widget_consent"Key for storing consent

Event Callbacks

PropTypeDescription
onVoiceStart() => voidTriggered when voice call starts
onVoiceEnd() => voidTriggered when voice call ends
onMessage(message: any) => voidTriggered for all messages
onError(error: Error) => voidTriggered on errors

React Component Usage

If you're using React, you can import and use the widget as a component:

import { VapiWidget } from '@vapi-ai/client-sdk-react';

function App() {
  return (
    <VapiWidget
      publicKey="your-vapi-public-key"
      assistantId="your-assistant-id"
      mode="hybrid"
      position="bottom-right"
      theme="light"
      accentColor="#3B82F6"
      title="AI Assistant"
      chatPlaceholder="Ask me anything..."
      voiceShowTranscript={true}
    />
  );
}

Embedding Methods

Use the widget as a custom HTML element with kebab-case attributes - the cleanest and most modern approach:

<vapi-widget
  public-key="pk_123"
  assistant-id="asst_456"
  mode="chat"
  theme="dark"
  accent-color="#8B5CF6"
  consent-required="true"
  chat-first-message="Welcome! How can I assist you?"
  chat-placeholder="Type your question here..."
></vapi-widget>

2. Data Attributes

Use this approach if your environment doesn't support custom elements or for better compatibility with older systems:

<div
  data-client-widget="VapiWidget"
  data-public-key="pk_123"
  data-assistant-id="asst_456"
  data-mode="voice"
  data-theme="dark"
  data-size="compact"
></div>

Usage Examples

Voice-Only Mode

<VapiWidget
  publicKey="pk_123"
  assistantId="asst_456"
  mode="voice"
  size="tiny"
  voiceShowTranscript={false}
  startButtonText="Call"
  endButtonText="Hang Up"
/>

Chat-Only Mode

<VapiWidget
  publicKey="pk_123"
  assistantId="asst_456"
  mode="chat"
  theme="dark"
  accentColor="#8B5CF6"
  chatFirstMessage="Hello! How can I help you today?"
  chatPlaceholder="Type your message here..."
/>

Hybrid Mode with Assistant Overrides

<VapiWidget
  publicKey="pk_123"
  assistantId="asst_456"
  assistantOverrides={{
    variableValues: { name: 'John' },
  }}
  mode="hybrid"
  consentRequired={true}
  consentTitle="Privacy Agreement"
  consentContent="By using this service, you agree to our terms..."
  title="Support Assistant"
  hybridEmptyMessage="Start a conversation with voice or text"
  onMessage={(msg) => console.log('Message:', msg)}
/>

Voice-Only with Full Assistant Object

<VapiWidget
  publicKey="pk_123"
  assistant={{
    model: {
      provider: 'openai',
      model: 'gpt-4o-mini',
      messages: [{ role: 'system', content: 'You are a helpful assistant.' }],
    },
    voice: {
      provider: '11labs',
      voiceId: 'burt',
    },
  }}
  mode="voice"
  size="full"
/>

Custom Styling

<VapiWidget
  publicKey="pk_123"
  assistantId="asst_456"
  baseBgColor="#1a1a1a"
  accentColor="#ff6b6b"
  ctaButtonColor="#2a2a2a"
  ctaButtonTextColor="#ffffff"
  borderRadius="large"
  size="full"
  title="Premium Support"
/>

Floating Button with Custom CTA

<VapiWidget
  publicKey="pk_123"
  assistantId="asst_456"
  mode="hybrid"
  position="bottom-center"
  title="Customer Support Portal"
  ctaTitle="Need Help?"
  ctaSubtitle="Chat with our AI assistant"
  accentColor="#10b981"
  size="full"
/>

Development

Setup

# Clone the repository
git clone https://github.com/VapiAI/client-sdk-react.git
cd client-sdk-react

# Install dependencies
npm install

# Build everything
npm run build:all

Development Commands

  • npm run dev - Start development server
  • npm run build - Build React library
  • npm run build:widget - Build embeddable widget
  • npm run build:all - Build both library and widget
  • npm run lint - Run ESLint
  • npm run type-check - Check TypeScript types

Running the Example

cd example
npm install
npm run dev

Visit http://localhost:5173 to see the example app.

Browser Support

  • Chrome/Edge 79+
  • Firefox 86+
  • Safari 14.1+
  • Mobile browsers with WebRTC support

Requirements

  • Microphone access for voice mode
  • HTTPS required in production
  • VAPI account and API key

Contributing

  • Fork the repository
  • Create a feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

Support

Keywords

vapi

FAQs

Package last updated on 20 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.