Guide for integrating the Sarvam Client SDK into React Native applications on iOS and Android. For shared concepts like configuration, proxy setup, error handling, and API reference, see the Overview.

Installation

For voice conversations, you need to implement your own audio interface using the AsyncAudioInterface contract. See Custom Audio Interface below.

Quick Start

Text Conversation

Voice Conversation


Custom Audio Interface

React Native does not have a built-in browser audio API, so you must provide your own audio interface that implements the AsyncAudioInterface contract:


Authentication

Since cookies aren’t available in React Native, use customHeaders to pass authentication tokens when using a proxy server:

Best Practices

Resource Cleanup

Always stop the agent when the component unmounts:

Handle App Lifecycle

Stop or pause the agent when the app goes to the background to avoid holding audio resources:

Connection Timeout

Always specify a timeout when waiting for connection:

Troubleshooting

Microphone Permission Denied

Request microphone permissions before starting a voice conversation. For Expo projects:
For bare React Native, use react-native-permissions:

Connection Timeout

  • Check internet connectivity
  • Verify your API key is valid
  • Ensure org_id, workspace_id, and app_id are correct
  • Make sure the app has a committed version

No Audio Output

  • Check device volume and silent mode switch (iOS)
  • Verify your AsyncAudioInterface.output() implementation is correctly writing to the audio output
  • Ensure the sample rate in your audio playback matches output_sample_rate

WebSocket Disconnects on Background

React Native suspends WebSocket connections when the app is backgrounded. Since reconnection is not supported (each WebSocket URL is single-use), you must stop the agent and create a new instance: