Sawalni API
APIsDocumentationOpen portal ↗
Omneity Labs API collection ↗Integration quickstart →API keys and playgrounds →
API Reference

Language Identification API

Identify the language of text using Gherbal, Sawalni's fastText-based language identification model. Supports 200+ languages with ISO 639-3 + script codes.

Endpoint

text
POST https://api.sawalni.com/v1/language/identify

Request Body

ParameterTypeRequiredDescription
modelstringYesgherbal-v4
inputstring or arrayYesText(s) to identify
topintegerNoNumber of predictions per text. Default: 1. Use -1 for all.

Example — curl

bash
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 }'

Example — Python

python
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%})")

Example — JavaScript

javascript
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); });

Response

json
{ "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 } }

Language Code Format

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)

Batch Identification

Pass an array of strings to identify multiple texts in one request (max 1024):

python
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 } )

The top Parameter

ValueBehavior
1Returns only the most likely language (default)
3Returns top 3 predictions
10Returns top 10 predictions
-1Returns all supported languages ranked by confidence

Models

ModelDescription
gherbal-v4Language identification for 200+ languages

Pricing

Language identification is metered by input bytes (UTF-8 encoded size).

MetricRate
Input bytes0.05 credits per 1M bytes

Use Cases

  • Content routing — Route user messages to language-specific pipelines
  • Data quality — Filter datasets by language
  • Multilingual UX — Auto-detect user's language for localization
  • Moderation — Identify language before applying language-specific filters