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

# Sarvamai

> Python API reference for the sarvamai llm plugin.

<Card title="Usage guide" icon="book" href="/plugins/llm/sarvamai" horizontal>
  Setup, environment variables, and Python/JavaScript/Go usage examples.
</Card>

## SarvamAILLM

Sarvam AI Large Language Model provider plugin.

Wraps the Sarvam AI chat-completions API, which exposes models optimised
for Indian languages (22 Indic languages + English).  Unique capabilities
include Sarvam-specific `wiki_grounding` (grounding responses in
Wikipedia-derived knowledge) and configurable `reasoning_effort` for
chain-of-thought depth control.  The API is OpenAI-compatible and
supports streaming, tool/function calling, and structured output.

### Constructor

```python theme={null}
SarvamAILLM(*, api_key: 'str | None' = None, model: 'SarvamAILLMModel | str' = 'sarvam-30b', temperature: 'float' = 0.7, tool_choice: 'str' = 'auto', max_completion_tokens: 'int | None' = None, top_p: 'float | None' = None, frequency_penalty: 'float | None' = None, presence_penalty: 'float | None' = None, seed: 'int | None' = None, stop: 'str | None' = None, user: 'str | None' = None, parallel_tool_calls: 'bool | None' = None, response_format: 'dict | None' = None, reasoning_effort: 'Optional[str]' = None, wiki_grounding: 'bool' = False, **kwargs) -> 'None'
```

<ParamField path="api_key" type="str | None">
  Sarvam AI API key.  Falls back to the `SARVAM_API_KEY` environment variable when `None`.
</ParamField>

<ParamField path="model" type="SarvamAILLMModel | str" default="sarvam-30b">
  Sarvam AI model identifier.  Defaults to `"sarvam-30b"`.  Available models: `"sarvam-30b"`: 30 B MoE model (2.4 B active params); strong reasoning and conversational capabilities at a balanced performance-to-cost ratio. `"sarvam-105b"`: 105 B flagship model; highest quality Indian-language understanding, reasoning, and generation.
</ParamField>

<ParamField path="temperature" type="float" default="0.7">
  Sampling temperature controlling output randomness. Range 0 – 2.  Defaults to `0.7` (`0.5` when reasoning is enabled, `0.2` when disabled on the API side).  Lower values produce more deterministic output.
</ParamField>

<ParamField path="tool_choice" type="str" default="auto">
  Controls when the model invokes tools.  Defaults to `"auto"`.  Mirrors the OpenAI `tool_choice` parameter (`"auto"`, `"none"`, `"required"`, or a specific tool object).
</ParamField>

<ParamField path="max_completion_tokens" type="int | None">
  Maximum number of tokens to generate in the completion.  Defaults to `1024` when not set.  Tier limits: Starter 4 096, Pro 8 192, Business 64 000.
</ParamField>

<ParamField path="top_p" type="float | None">
  Nucleus-sampling probability mass cutoff.  Range 0 – 1. `None` uses the provider default.
</ParamField>

<ParamField path="frequency_penalty" type="float | None">
  Penalises repeated tokens based on their cumulative frequency.  Range –2.0 – 2.0.  `None` disables.
</ParamField>

<ParamField path="presence_penalty" type="float | None">
  Penalises tokens that have already appeared at least once.  Range –2.0 – 2.0.  `None` disables.
</ParamField>

<ParamField path="seed" type="int | None">
  Fixed random seed for deterministic generation.  `None` means no fixed seed.
</ParamField>

<ParamField path="stop" type="str | None">
  Up to 4 stop sequences that halt generation early. `None` disables.
</ParamField>

<ParamField path="user" type="str | None">
  An opaque end-user identifier forwarded to the API for abuse-detection purposes.  `None` omits the field.
</ParamField>

<ParamField path="parallel_tool_calls" type="bool | None">
  When `True`, the model may emit multiple tool calls in a single response turn.  `None` uses the provider default.
</ParamField>

<ParamField path="response_format" type="dict | None">
  Structured-output specification dict (e.g. `&#123;"type": "json_object"&#125;`).  `None` returns plain text.
</ParamField>

<ParamField path="reasoning_effort" type="Optional[str]">
  Controls the depth of chain-of-thought reasoning.  Valid values: `"low"`, `"medium"`, `"high"`, or `None` to disable reasoning entirely.  Higher effort increases both quality and latency/cost since reasoning tokens are billed as completion tokens.
</ParamField>

<ParamField path="wiki_grounding" type="bool" default="False">
  When `True`, the model grounds its responses using Wikipedia-derived knowledge, improving factual accuracy for knowledge-intensive queries.  Defaults to `False`.
</ParamField>

### aclose

```python theme={null}
def aclose(self) -> 'None'
```

Release any resources held by the provider.

### cancel\_current\_generation

```python theme={null}
def cancel_current_generation(self) -> 'None'
```

Cancel the in-progress generation for the active session, if any.

### chat

```python theme={null}
def chat(self, messages: 'Any', tools: 'Any' = None, conversational_graph: 'Any' = None, **kwargs: 'Any') -> 'AsyncIterator[LLMResponse]'
```

Generate a streamed chat completion.

<ParamField path="messages" type="Any" required>
  The conversation history to send to the model.
</ParamField>

<ParamField path="tools" type="Any">
  Optional tool definitions the model may call.
</ParamField>

<ParamField path="conversational_graph" type="Any">
  Optional conversational graph guiding the exchange.
</ParamField>

<ResponseField name="returns" type="AsyncIterator[LLMResponse]">
  LLMResponse: Response chunks produced as the model generates output.
</ResponseField>

### emit

```python theme={null}
def emit(self, event: 'T', *args: 'Any') -> 'None'
```

Emit an event, invoking all registered handlers with the given arguments.

Handlers are called in registration order. Coroutine handlers are
scheduled on the running event loop. If the emitter is closed, the call
is a no-op.

<ParamField path="event" type="T" required>
  The event to emit.
</ParamField>

### off

```python theme={null}
def off(self, event: 'T', callback: 'Callable[..., Any]') -> 'None'
```

Remove a previously registered handler for an event.

If the handler is not registered for the event, the call is a no-op.

<ParamField path="event" type="T" required>
  The event the handler was registered for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any]" required>
  The handler to remove.
</ParamField>

### on

```python theme={null}
def on(self, event: 'T', callback: 'Callable[..., Any] | None' = None) -> 'Callable[..., Any]'
```

Register a handler for an event.

Can be used directly by passing a callback, or as a decorator when
`callback` is omitted.

<ParamField path="event" type="T" required>
  The event to listen for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any] | None">
  The handler to invoke when the event is emitted. If `None`, a decorator is returned that registers the decorated function.
</ParamField>

<ResponseField name="returns" type="Callable[..., Any]">
  The registered callback when `callback` is provided, otherwise a decorator that registers and returns the function it wraps.
</ResponseField>

***

## SarvamAILLMModel

```python theme={null}
SarvamAILLMModel = typing.Literal['sarvam-30b', 'sarvam-105b']
```
