POST /detect-language
Summary
Detects the natural language of a given text input and returns the identified language code.
Intent
Enables applications to automatically identify the language of user-submitted text without requiring the caller to know the language in advance, supporting multilingual workflows such as routing, translation, and content classification.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | The text content whose language should be detected. Should be a meaningful sample of text; very short or ambiguous strings may reduce detection accuracy. |
Request example
import requests
response = requests.post( "https://api.example.com/detect-language", json={ "text": "Bonjour, comment allez-vous aujourd'hui?" })
result = response.json()print(result["language"]) # e.g., "fr"print(result["confidence"]) # e.g., 0.99Response example
{ "language": "fr", "language_name": "French", "confidence": 0.99, "alternatives": [ { "language": "it", "confidence": 0.005 }, { "language": "es", "confidence": 0.003 } ]}Error cases
400— when the request body is missing the required ‘text’ field or the field is empty422— when the text is too short or contains only symbols/numbers and language cannot be reliably determined500— when an internal error occurs during language detection processing
Gotchas
- Very short strings (fewer than ~10 characters) or strings composed entirely of numbers, punctuation, or emojis may return low confidence scores or fail detection entirely.
- Mixed-language text (code-switching) will typically return only the dominant language detected, not all languages present.
- The endpoint does not require authentication, but may still be subject to rate limiting based on IP address or API key if one is provided.
- Language codes returned follow ISO 639-1 (two-letter) format by default; verify this matches your downstream system’s expectations.
- Confidence scores close to each other across multiple alternatives indicate ambiguous input — treat results with low confidence as unreliable.
- Sending personally identifiable information (PII) in the text field may have privacy implications depending on how the service processes and logs requests.