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
gemma4,glm5.2,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.
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.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.
- Base URL Resolution: The
base_urlis resolved automatically from the selected model when not explicitly provided.sarvam-105b-conversationsuses/v1, while all other models use/v2. If you need to override this, passbase_urlexplicitly. - Model-Specific Capabilities:
- Vision: Only
gemma4supports image input via inline data-URI images. Other models will return an error if image content is provided. - Reasoning:
gemma4,glm5.2, andsarvam-105bsupport thereasoning_effortparameter. Using it withsarvam-105b-conversationswill return an error. - Wiki Grounding:
gemma4andsarvam-105bsupport thewiki_groundingparameter. Using it with other models will return an error.
- Vision: Only
- Function Calling: Supports OpenAI-style tool/function calling format. When using
tool_choice, you must provide a non-emptytoolslist. - 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: