Developer Quickstart

View as Markdown

Get started with Sarvam APIs in 30 seconds: create a key, install the SDK, and make your first call with just a few lines of code.

Prerequisites:

  • A Sarvam AI account and API key. Create one on the dashboard if you don’t have one yet.
  • Python 3.9+ or Node.js 18+ (or skip both and call the REST API directly with curl).

By the end of this quickstart, you’ll have made a live call to a Sarvam AI API and gotten back a real result: a transcript, a playable audio file, a translation, or a chat reply, depending on which API you try below.

Setup

1

Create an API Key

Visit the Sarvam AI dashboard and create a new API key. Keep this key secure; you’ll need it to authenticate your requests.

2

Set Up Your Environment

Export your API key as an environment variable:

$export SARVAM_API_KEY="YOUR_SARVAM_API_KEY"
3

Install the SDK

Choose your preferred language and install our SDK. Need a different language or an older version? See Libraries & SDKs.

$pip install -U sarvamai
4

Make Your First API Call

Here’s a Chat Completion example using the key and SDK you just set up. Paste it in and run it:

1from sarvamai import SarvamAI
2
3client = SarvamAI(
4 api_subscription_key="YOUR_SARVAM_API_KEY",
5)
6
7response = client.chat.completions(
8 model="sarvam-105b",
9 messages=[
10 {"role": "user", "content": "What is the capital of India?"}
11 ],
12)
13print(response.choices[0].message.content)
14# → "The capital of India is New Delhi."

Prefer Speech to Text, Text to Speech, or Translation instead? Jump to Try an API below, each comes with its own Python, JavaScript, and cURL example.

Keep your key safe. Store it in an environment variable or a secrets manager, and never commit it to version control. Getting a 403? See Authentication. Getting a 429? See Credits & Rate Limits. Any other error code is listed in Errors & Troubleshooting.

Try an API

Sarvam AI covers four core capabilities below. Pick a tab, and copy-paste your way to a working call.

Saaras v3 is our latest speech recognition model. It supports multiple output modes: transcribe (default, original language), translate (to English), verbatim (word-for-word), translit (romanization), and codemix (mixed script).

1from sarvamai import SarvamAI
2
3client = SarvamAI(
4 api_subscription_key="YOUR_SARVAM_API_KEY",
5)
6
7try:
8 response = client.speech_to_text.transcribe(
9 file=open("audio.wav", "rb"), # path to your own audio file
10 model="saaras:v3",
11 mode="transcribe", # or "translate", "verbatim", "translit", "codemix"
12 )
13 print(response.transcript)
14except Exception as e:
15 print(f"Error: {e}")

Use transcribe for same-language output, translate to convert audio to English text, or verbatim/translit/codemix for specialized formatting. mode defaults to transcribe when omitted.

Next Steps

Pick up where you left off, based on the API you just tried: