> 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

Detect the primary language and script of text input. Example: "Hello, how are you?" → language: en-IN, script: Latn

Automatic language detection for seamless integration with translation and preprocessing APIs.

## Code Examples

```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
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
```

```bash
curl -X POST https://api.sarvam.ai/text-lid \
  -H "api-subscription-key: <YOUR_SARVAM_API_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

<strong>
  Available Languages:
</strong>

<ul>
  <li>
    en-IN: English
  </li>

  <li>
    hi-IN: Hindi
  </li>

  <li>
    bn-IN: Bengali
  </li>

  <li>
    gu-IN: Gujarati
  </li>

  <li>
    kn-IN: Kannada
  </li>

  <li>
    ml-IN: Malayalam
  </li>

  <li>
    mr-IN: Marathi
  </li>

  <li>
    od-IN: Odia
  </li>

  <li>
    pa-IN: Punjabi
  </li>

  <li>
    ta-IN: Tamil
  </li>

  <li>
    te-IN: Telugu
  </li>
</ul>

<strong>
  Available Scripts:
</strong>

<ul>
  <li>
    Latn: Latin (Romanized script)
  </li>

  <li>
    Deva: Devanagari (Hindi, Marathi)
  </li>

  <li>
    Beng: Bengali
  </li>

  <li>
    Gujr: Gujarati
  </li>

  <li>
    Knda: Kannada
  </li>

  <li>
    Mlym: Malayalam
  </li>

  <li>
    Orya: Odia
  </li>

  <li>
    Guru: Gurmukhi
  </li>

  <li>
    Taml: Tamil
  </li>

  <li>
    Telu: Telugu
  </li>
</ul>

## 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 containing details about what went wrong.

### Error Response Structure

```json
{
  "error": {
    "message": "Human-readable error description",
    "code": "error_code_for_programmatic_handling",
    "request_id": "unique_request_identifier"
  }
}
```

### Error Codes Reference

| 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  |
| `403`       | `invalid_api_key_error`      | API key is invalid, missing, or expired | Verify your API key in the dashboard             |
| `422`       | `unprocessable_entity_error` | Text too long (max 1000 characters)     | Split text into smaller chunks                   |
| `429`       | `insufficient_quota_error`   | API quota or rate limit exceeded        | Wait for reset or upgrade your plan              |
| `500`       | `internal_server_error`      | Unexpected server error                 | Retry the request; contact support if persistent |

### Example Error Response

```json
{
  "error": {
    "message": "Input text exceeds maximum length of 1000 characters",
    "code": "unprocessable_entity_error",
    "request_id": "20241115_abc12345"
  }
}
```

```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}")
```

Check out our detailed [API Reference](/api-reference-docs/text/identify-language)
to explore Language Identification and all available options.

For detailed pricing information and usage tiers, visit our [pricing
page](https://dashboard.sarvam.ai/pricing).