> 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. # Language Identification API > Identifies the language and script of input text, supporting multiple Indian languages. Automatic detection with confidence scores for multilingual text processing. ## Overview The Language Identification (LID) API identifies the language (e.g., en-IN, hi-IN) and script (e.g., Latin, Devanagari) of the input text. It supports multiple Indian languages and scripts, making it ideal for multilingual text processing. ## Detection Types #### Single Language Detect the primary language and script of text input. Example: "Hello, how are you?" → language: en-IN, script: Latn #### Auto Detection Automatic language detection for seamless integration with translation and preprocessing APIs. ## Code Examples #### Python ```python from sarvamai import SarvamAI client = SarvamAI( api_subscription_key="YOUR_SARVAM_API_KEY" ) response = client.text.identify_language( input="Hello, how are you?" ) print(f"Request ID: {response.request_id}") print(f"Language Code: {response.language_code}") # Output: en-IN print(f"Script Code: {response.script_code}") # Output: Latn ``` #### JavaScript ```javascript import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" }); const response = await client.text.identifyLanguage({ input: "Hello, how are you?" }); console.log(`Request ID: ${response.request_id}`); console.log(`Language Code: ${response.language_code}`); // Output: en-IN console.log(`Script Code: ${response.script_code}`); // Output: Latn ``` #### cURL ```bash curl -X POST https://api.sarvam.ai/text-lid \ -H "api-subscription-key: " \ -H "Content-Type: application/json" \ -d '{ "input": "Hello, how are you?" }' # Response: # { # "request_id": "abc123", # "language_code": "en-IN", # "script_code": "Latn" # } ``` ## Response Format ```json { "request_id": "string | null", "language_code": "string | null", "script_code": "string | null" } ``` ## Supported Languages and Scripts #### Language Support **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 #### Script Support **Available Scripts:** * Latn: Latin (Romanized script) * Deva: Devanagari (Hindi, Marathi) * Beng: Bengali * Gujr: Gujarati * Knda: Kannada * Mlym: Malayalam * Orya: Odia * Guru: Gurmukhi * Taml: Tamil * Telu: Telugu ## API Response Format | Field | Type | Description | | --------------- | ------ | ----------------------------------------------------------- | | `request_id` | string | Unique identifier for the request | | `language_code` | string | Detected language in BCP-47 format (e.g., `hi-IN`, `ta-IN`) | | `script_code` | string | Detected script code (e.g., `Deva`, `Latn`, `Taml`) | **Supported languages:** `en-IN`, `hi-IN`, `bn-IN`, `gu-IN`, `kn-IN`, `ml-IN`, `mr-IN`, `od-IN`, `pa-IN`, `ta-IN`, `te-IN` ```json { "request_id": "20241115_12345678-1234-5678-1234-567812345678", "language_code": "hi-IN", "script_code": "Deva" } ``` ### Script Codes Reference | Script Code | Script Name | Used By | | ----------- | ----------- | -------------- | | `Latn` | Latin | English | | `Deva` | Devanagari | Hindi, Marathi | | `Beng` | Bengali | Bengali | | `Gujr` | Gujarati | Gujarati | | `Knda` | Kannada | Kannada | | `Mlym` | Malayalam | Malayalam | | `Orya` | Odia | Odia | | `Guru` | Gurmukhi | Punjabi | | `Taml` | Tamil | Tamil | | `Telu` | Telugu | Telugu | ## 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 `input` parameter | Include the `input` field with text to identify | | `422` | `unprocessable_entity_error` | Text too long (max 1000 characters) | Split text into smaller chunks | #### 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.identify_language( input="Hello, how are you?" ) print(f"Language: {response.language_code}") print(f"Script: {response.script_code}") 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/identify-language) > to explore Language Identification and all available options. > **Note** > > For detailed pricing information and usage tiers, visit our [pricing page](https://dashboard.sarvam.ai/pricing). > Identifies the language and script of input text, supporting multiple Indian languages. Automatic detection with confidence scores for multilingual text processing.