Skip to navigation

Speech-to-Text Rest API

View as Markdown

Send an audio file, get the transcript back in the same HTTP response. Use it for short clips, voice commands, and quick testing. For anything longer than 30 seconds, use the Batch API.

EndpointPOST https://api.sarvam.ai/speech-to-text (multipart/form-data)
Max duration30 seconds per request
FormatsWAV, MP3, AAC, FLAC, OGG/Opus, M4A/MP4, AIFF, AMR, WMA, WebM
Authapi-subscription-key header
Default modelsaaras:v4

Not sure whether to use REST, Batch, or Streaming? See Which API to Use for a side-by-side comparison of limits, latency, and features.

Saaras is our state-of-the-art speech recognition family with flexible output formats. It supports multiple modes for different use cases: transcribe, translate, verbatim, transliterate, and codemix.

Saaras v4 is the default model and the one to use for new integrations. It adds Global English support and keyterm prompting. Saaras v3 is legacy; always set model="saaras:v4". Learn more about Saaras.

Output Modes

ModeDescription
transcribe (default)Standard transcription in the original language
translateTranslates speech to English
verbatimExact word-for-word transcription
translitRomanization to Latin script
codemixCode-mixed text output

Code Examples

The examples below use saaras:v4, the default model. Pass keyterms to bias recognition toward specific names, places, brands, or technical terms.

import os
from sarvamai import SarvamAI
client = SarvamAI(
api_subscription_key=os.environ["SARVAM_API_KEY"],
)
# Transcribe mode (default)
response = client.speech_to_text.transcribe(
file=open("audio.wav", "rb"),
model="saaras:v4",
mode="transcribe", # or "translate", "verbatim", "translit", "codemix"
keyterms=["Sarvam", "New Delhi", "Vistaar"] # optional, up to 50 terms
)
print(response)

keyterms is supported only on saaras:v4. Up to 50 terms, 64 characters each. See Keyterm Prompting.

Check out our detailed API Reference to explore all available options.

Preparing Your Audio

Most failed STT requests are caused by the audio itself, not the API call. Run through this checklist before uploading:

CheckRecommendation
DurationThe sync REST API accepts up to 30 seconds per request. For longer files, use the Batch API (up to 2 hours per file) or split the audio into ≤30s chunks.
Sample rate16 kHz is recommended. 8 kHz telephony audio (IVR, call recordings) is fully supported, no need to upsample.
ChannelsUse mono. For stereo telephony recordings with one speaker per channel, split the channels and transcribe each separately to keep speakers separated.
FormatWAV, MP3, AAC, FLAC, OGG/Opus, M4A/MP4, AIFF, AMR, WMA, or WebM. Prefer WAV (16-bit PCM) when you control the recording.
File integrityVerify the file exists and is non-empty before uploading (file.size > 0 in browsers). Pass a file object, not a path string, e.g. file=open("audio.wav", "rb") in Python.

Need Saaras v4 to recognize specific names, places, brands, or technical terms? Pass a keyterms list to bias recognition. See Keyterm Prompting.


Legacy Model (Deprecated)

The model below is deprecated. Do not use it. Use Saaras v4 instead.

Saaras v2.5 (speech-to-text-translate endpoint)

Saaras v2.5 was served by the separate /speech-to-text-translate endpoint, which translates speech directly to English. It is deprecated. To translate speech to English, use Saaras v4 with mode="translate" on /speech-to-text (see the code examples above).

API Response Format

Speech to Text Transcription Response

FieldTypeDescription
request_idstringUnique identifier for the request
transcriptstringThe transcribed text from the audio file
language_codestringBCP-47 language code of the detected language (e.g., hi-IN). Returns null if no language is detected
language_probabilitynumberConfidence of the language detection, from 0 to 1
{
"request_id": "20241115_12345678-1234-5678-1234-567812345678",
"transcript": "नमस्ते, आप कैसे हैं?",
"language_code": "hi-IN",
"language_probability": 1.0
}

Speech to Text Translation Response

FieldTypeDescription
request_idstringUnique identifier for the request
transcriptstringTranslated text in English
language_codestringBCP-47 code of the detected source language
language_probabilitynumberConfidence of the language detection, from 0 to 1

Leave language_code out (or send unknown) to auto-detect the source language. See Language codes for the full list.

{
"request_id": "20241115_12345678-1234-5678-1234-567812345678",
"transcript": "Hello, how are you?",
"language_code": "hi-IN",
"language_probability": 1.0
}

Error Responses

Errors return a JSON object with an error field (message, code, request_id). The exception is a request for a deprecated model, or for a model this endpoint doesn’t support (for example a realtime-only model), which returns 400 with a {"detail": "..."} body instead. The full error-code table, retry guidance, and SDK exception reference live on the central Errors & Troubleshooting page.

Errors specific to this endpoint:

HTTP StatusError CodeWhen This HappensWhat To Do
400invalid_request_errorAudio duration exceeds the maximum limit of 30 secondsUse the Batch API, or split the audio into chunks of 30 seconds or less
400invalid_request_errorFailed to read the file, please check the audio format (empty, truncated, or corrupt file)Check the file plays locally and is non-empty
400invalid_request_errorInvalid file type: ...Send one of the supported formats and set the correct content type on the file part
400invalid_request_errorInvalid model, mode, or language_code, or keyterms used with a model other than saaras:v4 (max 50 terms, 64 characters each)Fix the parameter named in the error message
403invalid_api_key_errorMissing or invalid api-subscription-keyCheck the key in the dashboard
import os
from sarvamai import SarvamAI
from sarvamai.core.api_error import ApiError
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
try:
response = client.speech_to_text.transcribe(
file=open("audio.wav", "rb"),
model="saaras:v4",
mode="transcribe"
)
print(response.transcript)
except ApiError as e:
if e.status_code == 400:
print(f"Bad request: {e.body}")
elif e.status_code == 403:
print("Invalid API key. Check your credentials.")
elif e.status_code == 429:
print("Rate limit exceeded. Wait and retry.")
elif e.status_code == 503:
print("Service overloaded. Retry with backoff.")
else:
print(f"Error {e.status_code}: {e.body}")

Next Steps

Need help? Ask on Discord.