Translation API Documentation

NLLB-200 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.

Endpoints

Translate Text

POST /translate

Translate text from one language to another.

Request Body

{
  "text": "<p>Hello world</p>",
  "source": "eng_Latn",
  "target": "srp_Cyrl"
}

Response

{
  "success": true,
  "translated": "Zdravo svete",
  "source": "eng_Latn",
  "target": "srp_Cyrl"
}

Health Check

GET /health

Check if the translation service is running.

Response

{
  "success": true,
  "status": "Node API running",
  "pythonService": {
    "status": "translator running"
  }
}

Code Examples

cURL

curl -X POST https://translate.prodajemauto.rs/translate \
  -H "Content-Type: application/json" \
  -H "api-key: YOUR_API_KEY" \
  -d '{
    "text": "<p>Hello world</p>",
    "source": "eng_Latn",
    "target": "srp_Cyrl"
  }'

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: '<p>Hello world</p>',
    source: 'eng_Latn',
    target: 'srp_Cyrl'
  })
});

const data = await response.json();
console.log(data.translated);

JavaScript (Axios)

import axios from 'axios';

const { data } = await axios.post(
  'https://translate.prodajemauto.rs/translate',
  {
    text: '<p>Hello world</p>',
    source: 'eng_Latn',
    target: 'srp_Cyrl'
  },
  {
    headers: {
      'Content-Type': 'application/json',
      'api-key': 'YOUR_API_KEY'
    }
  }
);

console.log(data.translated);

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) {
  try {
    const { data } = await axios.post(API_URL, {
      text,
      source: sourceLang,
      target: targetLang
    }, {
      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(
  '<p>Hello world</p>',
  'eng_Latn',
  'srp_Cyrl'
);

Python

import requests

url = 'https://translate.prodajemauto.rs/translate'
headers = {
    'Content-Type': 'application/json',
    'api-key': 'YOUR_API_KEY'
}
payload = {
    'text': '<p>Hello world</p>',
    'source': 'eng_Latn',
    'target': 'srp_Cyrl'
}

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

if data['success']:
    print(data['translated'])

Language Codes

The API supports 204 languages from the NLLB-200 model. Language codes follow the format:

language_Script

Examples:

View all supported languages at /languages

Error Codes