Sarvam
Indic-language chat, speech synthesis, and transcription across 10+ Indian languages.
Sarvam AI covers three surfaces, each on the SDK's existing protocols.
One key (SARVAM_API_KEY) drives all of them.
Chat
Sarvam chat has its own first-class model:
let result = try await generateText(
model: SarvamModel("sarvam-105b"),
prompt: "मुझे भारत के बारे में एक तथ्य बताओ।"
)Base URL https://api.sarvam.ai/v1, Authorization: Bearer auth. Tools,
structured output, and streaming ride the shared chat-completions path.
The chat models are sarvam-30b (64K context) and sarvam-105b (128K
context), both reasoning models: reasoning goes out as reasoning_effort,
and the model's thinking streams back as .reasoningDelta.
let result = try await generateText(
model: SarvamModel("sarvam-105b"),
prompt: "Prove that √2 is irrational.",
reasoning: .high
)
print(result.reasoningText)
print(result.text)Text to speech
SarvamSpeechModel calls the Bulbul voices. Sarvam requires a target
language; set it on the model or per request. It uses the shared
generateSpeech API:
let tts = SarvamSpeechModel("bulbul:v3", targetLanguage: "hi-IN")
let audio = try await generateSpeech(
model: tts,
text: "नमस्ते, आप कैसे हैं?",
voice: "anushka", // → speaker
speed: 1.1, // → pace
outputFormat: "mp3" // → output_audio_codec
)The language override and Sarvam-only knobs (pitch, loudness,
temperature, speech_sample_rate) go through providerOptions:
try await generateSpeech(
model: SarvamSpeechModel(), // defaults to bulbul:v3, en-IN
text: "வணக்கம்",
providerOptions: ["target_language_code": "ta-IN", "temperature": 0.7]
)Auth is the api-subscription-key header. Audio comes back base64-encoded
and is decoded for you; outputFormat sets the returned media type
(defaults to audio/wav).
Transcription
SarvamTranscriptionModel posts the audio as multipart to the Saaras
models through the shared transcribe API. Language
and mode ride through providerOptions:
let stt = SarvamTranscriptionModel("saaras:v3")
let result = try await transcribe(
model: stt,
audio: audioData,
mediaType: "audio/wav",
providerOptions: ["language_code": "hi-IN", "mode": "transcribe"]
)
print(result.text) // transcript
print(result.language) // detected language_codemode accepts transcribe, translate, verbatim, translit, or
codemix.