Text Translation — Sarvam AI
Live in-chat translate/localize → sarvam-mcp (
sarvam_tools_translate/_localize). This skill = SDK code.
Translating whole documents (PDF, DOCX, XLSX, PPTX, HTML)? → document-translation — that is a separate async API, not
client.text.translate().
[!IMPORTANT] Auth:
api-subscription-keyheader — NOTAuthorization: Bearer. Base URL:https://api.sarvam.ai(NOT/v1— that prefix is only for the OpenAI-compatible chat endpoint)
Models
| Model | Max Input | Languages | Features |
|---|---|---|---|
sarvam-translate:v1 | 2,000 chars | 23 (22 Indian + English) | mode (formal only), speaker_gender, numerals_format |
mayura:v1 | 1,000 chars | 11 (10 Indian + English) | All mode values, output_script, speaker_gender, numerals_format, auto source detection |
Quick Start (Python)
pythonfrom sarvamai import SarvamAI client = SarvamAI() response = client.text.translate( input="Hello, how are you?", source_language_code="en-IN", target_language_code="hi-IN", model="sarvam-translate:v1" ) print(response.translated_text)
Quick Start (JavaScript/TypeScript)
typescriptimport { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" }); const response = await client.text.translate({ input: "Hello, how are you?", source_language_code: "en-IN", target_language_code: "hi-IN", model: "sarvam-translate:v1" }); console.log(response.translated_text);
Gotchas
| Gotcha | Detail |
|---|---|
| Method name | Both Python & JS: client.text.translate({...}) — NOT client.translate.translate(). Same text namespace in both SDKs. |
output_script on sarvam-translate | NOT supported — only works with mayura:v1 (roman, fully-native, spoken-form-in-native). Verified live: sending it to sarvam-translate:v1 now returns 400 invalid_request_error — "Transliteration is not supported in sarvam-translate:v1. Please use mayura:v1 for transliteration support or remove the output_script parameter." — it's a hard error today, not a silent ignore (check your assumptions if you're on an older API/docs snapshot that said otherwise). |
mode values | sarvam-translate:v1 supports formal only. Colloquial modes (modern-colloquial, classic-colloquial, code-mixed) are mayura:v1 only. speaker_gender works on BOTH models. |
| Auto language detection | source_language_code="auto" only works with mayura:v1. sarvam-translate:v1 requires an explicit source language. |
| Odia language code | od-IN — NOT or-IN. |
| Character limits | Exceeding returns 422. Split long text at sentence boundaries. |
Full Docs
Fetch language codes, mode examples, script options, and numeral formats from:
- https://docs.sarvam.ai/llms.txt — comprehensive docs index
- Translation Guide
- Rate Limits


