> 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 POST https://api.sarvam.ai/transliterate Content-Type: application/json **Transliteration** converts text from one script to another while preserving the original pronunciation. For example, **'नमस्ते'** becomes **'namaste'** in English, and **'how are you'** can be written as **'हाउ आर यू'** in Devanagari. This process ensures that the sound of the original text remains intact, even when written in a different script. Transliteration is useful when you want to represent words phonetically across different writing systems, such as converting **'मैं ऑफिस जा रहा हूँ'** to **'main office ja raha hun'** in English letters. **Translation**, on the other hand, converts text from one language to another while preserving the meaning rather than pronunciation. For example, **'मैं ऑफिस जा रहा हूँ'** translates to **'I am going to the office'** in English, changing both the script and the language while conveying the intended message. ### Examples of **Transliteration**: - **'Good morning'** becomes **'गुड मॉर्निंग'** in Hindi, where the pronunciation is preserved but the meaning is not translated. - **'सुप्रभात'** becomes **'suprabhat'** in English. Available languages: - **`en-IN`**: English - **`hi-IN`**: Hindi - **`bn-IN`**: Bengali - **`gu-IN`**: Gujarati - **`kn-IN`**: Kannada - **`ml-IN`**: Malayalam - **`mr-IN`**: Marathi - **`od-IN`**: Odia - **`pa-IN`**: Punjabi - **`ta-IN`**: Tamil - **`te-IN`**: Telugu For hands-on practice, you can explore the notebook tutorial on [Transliterate API Tutorial](https://github.com/sarvamai/sarvam-ai-cookbook/blob/main/notebooks/transliterate/Transliterate_API_Tutorial.ipynb). Reference: https://docs.sarvam.ai/api-reference/text/transliterate-text ## Authentication - `api-subscription-key` header (required) — API Key authentication via header ## Request ### Body (application/json) This endpoint expects a Sarvam_Model_API_TransliterationRequest. - `input` (string, required) — The text you want to transliterate. - `source_language_code` (enum, required) — The language code of the input text. This specifies the source language for transliteration. Note: The source language should either be an Indic language or English. As we supports both Indic-to-English and English-to-Indic transliteration. - Allowed values: `auto`, `bn-IN`, `en-IN`, `gu-IN`, `hi-IN`, `kn-IN`, `ml-IN`, `mr-IN`, `od-IN`, `pa-IN`, `ta-IN`, `te-IN` - `target_language_code` (enum, required) — The language code of the transliteration text. This specifies the target language for transliteration. Note:The target language should either be an Indic language or English. As we supports both Indic-to-English and English-to-Indic transliteration. - Allowed values: `bn-IN`, `en-IN`, `gu-IN`, `hi-IN`, `kn-IN`, `ml-IN`, `mr-IN`, `od-IN`, `pa-IN`, `ta-IN`, `te-IN` - `numerals_format` (enum, optional) — `numerals_format` is an optional parameter with two options: - **`international`** (default): Uses regular numerals (0-9). - **`native`**: Uses language-specific native numerals. ### Example: - If `international` format is selected, we use regular numerals (0-9). For example: `मेरा phone number है: 9840950950`. - If `native` format is selected, we use language-specific native numerals, like: `मेरा phone number है: ९८४०९५०९५०`. - Allowed values: `international`, `native` - `spoken_form_numerals_language` (enum, optional) — `spoken_form_numerals_language` is an optional parameter with two options and only works when spoken_form is true: - **`english`** : Numbers in the text will be spoken in English. - **`native(default)`**: Numbers in the text will be spoken in the native language. ### Examples: - **Input:** "मेरे पास ₹200 है" - If `english` format is selected: "मेरे पास टू हन्डर्ड रूपीस है" - If `native` format is selected: "मेरे पास दो सौ रुपये है" - Allowed values: `english`, `native` - `spoken_form` (boolean, optional, default: false) — - Default: `False` - Converts text into a natural spoken form when `True`. - **Note:** No effect if output language is `en-IN`. ### Example: - **Input:** `मुझे कल 9:30am को appointment है` - **Output:** `मुझे कल सुबह साढ़े नौ बजे को अपॉइंटमेंट है` ## Response ### 200 Successful Response - `request_id` (string, required, nullable) - `transliterated_text` (string, required) — Transliterated text result in the requested target language. - `source_language_code` (string, required) — Detected or provided source language of the input text. ## Errors ### 400 Bad Request Error Bad Request - `error` (Sarvam_Model_API_ErrorDetails, required) — Error details ### 403 Forbidden Error Forbidden - `error` (Sarvam_Model_API_ErrorDetails, required) — Error details ### 422 Unprocessable Entity Error Unprocessable Entity - `error` (Sarvam_Model_API_ErrorDetails, required) — Error details ### 429 Too Many Requests Error Quota Exceeded - `error` (Sarvam_Model_API_ErrorDetails, required) — Error details ### 500 Internal Server Error Internal Server Error - `error` (Sarvam_Model_API_ErrorDetails, required) — Error details ## Types ### Sarvam_Model_API_ErrorDetails - `request_id` (string, required, nullable) - `message` (string, required) — Message describing the error - `code` (enum, required) — Error code for the specific error that has occurred. Refer to the error code documentation for more details. - Allowed values: `invalid_request_error`, `internal_server_error`, `unprocessable_entity_error`, `insufficient_quota_error`, `invalid_api_key_error`, `authentication_error`, `not_found_error`, `rate_limit_exceeded_error`, `model_call_error`, `gateway_timeout_error`, `billing_service_unavailable_error` ## Examples **Request** ```json { "input": "namaste", "source_language_code": "en-IN", "target_language_code": "hi-IN" } ``` **Response** ```json { "request_id": "20250101_0a1b2c3d-1234-5678-9abc-def012345678", "transliterated_text": "नमस्ते", "source_language_code": "en-IN" } ``` **SDK Code** ```python text_transliterate_example import requests url = "https://api.sarvam.ai/transliterate" payload = { "input": "namaste", "source_language_code": "en-IN", "target_language_code": "hi-IN" } headers = { "api-subscription-key": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript text_transliterate_example const url = 'https://api.sarvam.ai/transliterate'; const options = { method: 'POST', headers: { 'api-subscription-key': '', 'Content-Type': 'application/json' }, body: '{"input":"namaste","source_language_code":"en-IN","target_language_code":"hi-IN"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go text_transliterate_example package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.sarvam.ai/transliterate" payload := strings.NewReader("{\n \"input\": \"namaste\",\n \"source_language_code\": \"en-IN\",\n \"target_language_code\": \"hi-IN\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("api-subscription-key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby text_transliterate_example require 'uri' require 'net/http' url = URI("https://api.sarvam.ai/transliterate") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["api-subscription-key"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"input\": \"namaste\",\n \"source_language_code\": \"en-IN\",\n \"target_language_code\": \"hi-IN\"\n}" response = http.request(request) puts response.read_body ``` ```java text_transliterate_example import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.sarvam.ai/transliterate") .header("api-subscription-key", "") .header("Content-Type", "application/json") .body("{\n \"input\": \"namaste\",\n \"source_language_code\": \"en-IN\",\n \"target_language_code\": \"hi-IN\"\n}") .asString(); ``` ```php text_transliterate_example request('POST', 'https://api.sarvam.ai/transliterate', [ 'body' => '{ "input": "namaste", "source_language_code": "en-IN", "target_language_code": "hi-IN" }', 'headers' => [ 'Content-Type' => 'application/json', 'api-subscription-key' => '', ], ]); echo $response->getBody(); ``` ```csharp text_transliterate_example using RestSharp; var client = new RestClient("https://api.sarvam.ai/transliterate"); var request = new RestRequest(Method.POST); request.AddHeader("api-subscription-key", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"input\": \"namaste\",\n \"source_language_code\": \"en-IN\",\n \"target_language_code\": \"hi-IN\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift text_transliterate_example import Foundation let headers = [ "api-subscription-key": "", "Content-Type": "application/json" ] let parameters = [ "input": "namaste", "source_language_code": "en-IN", "target_language_code": "hi-IN" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.sarvam.ai/transliterate")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```