Sarvam AI
LangChain logo

Sarvam + LangChain

Agent Framework

The official langchain-sarvam package. Use ChatSarvam as a drop-in BaseChatModel for chains, agents, tool calling, streaming, and structured output, exactly like ChatOpenAI or ChatAnthropic.

Sarvam APIs supported
sarvam-105b

Language model

Multilingual model with support for Indian languages, for text generation and reasoning.

How it works
1.

Install langchain-sarvam

Add langchain-sarvam and python-dotenv. It needs Python 3.10 or higher.

2.

Add your API key

Set SARVAM_API_KEY in a .env file with a key from indus.sarvam.ai. ChatSarvam reads it automatically.

3.

Create a ChatSarvam instance

Use ChatSarvam(model="sarvam-105b") in chains, agents, or tool-calling loops like any other BaseChatModel.

Quick start
Install
Bash
pip install langchain-sarvam python-dotenv
Code
Python
from dotenv import load_dotenv
from langchain_sarvam import ChatSarvam

load_dotenv()

llm = ChatSarvam(model="sarvam-105b")

response = llm.invoke("Translate this to malayalam: 'Keep cooking, guys'")
print(response.content)  # പാചകം തുടരൂ, സുഹൃത്തുക്കളേ
Best practices

Raise max_tokens for long answers

Set max_tokens and check response_metadata["finish_reason"]. A value of "length" means the answer was cut off.

Set reasoning_effort for structured output

with_structured_output() sends reasoning_effort=None by default to keep the token budget for the JSON. Pass "low", "medium", or "high" to combine the two.

Catch ChatSarvamError

ChatSarvam wraps auth, rate limit, and network failures in one ChatSarvamError. Catch it and read str(e) for the cause.

Control tool calls with tool_choice

Pass "auto", "none", "required", or a tool name to bind_tools() to decide when the model calls a tool.

Use cases

Multilingual

Multilingual chat agents

Build LangChain agents that reason and respond in Indian languages.

Tool-calling

Tool-calling pipelines

Wire Sarvam models into bind_tools() workflows alongside retrievers and other LangChain components.

Structured

Structured output chains

Use with_structured_output() to extract typed, schema-constrained data from text in Indian languages.

Resources and details
Type Official integration
Language Python 3.10+
Maintained by Sarvam
Install pip install langchain-sarvam

Ready to build? Follow the LangChain guide in the Sarvam docs.