vapi library

Vapi Flutter SDK with unified mobile and web support

A Flutter SDK for integrating with the Vapi voice AI platform.

This library provides a simple and intuitive interface for adding voice AI capabilities to your Flutter applications across multiple platforms.

Getting Started

  1. Create a VapiClient instance with your public API key:
final vapiClient = VapiClient('your-public-key-here');
  1. Start a call and get a VapiCall instance:
final call = await vapiClient.start(assistantId: 'your-assistant-id');
  1. Access call information:
print('Call ID: ${call.id}');
print('Assistant ID: ${call.assistantId}');
print('Created at: ${call.createdAt}');
print('Status: ${call.status}');
  1. Listen for events on the call:
call.onEvent.listen((event) {
  switch (event.label) {
    case 'call-start':
      print('Assistant is ready and listening');
      break;
    case 'call-end':
      print('Call has ended');
      break;
    case 'message':
      print('Message from assistant: ${event.value}');
      break;
  }
});
  1. Interact during the call:
// Send a message
await call.send({'type': 'user-message', 'message': 'Hello'});

// Mute/unmute
call.setMuted(true);

// Change audio device (mobile only)
if (call is VapiMobileCall) {
  call.setAudioDevice(device: VapiAudioDevice.speakerphone);
}

// Check if call is still active
if (call.status == VapiCallStatus.active) {
  // Call is still ongoing
}
  1. End the call and clean up:
await call.stop();
call.dispose();
client.dispose();

Architecture

The SDK uses a clean factory pattern with platform-specific implementations:

  • VapiClient: Factory class that creates platform-appropriate implementations
  • VapiClientInterface: Abstract interface for all client implementations
  • VapiCallInterface: Abstract interface for all call implementations
  • VapiMobileClient/VapiMobileCall: Mobile implementation using Daily.co WebRTC
  • VapiWebClient/VapiWebCall: Web implementation using Vapi Web SDK (coming soon)

This architecture allows for:

  • Automatic platform detection and selection
  • Platform-specific optimizations
  • Clean separation of concerns
  • Easy addition of new platforms
  • Type-safe platform-specific features
  • Consistent API across platforms

Available Types

The SDK exports the following types for your use:

  • VapiClient - The main factory class for creating platform-appropriate clients
  • VapiClientInterface - Interface for client implementations
  • VapiCallInterface - Interface for call implementations
  • VapiCallStatus - Enum representing call status (starting, active, ended)
  • VapiEvent - Event objects emitted during calls
  • VapiAudioDevice - Audio device options
  • Various exception classes for error handling

Classes

AssistantConfig
VapiCall
Abstract interface defining the contract for Vapi call implementations.
VapiClient
Factory class for creating platform-specific Vapi clients.
VapiClientInterface
Abstract interface defining the contract for Vapi client implementations.
VapiEvent
Represents an event that occurs during the Vapi call lifecycle.

Enums

VapiAudioDevice
Available audio output devices for Vapi calls.
VapiCallStatus
Represents the current status of a Vapi call.

Constants

defaultApiBaseUrl → const String

Exceptions / Errors

VapiCallEndedException
Thrown when attempting to perform an operation on a call that has ended.
VapiCallInProgressException
Thrown when attempting to start a call while another call is already in progress.
VapiClientCreationError
Error thrown when the Vapi client cannot be created
VapiConfigurationException
Thrown when the client is configured with invalid parameters.
VapiError
The base error class for all Vapi-related errors.
VapiException
Base exception class for all Vapi-related errors.
VapiMissingAssistantException
Thrown when neither assistantId nor assistant is provided to the start method.
VapiStartCallException
Thrown when the call client fails to start or join the call session.