The Sarvam Client SDKs provide a lightweight, event-driven interface for building real-time voice and text conversations. They handle WebSocket connectivity, audio streaming, buffering, and state management out of the box — so you can focus on your application logic.

Web

For browser-based web apps using React.

React Native

For iOS and Android apps using React Native.

Flutter

For cross-platform mobile apps using Flutter.

Configuration

The configuration and API reference on this page apply to the TypeScript SDK (Web and React Native). For Flutter/Dart equivalents, see the Flutter page.

Required Fields

Optional Fields


Using a Proxy Server

We strongly recommend using a proxy server for production deployments to keep your API key secure and enforce access control. See the Proxy Setup guide for server configuration, client examples for each platform, and security best practices.

Mute and Unmute

Control microphone input without disconnecting:
When muted, the SDK sends continuous silence chunks to keep VAD (Voice Activity Detection) stable, preventing connection issues.

Custom Events via Transcript

Backend tools can send custom events to the frontend through the transcriptCallback. These messages appear as bot transcripts with special formats that your app can intercept and handle.
Backend Requirement: Tools must emit ServerToolEvent.NotifyUI events with message_to_user containing the message content. See your backend SDK documentation for implementation details.

Thinking State

The backend sends thinking_started and thinking_completed messages when tools are processing:

MCP Widgets

MCP (Model Context Protocol) Apps enable interactive widgets in your conversation UI. The backend sends widget URLs with data, and your frontend renders them in iframes.

Message Format

The backend sends messages in this format:
Example:

Parsing Widget Messages

Initializing the Widget

Widgets expect initialization data via postMessage when the iframe loads:

Rendering the Widget


Agent State Tracking

Monitor the agent’s state to update your UI:

Transcripts and Chat History

Use transcriptCallback for voice conversation transcripts:
Use textCallback for text chat agent responses:

Analytics and Telemetry

Track SDK events for monitoring and debugging. Here’s an example using New Relic:

Connection Lifecycle

Reconnection is not supported. Each WebSocket URL is single-use and expires after the first connection. If the connection drops, you must call agent.stop() and create a new ConversationAgent instance to start a fresh session.

Supported Languages

Available languages:
  • BENGALI, GUJARATI, KANNADA, MALAYALAM, TAMIL
  • TELUGU, PUNJABI, ODIA, MARATHI, HINDI, ENGLISH

API Reference

ConversationAgent Constructor

ConversationAgent Methods


Error Handling

The SDK provides typed error classes for different failure scenarios:

Error Types

All errors extend SDKError which has:
  • message - Human-readable error description
  • code - Programmatic error code (e.g., "RATE_LIMITED", "AUTHENTICATION_FAILED")
  • statusCode - HTTP status code if applicable

Handling Connection Errors

Use the telemetryCallback to monitor connection issues:

Troubleshooting

Connection timeout

Ensure your app_id has a committed version. If no version is specified, the SDK uses the latest committed version—if none exists, the connection fails.