Skip to main content

Overview

SarvamLLMService provides chat completion capabilities using Sarvam’s API with OpenAI-compatible interface. It supports streaming responses, function calling, and Sarvam-specific features like wiki grounding and configurable reasoning effort levels.

Sarvam LLM API Reference

Pipecat’s API methods for Sarvam integration

Example Implementation

Function calling example with Sarvam

Sarvam Documentation

Official Sarvam documentation

Sarvam Platform

Access models and manage API keys

Installation

To use Sarvam LLM services, install the required dependencies:

Prerequisites

Sarvam Account Setup

Before using Sarvam LLM services, you need:
  1. Sarvam Account: Sign up at Sarvam
  2. API Key: Generate an API key from your account dashboard
  3. Model: The service supports gemma4, glm5.2, sarvam-105b, and sarvam-105b-conversations models

Required Environment Variables

  • SARVAM_API_KEY: Your Sarvam API key for authentication

Configuration

str
required
Sarvam API key used for both OpenAI auth and Sarvam subscription header.
str | None
default:"None"
Sarvam OpenAI-compatible base URL. When None, resolved from the model: /v1 for sarvam-105b-conversations, /v2 for all other models. Override if using a different endpoint.
SarvamLLMService.Settings
default:"None"
Runtime-configurable model settings. See Settings below.
Mapping[str, str]
default:"None"
Additional HTTP headers to include in every request.

Settings

Runtime-configurable settings passed via the settings constructor argument using SarvamLLMService.Settings(...). These can be updated mid-conversation with LLMUpdateSettingsFrame. See Service Settings for details.
NOT_GIVEN values are omitted from the API request entirely, letting the Sarvam API use its own defaults. This is different from None, which would be sent explicitly.

Usage

Basic Setup

With Custom Settings

Updating Settings at Runtime

Model settings can be changed mid-conversation using LLMUpdateSettingsFrame:

Notes

  • OpenAI Compatibility: Sarvam’s API is OpenAI-compatible, allowing use of familiar patterns and parameters.
  • Base URL Resolution: The base_url is resolved automatically from the selected model when not explicitly provided. sarvam-105b-conversations uses /v1, while all other models use /v2. If you need to override this, pass base_url explicitly.
  • Model-Specific Capabilities:
    • Vision: Only gemma4 supports image input via inline data-URI images. Other models will return an error if image content is provided.
    • Reasoning: gemma4, glm5.2, and sarvam-105b support the reasoning_effort parameter. Using it with sarvam-105b-conversations will return an error.
    • Wiki Grounding: gemma4 and sarvam-105b support the wiki_grounding parameter. Using it with other models will return an error.
  • Function Calling: Supports OpenAI-style tool/function calling format. When using tool_choice, you must provide a non-empty tools list.
  • Unsupported Parameters: Some OpenAI parameters are not supported by Sarvam’s API and are automatically removed from requests: stream_options, max_completion_tokens, service_tier.

Event Handlers

SarvamLLMService supports the following event handlers, inherited from LLMService: