> 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. # Transliteration API > Complete overview of Sarvam AI Transliteration API for script conversion between Indian languages. Convert between Roman, Devanagari, and other scripts with high accuracy. ## Transliteration Types #### Romanization Convert Indic scripts to Roman script (English alphabet). Example: मैं ऑफिस → main office #### Indic Script Conversion Convert code-mixed, romanized, or English text to Indic scripts. Example: main office → मैं ऑफिस #### Spoken Form Convert written text to natural spoken form. Example: 9:30am → सुबह साढ़े नौ बजे ## Code Examples #### Basic Usage #### Python ```python from sarvamai import SarvamAI client = SarvamAI( api_subscription_key="YOUR_SARVAM_API_KEY" ) try: response = client.text.transliterate( input="मैं ऑफिस जा रहा हूँ", source_language_code="hi-IN", target_language_code="en-IN", spoken_form=True ) print(response) except Exception as e: print(f"Error: {e}") ``` #### JavaScript ```javascript import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" }); try { const response = await client.text.transliterate({ input: "मैं ऑफिस जा रहा हूँ", source_language_code: "hi-IN", target_language_code: "en-IN", spoken_form: true }); console.log(response); } catch (error) { console.error("Error:", error); } ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/transliterate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "मैं ऑफिस जा रहा हूँ", "source_language_code": "hi-IN", "target_language_code": "en-IN", "spoken_form": true }' ``` #### Advanced Options ### Advanced Transliteration Features Explore different parameters to customize your transliteration output: #### Numerals Format Choose between international (0-9) or native numerals (e.g., ०-९) for number representation in the output text. #### Python ```python from sarvamai import SarvamAI client = SarvamAI( api_subscription_key="YOUR_SARVAM_API_KEY" ) try: response = client.text.transliterate( input="मेरा phone number है 9840950950", source_language_code="hi-IN", target_language_code="hi-IN", numerals_format="native" ) print(response.transliterated_text) except Exception as e: print(f"Error: {e}") ``` #### JavaScript ```javascript import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" }); try { const response = await client.text.transliterate({ input: "मेरा phone number है 9840950950", source_language_code: "hi-IN", target_language_code: "hi-IN", numerals_format: "native" }); console.log(response.transliterated_text); } catch (error) { console.error("Error:", error); } ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/transliterate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "मैं ऑफिस जा रहा हूँ", "source_language_code": "hi-IN", "target_language_code": "en-IN", "numerals_format": "native" }' ``` #### Spoken Form Convert text into natural spoken form. Note: This has no effect if output language is en-IN. #### Python ```python from sarvamai import SarvamAI client = SarvamAI( api_subscription_key="YOUR_SARVAM_API_KEY" ) try: response = client.text.transliterate( input="मेरे पास ₹200 है", source_language_code="hi-IN", target_language_code="hi-IN", spoken_form=True ) print(response.transliterated_text) except Exception as e: print(f"Error: {e}") ``` #### JavaScript ```javascript import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" }); try { const response = await client.text.transliterate({ input: "मेरे पास ₹200 है", source_language_code: "hi-IN", target_language_code: "hi-IN", spoken_form: true }); console.log(response.transliterated_text); } catch (error) { console.error("Error:", error); } ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/transliterate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "मेरे पास ₹200 है", "source_language_code": "hi-IN", "target_language_code": "hi-IN", "spoken_form": true }' ``` #### Spoken Form Numerals Choose between English or native language for number pronunciation when spoken\_form is enabled. #### Python ```python from sarvamai import SarvamAI client = SarvamAI( api_subscription_key="YOUR_SARVAM_API_KEY" ) try: response = client.text.transliterate( input="मेरे पास ₹200 है", source_language_code="hi-IN", target_language_code="hi-IN", spoken_form=True ) print(response.transliterated_text) except Exception as e: print(f"Error: {e}") ``` #### JavaScript ```javascript import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" }); try { const response = await client.text.transliterate({ input: "मेरे पास ₹200 है", source_language_code: "hi-IN", target_language_code: "hi-IN", spoken_form: true, spoken_form_numerals_language: "english" }); console.log(response.transliterated_text); } catch (error) { console.error("Error:", error); } ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/transliterate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "मेरे पास ₹200 है", "source_language_code": "hi-IN", "target_language_code": "hi-IN", "spoken_form": true }' ``` #### All Parameters Example using all available parameters together for maximum customization. #### Python ```python from sarvamai import SarvamAI client = SarvamAI( api_subscription_key="YOUR_SARVAM_API_KEY" ) try: response = client.text.transliterate( input="मेरे पास ₹200 है और time है 9:30am", source_language_code="hi-IN", target_language_code="hi-IN", spoken_form=True, numerals_format="native", spoken_form_numerals_language="native" ) print(response.transliterated_text) except Exception as e: print(f"Error: {e}") ``` #### JavaScript ```javascript import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" }); try { const response = await client.text.transliterate({ input: "मेरे पास ₹200 है और time है 9:30am", source_language_code: "hi-IN", target_language_code: "hi-IN", spoken_form: true, numerals_format: "native", spoken_form_numerals_language: "native" }); console.log(response.transliterated_text); } catch (error) { console.error("Error:", error); } ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/transliterate \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "मेरे पास ₹200 है और time है 9:30am", "source_language_code": "hi-IN", "target_language_code": "hi-IN", "spoken_form": true, "numerals_format": "native", "spoken_form_numerals_language": "native" }' ``` ## API Features #### Input Options * Multiple Indic languages * Code-mixed text support * Romanized text input * English text input #### Output Formats * Roman script (English) * Native script conversion * Spoken form output * Natural number formats #### Number Handling * International numerals (0-9) * Native numerals (१-९) * English number words * Native number words ## API Response Format | Field | Type | Description | | ---------------------- | ------ | ---------------------------------------------------- | | `request_id` | string | Unique identifier for the request | | `transliterated_text` | string | Text converted to target script | | `source_language_code` | string | Detected or provided source language (BCP-47 format) | **Supported languages:** `bn-IN`, `en-IN`, `gu-IN`, `hi-IN`, `kn-IN`, `ml-IN`, `mr-IN`, `od-IN`, `pa-IN`, `ta-IN`, `te-IN` ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "transliterated_text": "main office ja raha hun", "source_language_code": "hi-IN" } ``` #### More Response Examples **Indic Script Conversion (English to Indic):** ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "transliterated_text": "मैं ऑफिस जा रहा हूँ", "source_language_code": "en-IN" } ``` **With Spoken Form Numerals:** ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "transliterated_text": "मुझे कल सुबह साढ़े नौ बजे को अपॉइंटमेंट है", "source_language_code": "hi-IN" } ``` **With Native Numerals:** ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "transliterated_text": "मेरा फोन नंबर है: ९८४०९५०९५०", "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 | Keep text under 1000 characters | #### 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.transliterate( input="मैं ऑफिस जा रहा हूँ", source_language_code="hi-IN", target_language_code="en-IN" ) print(response.transliterated_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/transliterate-text) > to explore Transliteration and all available options. > **Note** > > Need help with transliteration? Contact us on > [discord](https://discord.com/invite/5rAsykttcs) for guidance. > Complete overview of Sarvam AI Transliteration API for script conversion between Indian languages. Convert between Roman, Devanagari, and other scripts with high accuracy.