> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sarvam

> Large Language Model services using Sarvam's OpenAI-compatible API

## 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.

<CardGroup cols={2}>
  <Card title="Sarvam LLM API Reference" icon="code" href="https://reference-server.pipecat.ai/en/latest/api/pipecat.services.sarvam.llm.html">
    Pipecat's API methods for Sarvam integration
  </Card>

  <Card title="Example Implementation" icon="play" href="https://github.com/pipecat-ai/pipecat/blob/main/examples/function-calling/function-calling-sarvam.py">
    Function calling example with Sarvam
  </Card>

  <Card title="Sarvam Documentation" icon="book" href="https://sarvam.ai/">
    Official Sarvam documentation
  </Card>

  <Card title="Sarvam Platform" icon="globe" href="https://api.sarvam.ai">
    Access models and manage API keys
  </Card>
</CardGroup>

## Installation

To use Sarvam LLM services, install the required dependencies:

```bash theme={null}
uv add "pipecat-ai[sarvam]"
```

## Prerequisites

### Sarvam Account Setup

Before using Sarvam LLM services, you need:

1. **Sarvam Account**: Sign up at [Sarvam](https://sarvam.ai/)
2. **API Key**: Generate an API key from your account dashboard
3. **Model Selection**: Choose from available models (sarvam-30b, sarvam-105b, etc.)

### Required Environment Variables

* `SARVAM_API_KEY`: Your Sarvam API key for authentication

## Configuration

<ParamField path="api_key" type="str" required>
  Sarvam API key used for both OpenAI auth and Sarvam subscription header.
</ParamField>

<ParamField path="base_url" type="str" default="https://api.sarvam.ai/v1">
  Sarvam OpenAI-compatible base URL. Override if using a different endpoint.
</ParamField>

<ParamField path="settings" type="SarvamLLMService.Settings" default="None">
  Runtime-configurable model settings. See [Settings](#settings) below.
</ParamField>

<ParamField path="default_headers" type="Mapping[str, str]" default="None">
  Additional HTTP headers to include in every request.
</ParamField>

### Settings

Runtime-configurable settings passed via the `settings` constructor argument using `SarvamLLMService.Settings(...)`. These can be updated mid-conversation with `LLMUpdateSettingsFrame`. See [Service Settings](/pipecat/fundamentals/service-settings) for details.

| Parameter           | Type                               | Default        | Description                                                                                                  |
| ------------------- | ---------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------ |
| `model`             | `str`                              | `"sarvam-30b"` | Sarvam model identifier. Supported models: `sarvam-30b`, `sarvam-30b-16k`, `sarvam-105b`, `sarvam-105b-32k`. |
| `wiki_grounding`    | `bool`                             | `None`         | Enable or disable wiki grounding feature. Sarvam-specific parameter.                                         |
| `reasoning_effort`  | `Literal["low", "medium", "high"]` | `None`         | Set reasoning effort level. Sarvam-specific parameter.                                                       |
| `temperature`       | `float`                            | `NOT_GIVEN`    | Sampling temperature (0.0 to 2.0). Lower values are more focused, higher values are more creative.           |
| `max_tokens`        | `int`                              | `NOT_GIVEN`    | Maximum tokens to generate.                                                                                  |
| `top_p`             | `float`                            | `NOT_GIVEN`    | Top-p (nucleus) sampling (0.0 to 1.0). Controls diversity of output.                                         |
| `frequency_penalty` | `float`                            | `NOT_GIVEN`    | Penalty for frequent tokens (-2.0 to 2.0). Positive values discourage repetition.                            |
| `presence_penalty`  | `float`                            | `NOT_GIVEN`    | Penalty for new topics (-2.0 to 2.0). Positive values encourage the model to talk about new topics.          |

<Note>
  `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.
</Note>

## Usage

### Basic Setup

```python theme={null}
import os
from pipecat.services.sarvam import SarvamLLMService

llm = SarvamLLMService(
    api_key=os.getenv("SARVAM_API_KEY"),
)
```

### With Custom Settings

```python theme={null}
import os
from pipecat.services.sarvam import SarvamLLMService

llm = SarvamLLMService(
    api_key=os.getenv("SARVAM_API_KEY"),
    settings=SarvamLLMService.Settings(
        model="sarvam-105b",
        temperature=0.7,
        max_tokens=1000,
        wiki_grounding=True,
        reasoning_effort="high",
    ),
)
```

### Updating Settings at Runtime

Model settings can be changed mid-conversation using `LLMUpdateSettingsFrame`:

```python theme={null}
from pipecat.frames.frames import LLMUpdateSettingsFrame
from pipecat.services.sarvam.llm import SarvamLLMSettings

await task.queue_frame(
    LLMUpdateSettingsFrame(
        delta=SarvamLLMSettings(
            temperature=0.3,
            reasoning_effort="medium",
        )
    )
)
```

## Notes

* **OpenAI Compatibility**: Sarvam's API is OpenAI-compatible, allowing use of familiar patterns and parameters.
* **Sarvam-Specific Features**: The `wiki_grounding` and `reasoning_effort` parameters are unique to Sarvam and provide additional control over model behavior.
* **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](/api-reference/server/events/service-events):

| Event                       | Description                                                             |
| --------------------------- | ----------------------------------------------------------------------- |
| `on_completion_timeout`     | Called when an LLM completion request times out                         |
| `on_function_calls_started` | Called when function calls are received and execution is about to start |

```python theme={null}
@llm.event_handler("on_completion_timeout")
async def on_completion_timeout(service):
    print("LLM completion timed out")
```
