Skip to content

Detect language

Identifies the language of one string. This route does not translate and does not accept the translate options.

POSThttps://edge.harktranslate.com/api/v1/translator/detect-language

Request

Send JSON (Content-Type: application/json). Form-encoded bodies are also accepted. Authenticate with the x-hark-key header.

Request fields
FieldTypeRequiredDefaultAllowedDescription
textstringyesnone1 to 1,037,299 characters.The string to translate, or the text whose language should be identified.

Response

Success is HTTP 200.

Response fields
FieldTypeDescription
trust_levelnumberHow confident detection was.
source_lang_codestringDetected language code.
source_langstringDetected language name.
{
  "trust_level": 1,
  "source_lang_code": "fr",
  "source_lang": "French"
}

Samples

Replace YOUR_API_KEY or set HARK_API_KEY. The samples call https://edge.harktranslate.com/api/v1/translator.

Detect

curl
curl -X POST "https://edge.harktranslate.com/api/v1/translator/detect-language" \
  -H "x-hark-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{
  "text": "Bonjour"
}
JSON
JavaScript
const response = await fetch("https://edge.harktranslate.com/api/v1/translator/detect-language", {
  method: "POST",
  headers: {
    "x-hark-key": process.env.HARK_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "text": "Bonjour"
  }),
});

if (!response.ok) {
  throw new Error(`Hark responded ${response.status}`);
}

console.log(await response.json());
Python
import os
import requests

response = requests.post(
    "https://edge.harktranslate.com/api/v1/translator/detect-language",
    headers={"x-hark-key": os.environ["HARK_API_KEY"]},
    json={
        "text": "Bonjour",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())

Status codes and machine codes are listed on the error catalog, including 200, 202, 400, 401, 403, 404, 413, 429, and 503.