Identify the language of text using Gherbal, Sawalni's fastText-based language identification model. Supports 200+ languages with ISO 639-3 + script codes.
POST https://api.sawalni.com/v1/language/identify
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | gherbal-v4 |
input | string or array | Yes | Text(s) to identify |
top | integer | No | Number of predictions per text. Default: 1. Use -1 for all. |
curl https://api.sawalni.com/v1/language/identify \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gherbal-v4", "input": "مرحبا بالعالم", "top": 3 }'
import requests response = requests.post( "https://api.sawalni.com/v1/language/identify", headers={"Authorization": "Bearer YOUR_API_KEY"}, json={ "model": "gherbal-v4", "input": ["مرحبا بالعالم", "Hello world", "Bonjour le monde"], "top": 3 } ) for item in response.json()["data"]: top = item["predictions"][0] print(f"{item['input']} → {top['language']} ({top['confidence']:.2%})")
const response = await fetch('https://api.sawalni.com/v1/language/identify', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'gherbal-v4', input: ['مرحبا', 'Hello', 'Bonjour'], top: 3 }) }); const result = await response.json(); result.data.forEach(item => { console.log(item.input, '→', item.predictions[0].language); });
{ "data": [ { "input": "مرحبا بالعالم", "predictions": [ { "language": "arb_Arab", "confidence": 0.987 }, { "language": "arz_Arab", "confidence": 0.008 }, { "language": "acm_Arab", "confidence": 0.003 } ] } ], "model": "gherbal-v4", "usage": { "input_bytes": 25, "input_count": 1, "processing_ms": 2.1 } }
Labels follow the ISO 639-3 + Unicode script format: {iso639-3}_{script}
Examples: arb_Arab (Modern Standard Arabic), eng_Latn (English), fra_Latn (French), deu_Latn (German), zho_Hans (Chinese Simplified)
Pass an array of strings to identify multiple texts in one request (max 1024):
response = requests.post( "https://api.sawalni.com/v1/language/identify", headers={"Authorization": "Bearer YOUR_API_KEY"}, json={ "model": "gherbal-v4", "input": ["First text", "Second text", "Third text"], "top": 1 } )
top Parameter| Value | Behavior |
|---|---|
1 | Returns only the most likely language (default) |
3 | Returns top 3 predictions |
10 | Returns top 10 predictions |
-1 | Returns all supported languages ranked by confidence |
| Model | Description |
|---|---|
gherbal-v4 | Language identification for 200+ languages |
Language identification is metered by input bytes (UTF-8 encoded size).
| Metric | Rate |
|---|---|
| Input bytes | 0.05 credits per 1M bytes |