Transliteration API

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

1from sarvamai import SarvamAI
2
3client = SarvamAI(
4 api_subscription_key="YOUR_SARVAM_API_KEY"
5)
6
7response = client.text.transliterate(
8 input="मैं ऑफिस जा रहा हूँ",
9 source_language_code="hi-IN",
10 target_language_code="en-IN",
11 spoken_form=True
12)
13
14print(response)

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

FieldTypeDescription
request_idstringUnique identifier for the request
transliterated_textstringText converted to target script
source_language_codestringDetected 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

1{
2 "request_id": "20241115_12345678-1234-5678-1234-567812345678",
3 "transliterated_text": "main office ja raha hun",
4 "source_language_code": "hi-IN"
5}

Indic Script Conversion (English to Indic):

1{
2 "request_id": "20241115_12345678-1234-5678-1234-567812345678",
3 "transliterated_text": "मैं ऑफिस जा रहा हूँ",
4 "source_language_code": "en-IN"
5}

With Spoken Form Numerals:

1{
2 "request_id": "20241115_12345678-1234-5678-1234-567812345678",
3 "transliterated_text": "मुझे कल सुबह साढ़े नौ बजे को अपॉइंटमेंट है",
4 "source_language_code": "hi-IN"
5}

With Native Numerals:

1{
2 "request_id": "20241115_12345678-1234-5678-1234-567812345678",
3 "transliterated_text": "मेरा फोन नंबर है: ९८४०९५०९५०",
4 "source_language_code": "hi-IN"
5}

Error Responses

All errors return a JSON object with an error field containing details about what went wrong.

Error Response Structure

1{
2 "error": {
3 "message": "Human-readable error description",
4 "code": "error_code_for_programmatic_handling",
5 "request_id": "unique_request_identifier"
6 }
7}

Error Codes Reference

HTTP StatusError CodeWhen This HappensWhat To Do
400invalid_request_errorMissing required parameters or malformed requestCheck input, source_language_code, target_language_code
403invalid_api_key_errorAPI key is invalid, missing, or expiredVerify your API key in the dashboard
422unprocessable_entity_errorText too long or unsupported languageKeep text under 1000 characters
429insufficient_quota_errorAPI quota or rate limit exceededWait for reset or upgrade your plan
500internal_server_errorUnexpected server errorRetry the request; contact support if persistent

Example Error Response

1{
2 "error": {
3 "message": "Input text exceeds maximum length of 1000 characters",
4 "code": "unprocessable_entity_error",
5 "request_id": "20241115_abc12345"
6 }
7}
1from sarvamai import SarvamAI
2from sarvamai.core.api_error import ApiError
3
4client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
5
6try:
7 response = client.text.transliterate(
8 input="मैं ऑफिस जा रहा हूँ",
9 source_language_code="hi-IN",
10 target_language_code="en-IN"
11 )
12 print(response.transliterated_text)
13except ApiError as e:
14 if e.status_code == 400:
15 print(f"Bad request: {e.body}")
16 elif e.status_code == 403:
17 print("Invalid API key. Check your credentials.")
18 elif e.status_code == 422:
19 print(f"Invalid parameters: {e.body}")
20 elif e.status_code == 429:
21 print("Rate limit exceeded. Wait and retry.")
22 else:
23 print(f"Error {e.status_code}: {e.body}")

Check out our detailed API Reference to explore Transliteration and all available options.

Need help with transliteration? Contact us on discord for guidance.