Text language detection returns a language name and a two-letter code. The hard part is not the call, it is knowing when the answer can be trusted. The service draws a line at 100 characters, and that line is measured rather than arbitrary.
The language detection API covers 26 languages across Latin, Cyrillic, Hebrew and Arabic scripts. Send a paragraph, get back a code, a name and the length of the text that was analysed.
curl -s "https://api2.globus.studio/v2/language?text=Your%20text%20here&format=json"
Why text language detection needs 100 characters
The detector builds a profile from character sequences and compares it against language models. A sentence or two gives the model too little to work with, so the profile stays close to several languages at once.
The threshold comes from a failure. An English sentence of 58 characters came back as Danish. The same text expanded past 100 characters came back as English. Confident wrong answers are the worst failure for a detector, so short input is rejected with Text too short for detection (min 100 chars) and the cleaned length.
If a pipeline only has a headline, collect the surrounding text first. A form field with a subject line is not enough; the message body usually is.
What the response gives you
The basic response has language, code, name and text_length. Add detailed=1 and you also get up to five alternatives, a confidence value for each and a margin to the runner-up.
text_length counts characters after punctuation and digits are removed. It is the same text the model saw, so it explains a rejection better than the raw length of the request.
Read the margin, not the confidence
confidence is an n-gram similarity index from 0 to 100, not a probability. A value of 14 on a clear English paragraph is normal: it says how much of the text matches the profile, not how likely the answer is.
margin is the readable number. The detector treats a lead under 0.5 points as ambiguous. On a full paragraph, a margin above two points is a solid answer; anything smaller deserves a second look, especially with mixed-language text.
Where text language detection fits in a pipeline
Three places work well:
- routing: sort an inbox or a support queue by language before a human opens it;
- translation QA: a page in the Russian section should come back as
ru, and that check is cheap to automate; - tagging: label an inherited corpus that has no metadata, then review the low-margin cases by hand.
In all three, the code is a first pass. The result decides the order of work, not whether work happens.
What it will not do
It does not translate, and it does not verify that the text is good in that language. A machine translation reads like the target language to a character model and still fails a reader.
It does not name a country, and it should not be treated as evidence about a person. A language belongs to the text, and the author can write in three of them.
Mixed-language pages stay unreliable: a page with English code samples inside Russian prose can land on either language depending on the balance. Test your own content before wiring the result to a hard rule.
Cost and caching
The call is fast and has no heavy dependency, so it fits in request handling. Cache the result per document hash anyway: a text that has not changed will not change language.
Do not call text language detection on every keystroke in a form. Wait until the text passes the 100-character threshold, then ask once.
Related reading
For length and complexity of the same text, see the readability score guide. For filler text in a chosen length while a layout is built, the placeholder text guide is quicker than writing it by hand.
What to log from each call
Record the code, the margin and the text length for every detection. A rise in low-margin answers usually means the incoming text changed, not the model: shorter messages, more names, more pasted code. That signal is more useful than the language itself, because it tells you where the queue will need a human. Keep the log small and delete it on a schedule: the text itself does not need to stay.
Further reading: RFC 5646, Tags for Identifying Languages.