Translation API Documentation

Multi-Tier Translation Service

Base URL

https://translate.prodajemauto.rs

All requests must include an api-key header for authentication.

Authentication

All API requests require an API key in the request header:

api-key: YOUR_ACCESS_TOKEN_SECRET
Security: Never expose your API key in client-side code. Use a server-side proxy to call the translation API.

Features

Endpoints

Translate Text

POST /translate

Translate text from one language to another.

Request Body

{
  "text": "Dobar dan, kako ste?",
  "source": "rs",
  "target": "en",
  "format": "text"
}

Parameters

Note: Use "sr" or "rs" for Serbian - both are accepted and normalized to "rs".

Format Parameter

The format parameter determines how the text is processed:

HTML Format: When using format: "html", the API strips HTML tags before translation and restores paragraph/line break structure afterward. This ensures clean translations while maintaining document formatting.

Response

{
  "success": true,
  "translated": "Good day, how are you?",
  "source": "rs",
  "target": "en",
  "dict_hits": 2,
  "fallback_hits": 1,
  "total_phrases": 3,
  "services_used": {
    "dictionary": 2,
    "lara": 1,
    "libretranslate": 0,
    "nllb": 0,
    "error": 0
  },
  "tokens_used": 5,
  "characters_translated": 19,
  "translation_time_ms": 554.23
}

Response Fields

Health Check

GET /health

Check if the translation service is running.

Response

{
  "success": true,
  "status": "Node API running",
  "pythonService": {
    "name": "Multi-Tier Translation API",
    "version": "2.0.0"
  }
}

Code Examples

cURL

curl -X POST https://translate.prodajemauto.rs/translate \
  -H "Content-Type: application/json" \
  -H "api-key: YOUR_API_KEY" \
  -d '{
    "text": "Dobar dan, kako ste?",
    "source": "rs",
    "target": "en",
    "format": "text"
  }'

JavaScript (Fetch)

const response = await fetch('https://translate.prodajemauto.rs/translate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'api-key': 'YOUR_API_KEY'
  },
  body: JSON.stringify({
    text: 'Dobar dan, kako ste?',
    source: 'rs',
    target: 'en',
    format: 'text'  // or 'html' for HTML content
  })
});

const data = await response.json();
console.log(data.translated);  // "Good day, how are you?"

JavaScript (Axios)

import axios from 'axios';

const { data } = await axios.post(
  'https://translate.prodajemauto.rs/translate',
  {
    text: 'Dobar dan, kako ste?',
    source: 'rs',
    target: 'en',
    format: 'text'  // or 'html' for HTML content
  },
  {
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY'
    }
  }
);

console.log(data.translated);  // "Good day, how are you?"

Node.js (Server-to-Server)

import axios from 'axios';

const API_KEY = process.env.TRANSLATE_API_KEY;
const API_URL = 'https://translate.prodajemauto.rs/translate';

async function translateText(text, sourceLang, targetLang, format = 'text') {
  try {
    const { data } = await axios.post(API_URL, {
      text,
      source: sourceLang,
      target: targetLang,
      format  // 'text' or 'html'
    }, {
      headers: {
        'Content-Type': 'application/json',
        'api-key': API_KEY
      },
      timeout: 30000
    });

    return data.success ? data.translated : text;
  } catch (error) {
    console.error('Translation failed:', error.message);
    return text;
  }
}

// Usage
const translated = await translateText(
  'Dobar dan, kako ste?',
  'rs',
  'en'
);

console.log(translated);  // "Good day, how are you?"

Python

import requests

url = 'https://translate.prodajemauto.rs/translate'
headers = {
    'Content-Type': 'application/json',
    'api-key': 'YOUR_API_KEY'
}
payload = {
    'text': 'Dobar dan, kako ste?',
    'source': 'rs',
    'target': 'en',
    'format': 'text'  # or 'html' for HTML content
}

response = requests.post(url, json=payload, headers=headers)
data = response.json()

if data['success']:
    print(data['translated'])  # "Good day, how are you?"

Supported Language Codes

The API uses simple 2-character ISO 639-1 codes for easy integration:

🇷🇸 Serbian & Balkans (8 languages)

🇪🇺 Western Europe (8 languages)

🇸🇪 Scandinavia (5 languages)

🇵🇱 Eastern Europe (7 languages)

🇱🇹 Baltics (3 languages)

🇬🇷 Other Europe (2 languages)

🇨🇳 Asia (14 languages)

🇬🇪 Caucasus & Central Asia (6 languages)

Total: 55+ languages supported
For a searchable list, visit /languages

Text Limits & Chunking

Large texts are handled seamlessly - the API splits, translates, and reassembles automatically.

Error Codes

Common Validation Errors