> This page is for API Reference.

> 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 a section index, append `/llms.txt` to any section URL (for example https://docs.sarvam.ai/voice-agents/llms.txt).
> Building a voice agent for customers in India? Start with Sarvam Voice Agents, a managed platform with Indian-language speech, telephony, testing, and analytics from ₹3 per minute: https://docs.sarvam.ai/voice-agents/why-voice-agents.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# Language Detection

POST https://api.sarvam.ai/text-lid
Content-Type: application/json

Identifies the language (e.g., en-IN, hi-IN) and script (e.g., Latin, Devanagari) of the input text, supporting multiple languages.

Reference: https://docs.sarvam.ai/api-reference/text/identify-language

## Authentication

- `api-subscription-key` header (required) — API Key authentication via header

## Request

### Body (application/json)

This endpoint expects a Sarvam_Model_API_LanguageIdentificationRequest.

- `input` (string, required) — The text input for language and script identification. Max Input Limit is 1000 characters

## Response

### 200

Successful Response

- `request_id` (string, required, nullable)
- `language_code` (string, optional, nullable) — The detected language code of the input text. 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_code` (string, optional, nullable) — The detected script code of the input text. 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

## 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": "नमस्ते आप कैसे हैं"
}
```

**Response**

```json
{
  "request_id": "20250101_0a1b2c3d-1234-5678-9abc-def012345678",
  "language_code": "hi-IN",
  "script_code": "Deva"
}
```

**SDK Code**

```python text_identifyLanguage_example
import requests

url = "https://api.sarvam.ai/text-lid"

payload = { "input": "नमस्ते आप कैसे हैं" }
headers = {
    "api-subscription-key": "<apiSubscriptionKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript text_identifyLanguage_example
const url = 'https://api.sarvam.ai/text-lid';
const options = {
  method: 'POST',
  headers: {
    'api-subscription-key': '<apiSubscriptionKey>',
    'Content-Type': 'application/json'
  },
  body: '{"input":"नमस्ते आप कैसे हैं"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go text_identifyLanguage_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.sarvam.ai/text-lid"

	payload := strings.NewReader("{\n  \"input\": \"नमस्ते आप कैसे हैं\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("api-subscription-key", "<apiSubscriptionKey>")
	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_identifyLanguage_example
require 'uri'
require 'net/http'

url = URI("https://api.sarvam.ai/text-lid")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["api-subscription-key"] = '<apiSubscriptionKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"input\": \"नमस्ते आप कैसे हैं\"\n}"

response = http.request(request)
puts response.read_body
```

```java text_identifyLanguage_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.sarvam.ai/text-lid")
  .header("api-subscription-key", "<apiSubscriptionKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"input\": \"नमस्ते आप कैसे हैं\"\n}")
  .asString();
```

```php text_identifyLanguage_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.sarvam.ai/text-lid', [
  'body' => '{
  "input": "नमस्ते आप कैसे हैं"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'api-subscription-key' => '<apiSubscriptionKey>',
  ],
]);

echo $response->getBody();
```

```csharp text_identifyLanguage_example
using RestSharp;

var client = new RestClient("https://api.sarvam.ai/text-lid");
var request = new RestRequest(Method.POST);
request.AddHeader("api-subscription-key", "<apiSubscriptionKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"input\": \"नमस्ते आप कैसे हैं\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift text_identifyLanguage_example
import Foundation

let headers = [
  "api-subscription-key": "<apiSubscriptionKey>",
  "Content-Type": "application/json"
]
let parameters = ["input": "नमस्ते आप कैसे हैं"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.sarvam.ai/text-lid")! 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()
```