Skip to main content

langchain-sarvamai

The langchain-sarvamai package provides a LangChain integration for Sarvam AI's language models, optimised for Indian languages and enterprise workloads.

Installation

pip install langchain-sarvamai

Setup

Get your API key from Sarvam AI and set it as an environment variable:

export SARVAM_API_KEY="your-api-key"

Usage

Chat Model

from langchain_sarvamai import ChatSarvam

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

# Invoke
response = llm.invoke("What is the capital of India?")
print(response.content)

# With system message
from langchain_core.messages import HumanMessage, SystemMessage

messages = [
    SystemMessage(content="You are a helpful assistant."),
    HumanMessage(content="Tell me about Indian languages."),
]
response = llm.invoke(messages)
print(response.content)

# Stream
for chunk in llm.stream("Count from 1 to 5."):
    print(chunk.content, end="", flush=True)

# Async
import asyncio
response = asyncio.run(llm.ainvoke("Hello!"))

Available Models

Model Description
sarvam-105b Flagship model — best quality (default)
sarvam-30b Faster, lighter model

Reasoning Mode

llm = ChatSarvam(model="sarvam-105b", reasoning_effort="high")
response = llm.invoke("Explain the Riemann hypothesis.")
# Access reasoning trace
print(response.additional_kwargs.get("reasoning_content"))

Supported values for reasoning_effort: "low", "medium", "high".

Parameters

Parameter Type Default Description
model str "sarvam-105b" Model name
temperature float None Sampling temperature [0, 1]
max_tokens int None Max tokens to generate
top_p float None Nucleus sampling probability
streaming bool False Enable streaming
reasoning_effort str None Reasoning effort: "low", "medium", "high"
api_key str env var Sarvam API key
base_url str "https://api.sarvam.ai/v1" Custom API base URL

Development

# Install with dev dependencies
pip install -e ".[test]"

# Run unit tests
pytest tests/unit_tests/ -v

# Run integration tests (requires SARVAM_API_KEY)
pytest tests/integration_tests/ -v

License

MIT

Metadata

Release files for langchain-sarvamai 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-sarvamai 0.1.0
File Size Uploaded
langchain_sarvamai-0.1.0.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-sarvamai 0.1.0
File Interpreter ABI Platform
langchain_sarvamai-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.7 kB

Release files / langchain_sarvamai-0.1.0.tar.gz

Download URL langchain_sarvamai-0.1.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
19e005c3bfeafa5f4e7805ea81a89bc508d682e67a87237cb1e6e22915983970
BLAKE2b-256 checksum
How to use checksums
e6cec4c9f37688d39a96ed5b040e379ea23054613be183bdbb93edf1a0aad00f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 17, 2026.

Transparency log

Release files / langchain_sarvamai-0.1.0-py3-none-any.whl

Download URL langchain_sarvamai-0.1.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3413b0ae9a5cdbf0279e8d3eaebb039c170d104a71aa9aa6a9997be8abd6b7fc
BLAKE2b-256 checksum
How to use checksums
5befcc81609f2d04410a479800f085b2ec62e245178341b7cd98a9b3735c30bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page