Language detection sounds simple until you try to build it yourself: ML models need a Python runtime or GPU, cloud translation APIs charge per character and require billing setup, and browser-side heuristics break on short strings or multilingual input.
One POST detects the language of any text across 187 languages — no ML server, no third-party API key, no outbound calls from the server:
curl --request POST \
--url 'https://language-detection-api7.p.rapidapi.com/api/v1/detect' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
--header 'x-rapidapi-host: language-detection-api7.p.rapidapi.com' \
--header 'content-type: application/json' \
--data '{"text":"Bonjour, comment allez-vous?"}'
Returns language (ISO 639-1 code), languageName, confidence, and an alternatives array for ambiguous input — helpful when text is short or code-mixed.
const { language, languageName, confidence } = await fetch(
'https://language-detection-api7.p.rapidapi.com/api/v1/detect',
{
method: 'POST',
headers: {
'content-type': 'application/json',
'x-rapidapi-key': process.env.RAPIDAPI_KEY,
'x-rapidapi-host': 'language-detection-api7.p.rapidapi.com',
},
body: JSON.stringify({ text: userInput }),
}
).then(r => r.json());
if (language === 'de') serveGermanContent();
Need to classify a list of strings? POST /api/v1/detect/batch accepts up to 20 texts in one call. GET /api/v1/languages returns all 187 supported languages with ISO codes — useful for building a language picker. Powered by franc (MIT licence), a pure statistical n-gram model; no GPU, no Python, no billing surprises.
Free tier on RapidAPI: https://rapidapi.com/danieligel/api/language-detection-api7
Do you detect user language from Accept-Language headers, text content, or a combination of both?
Top comments (0)