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:- Sarvam Account: Sign up at Sarvam
- API Key: Generate an API key from your account dashboard
- Model: The service supports
deepseekv4.1-flash,gemma4,glm5.3,sarvam-105b, andsarvam-105b-conversationsmodels
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.
Raises
ValueError when empty.str | None
default:"None"
Sarvam OpenAI-compatible base URL. When
None, resolved from the model at
construction: /v1 for sarvam-105b-conversations, /v2 for all other
models. Changing model at runtime does not change the endpoint. Override if
using a different endpoint.Mapping[str, str]
default:"None"
Additional HTTP headers to include in every request.
Settings
Runtime-configurable settings passed via thesettings 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 usingLLMUpdateSettingsFrame:
Notes
- OpenAI Compatibility: Sarvam’s API is OpenAI-compatible, allowing use of familiar patterns and parameters.
- Model-Specific Capabilities: A request that uses a capability the model lacks is not sent; the service pushes an
ErrorFrameinstead.- Vision: Only
gemma4supports image input via inline data-URI images. - Reasoning:
deepseekv4.1-flash,gemma4,glm5.3, andsarvam-105bsupport thereasoning_effortparameter.sarvam-105b-conversationsdoes not. - Wiki Grounding:
gemma4andsarvam-105bsupport thewiki_groundingparameter.
- Vision: Only
- Function Calling: Supports OpenAI-style tool/function calling format. A request with
tool_choiceand no non-emptytoolslist is not sent; the service pushes anErrorFrameinstead. - Unsupported Parameters: Some OpenAI parameters are not supported by Sarvam’s API and are automatically removed from requests:
stream_optionsandservice_tier.
Event Handlers
SarvamLLMService supports the following event handlers, inherited from LLMService: