Docs🛠️ DeveloperLanguage Detection
POST/api/detect-language$0.001

🛠️ Language Detection

Detect the natural language of any text input. Returns the ISO 639-1 language code, language name, and confidence score. Supports 50+ languages including English, Spanish, French, German, Chinese, Japanese, Arabic, and more.

Request Body

ParameterTypeRequiredDescriptionDefault
textstringrequiredText to detect the language of

Response Fields

FieldTypeDescription
languagestringISO 639-1 language code (e.g. en, es, fr)
language_namestringFull language name in English
confidencenumberDetection confidence 0.0–1.0
alternativesarrayAlternative language candidates

Code Examples

cURL
bash
curl -X POST https://sparkforge.sh/api/detect-language \
  -H "Content-Type: application/json" \
  -H "X-PAYMENT: <x402-payment-token>" \
  -d '{"text": "Bonjour, comment allez-vous?"}'
Python
python
import requests

response = requests.post(
    "https://sparkforge.sh/api/detect-language",
    headers={"Content-Type": "application/json", "X-PAYMENT": "<token>"},
    json={"text": "Bonjour, comment allez-vous?"}
)

data = response.json()
print(f"{data['language_name']} ({data['language']}) - {data['confidence']:.0%} confidence")
TypeScript / Node.js
typescript
const res = await fetch402("https://sparkforge.sh/api/detect-language", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: "Bonjour, comment allez-vous?" }),
});

const { language, language_name, confidence } = await res.json();

Example Response

json
{
  "language": "fr",
  "language_name": "French",
  "confidence": 0.97,
  "alternatives": [
    { "language": "ro", "language_name": "Romanian", "confidence": 0.02 },
    { "language": "it", "language_name": "Italian", "confidence": 0.01 }
  ]
}

💳 Payment via x402

This endpoint costs $0.001 per call, paid in USDC on Base, Polygon, or Solana. Use the @x402/fetch library to handle payments automatically, or implement the x402 handshake manually.

bash
# Free demo mode (no payment)
curl https://sparkforge.sh/api/detect-language?demo=true

# Or try via MCP (Claude Desktop, Cursor, Windsurf)
# Add to mcp config: { "url": "https://sparkforge.sh/api/mcp" }
Previous
Text Diff
Next
AI Code Review