This repository contains small, practical examples for building with Sarvam AI:
- direct chat completion calls using the Sarvam SDK
- an OpenAI-compatible local bridge server backed by Sarvam
- a client script that talks to that bridge through the OpenAI SDK
- Python (project metadata currently declares
>=3.14inpyproject.toml) - A valid Sarvam API key
- Clone the repository:
git clone https://github.com/harshdadiya-wappnet/explore_sarvam
cd explore_sarvam- Create your environment file:
cp .env.example .envThen set your key in .env:
SARVAM_API_KEY=your_actual_key- Install dependencies (choose one):
Using uv:
uv venv
source .venv/bin/activate
uv syncUsing pip:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install fastapi uvicorn openai.
├── README.md
├── pyproject.toml
├── requirements.txt
└── learning/
├── simple_usage.py
├── openai_chat_completion_server.py
└── simple_usage_using_openai.py
Run:
python -m learning.simple_usageWhat it does:
- reads
SARVAM_API_KEYfrom.env - sends chat completion requests through the
sarvamaiSDK - runs an interactive CLI loop until you type
exit,quit, orq
Run:
python -m learning.openai_chat_completion_serverThe server starts at http://localhost:8000 and exposes:
GET /v1/modelsPOST /v1/chat/completions
It accepts OpenAI-style chat completion requests and forwards them to Sarvam.
In a second terminal (with the same virtual env active), run:
python learning/simple_usage_using_openai.pyThis script uses:
base_url="http://localhost:8000"api_key=$SARVAM_API_KEYmodel="sarvam-m"
With the bridge server running:
curl -s http://localhost:8000/v1/modelsExample chat request:
curl -s http://localhost:8000/v1/chat/completions \
-H "Authorization: Bearer $SARVAM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "sarvam-m",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello in one line."}
]
}'- If you are using only
requirements.txt, install extra runtime packages for the bridge/client (fastapi,uvicorn,openai) as shown above. - Keep
.envout of version control.