Language model
Multilingual model with support for Indian languages, for text generation and reasoning.
Install langchain-sarvam
Add langchain-sarvam and python-dotenv. It needs Python 3.10 or higher.
Add your API key
Set SARVAM_API_KEY in a .env file with a key from indus.sarvam.ai. ChatSarvam reads it automatically.
Create a ChatSarvam instance
Use ChatSarvam(model="sarvam-105b") in chains, agents, or tool-calling loops like any other BaseChatModel.
pip install langchain-sarvam python-dotenv
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) # പാചകം തുടരൂ, സുഹൃത്തുക്കളേ
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.
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.
Ready to build? Follow the LangChain guide in the Sarvam docs.
Ready to build?
Follow the LangChain guide in the Sarvam docs.