> For clean Markdown of any page, append `.md` to the page URL. > For a complete documentation index, see https://docs.sarvam.ai/llms.txt. > For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server. # Text Translation API > Complete overview of Sarvam AI Text Translation API supporting English to Indian languages and vice versa with multiple translation modes and high accuracy. > **Note** > > Translating a file (PDF, Word, Excel, PowerPoint, or HTML) with layout preserved? Use the [Document Translation API](/api/api-guides-tutorials/doc-translation/overview) instead of sending file text through this endpoint. #### [Document Translation](/api/api-guides-tutorials/doc-translation/overview) Upload once, translate into up to 12 languages per job, and export in the same format as the source (PDF→PDF, DOCX→DOCX). #### [Translate a PDF](/api/api-guides-tutorials/doc-translation/guides/translate-a-pdf) End-to-end walkthrough: create a job, upload your file, poll progress, and download the translated document. ## Translation Types #### English to Indic Translate from English to various Indian languages with support for different translation modes. #### Indic to English Convert Indian languages to English with high accuracy and natural output. #### Indic to Indic Translate between different Indian languages while preserving context and meaning. ## Translation Modes #### Formal Highly professional, uses pure language forms. Ideal for official documents and legal papers. #### Classic-Colloquial Balanced mix of languages, slightly informal. Perfect for business emails and general communication. #### Modern-Colloquial Casual and direct style with mixed language. Best for chatbots and social media content. #### Code-Mixed Mixes English and the target language within the same sentence, mirroring how people actually speak. Available with `mayura:v1` via `mode="code-mixed"`. ## Code Examples #### Basic Translation #### Python ```python from sarvamai import SarvamAI client = SarvamAI( api_subscription_key="YOUR_SARVAM_API_KEY" ) response = client.text.translate( input="Hello, how are you?", source_language_code="en-IN", target_language_code="hi-IN", speaker_gender="Male" ) print(response) ``` #### JavaScript ```javascript import { 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", speaker_gender: "Male" }); console.log(response); ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/translate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "Hello, how are you?", "source_language_code": "en-IN", "target_language_code": "hi-IN", "speaker_gender": "Male" }' ``` #### Advanced Options ### Advanced Translation Features Explore different parameters to customize your translation output: #### Speaker Gender Choose between Male and Female voice characteristics for gender-specific translations. #### Python ```python response = client.text.translate( input="Welcome to our service!", source_language_code="en-IN", target_language_code="hi-IN", model="mayura:v1", speaker_gender="Female" ) ``` #### JavaScript ```javascript const response = await client.text.translate({ input: "Welcome to our service!", source_language_code: "en-IN", target_language_code: "hi-IN", model: "mayura:v1", speaker_gender: "Female" }); ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/translate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "Hello, how are you?", "source_language_code": "en-IN", "target_language_code": "hi-IN", "speaker_gender": "Female" }' ``` #### Translation Mode Select the tone and style of translation - formal, modern-colloquial, classic-colloquial, or code-mixed for different use cases (`mayura:v1` only; `sarvam-translate:v1` supports formal mode only). #### Python ```python response = client.text.translate( input="Welcome to our service!", source_language_code="en-IN", target_language_code="hi-IN", model="mayura:v1", mode="modern-colloquial" ) ``` #### JavaScript ```javascript const response = await client.text.translate({ input: "Welcome to our service!", source_language_code: "en-IN", target_language_code: "hi-IN", model: "mayura:v1", mode: "modern-colloquial" }); ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/translate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "Welcome to our service!", "source_language_code": "en-IN", "target_language_code": "hi-IN", "model": "mayura:v1", "mode": "modern-colloquial" }' ``` #### Output Script Choose between different script options (roman/fully-native/spoken-form-in-native) for the translated text output. #### Python ```python response = client.text.translate( input="Welcome to our service!", source_language_code="en-IN", target_language_code="hi-IN", model="mayura:v1", output_script="fully-native" ) ``` #### JavaScript ```javascript const response = await client.text.translate({ input: "Welcome to our service!", source_language_code: "en-IN", target_language_code: "hi-IN", model: "mayura:v1", output_script: "fully-native" }); ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/translate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "Welcome to our service!", "source_language_code": "en-IN", "target_language_code": "hi-IN", "model": "mayura:v1", "output_script": "fully-native" }' ``` #### Numerals Format Specify the format for numbers in the output - choose between international (1,2,3) or native numerals (१,२,३). #### Python ```python response = client.text.translate( input="Welcome to our service!", source_language_code="en-IN", target_language_code="hi-IN", model="mayura:v1", numerals_format="native" ) ``` #### JavaScript ```javascript const response = await client.text.translate({ input: "Welcome to our service!", source_language_code: "en-IN", target_language_code: "hi-IN", model: "mayura:v1", numerals_format: "native" }); ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/translate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "Welcome to our service!", "source_language_code": "en-IN", "target_language_code": "hi-IN", "model": "mayura:v1", "numerals_format": "native" }' ``` #### All Parameters Example using all available parameters together for maximum customization. #### Python ```python response = client.text.translate( input="Welcome to our service!", source_language_code="en-IN", target_language_code="hi-IN", model="mayura:v1", speaker_gender="Female", mode="modern-colloquial", output_script="fully-native", numerals_format="native" ) ``` #### JavaScript ```javascript const response = await client.text.translate({ input: "Welcome to our service!", source_language_code: "en-IN", target_language_code: "hi-IN", model: "mayura:v1", speaker_gender: "Female", mode: "modern-colloquial", output_script: "fully-native", numerals_format: "native" }); ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/translate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "Welcome to Sarvam AI!", "source_language_code": "en-IN", "target_language_code": "hi-IN", "model": "mayura:v1", "speaker_gender": "Female", "mode": "modern-colloquial", "output_script": "fully-native", "numerals_format": "native" }' ``` ## API Features #### Translation Options * Multiple Indian languages support * Four translation modes * Gender-specific translations * Code-mixed text support #### Output Formats * Multiple script options * Native/International numerals * Customizable formatting * Transliteration support #### Advanced Features * Automatic language detection * Context preservation * Entity handling ## API Response Format | Field | Type | Description | | ---------------------- | ------ | ---------------------------------------------------- | | `request_id` | string | Unique identifier for the request | | `translated_text` | string | Translated text in the target language | | `source_language_code` | string | Detected or provided source language (BCP-47 format) | **Supported languages:** * **mayura:v1:** `bn-IN`, `en-IN`, `gu-IN`, `hi-IN`, `kn-IN`, `ml-IN`, `mr-IN`, `od-IN`, `pa-IN`, `ta-IN`, `te-IN` * **sarvam-translate:v1:** All mayura languages + `as-IN`, `brx-IN`, `doi-IN`, `kok-IN`, `ks-IN`, `mai-IN`, `mni-IN`, `ne-IN`, `sa-IN`, `sat-IN`, `sd-IN`, `ur-IN` ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "translated_text": "नमस्ते, आप कैसे हैं?", "source_language_code": "en-IN" } ``` #### More Response Examples **With Roman Script Output:** ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "translated_text": "namaste, aap kaise hain?", "source_language_code": "en-IN" } ``` **With Native Numerals:** ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "translated_text": "मेरा फोन नंबर है ९८४०९५०९५०", "source_language_code": "en-IN" } ``` **Auto-Detected Source Language:** ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "translated_text": "Hello, how are you?", "source_language_code": "hi-IN" } ``` ## Error Responses All errors return a JSON object with an `error` field (`message`, `code`, `request_id`). The full error-code table, retry guidance, and SDK exception reference live on the central [Errors & Troubleshooting](/api/getting-started/errors-troubleshooting) page. Errors specific to this endpoint: | HTTP Status | Error Code | When This Happens | What To Do | | ----------- | ---------------------------- | ------------------------------------------------ | -------------------------------------------------------------------------- | | `400` | `invalid_request_error` | Missing required parameters or malformed request | Check `input`, `source_language_code`, `target_language_code` | | `422` | `unprocessable_entity_error` | Text too long or unsupported language pair | Keep text under 1000 chars (mayura:v1) or 2000 chars (sarvam-translate:v1) | #### Error Handling Code Example ```python from sarvamai import SarvamAI from sarvamai.core.api_error import ApiError client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY") try: response = client.text.translate( input="Hello, how are you?", source_language_code="en-IN", target_language_code="hi-IN" ) print(response.translated_text) 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 == 422: print(f"Invalid parameters: {e.body}") elif e.status_code == 429: print("Rate limit exceeded. Wait and retry.") else: print(f"Error {e.status_code}: {e.body}") ``` > **Note** > > Check out our detailed [API Reference](/api-reference/text/translate-text) > to explore Translation and all available options. > **Note** > > Need help with translation? Contact us on > [discord](https://discord.com/invite/5rAsykttcs) for guidance. > Complete overview of Sarvam AI Text Translation API supporting English to Indian languages and vice versa with multiple translation modes and high accuracy.