Translation Endpoints

Translate documents and text using the Antinium API

Overview

The Translation API allows you to translate text and documents programmatically. You can translate individual text segments, entire documents, or batch multiple translations.

Translate Text

Translate a simple text string:

POST /v1/translate

Request Body:
{
  "text": "Hello, world!",
  "source_language": "en",
  "target_language": "es",
  "style": "formal" // optional
}

Response:
{
  "success": true,
  "data": {
    "translated_text": "¡Hola, mundo!",
    "source_language": "en",
    "target_language": "es"
  }
}

Parameters

  • text (required): The text to translate
  • source_language (required): Source language code (e.g., "en", "es")
  • target_language (required): Target language code
  • style (optional): Localization style ("formal", "casual", "legal", "marketing", "technical", "academic")

Translate Document

Translate an entire document:

POST /v1/documents/{document_id}/translate

Request Body:
{
  "target_language": "es",
  "style": "formal",
  "use_translation_memory": true // optional
}

Response:
{
  "success": true,
  "data": {
    "document_id": "doc_123",
    "translation_id": "trans_456",
    "status": "processing",
    "estimated_completion": "2024-01-15T10:30:00Z"
  }
}

Large documents are processed asynchronously. Check the translation status using the translation_id.

Check Translation Status

Check the status of an asynchronous translation:

GET /v1/translations/{translation_id}

Response:
{
  "success": true,
  "data": {
    "translation_id": "trans_456",
    "status": "completed", // "pending", "processing", "completed", "failed"
    "progress": 100,
    "document_id": "doc_123",
    "target_language": "es",
    "completed_at": "2024-01-15T10:25:00Z"
  }
}

Batch Translation

Translate multiple text segments in a single request:

POST /v1/translate/batch

Request Body:
{
  "texts": [
    "Hello, world!",
    "How are you?",
    "Thank you very much!"
  ],
  "source_language": "en",
  "target_language": "es"
}

Response:
{
  "success": true,
  "data": {
    "translations": [
      "¡Hola, mundo!",
      "¿Cómo estás?",
      "¡Muchas gracias!"
    ]
  }
}

Supported Languages

See the full list of supported languages. Language codes follow ISO 639-1 format (e.g., "en" for English, "es" for Spanish).

Example: Complete Workflow

// 1. Translate text
const response = await fetch('https://api.antinium.dev/v1/translate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    text: 'Welcome to our product!',
    source_language: 'en',
    target_language: 'es',
    style: 'marketing'
  })
});

const { data } = await response.json();
console.log(data.translated_text);
// Output: "¡Bienvenido a nuestro producto!"

// 2. Translate document (async)
const docResponse = await fetch(
  'https://api.antinium.dev/v1/documents/doc_123/translate',
  {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      target_language: 'es'
    })
  }
);

const { data: translation } = await docResponse.json();

// 3. Poll for completion
const checkStatus = async () => {
  const statusResponse = await fetch(
    `https://api.antinium.dev/v1/translations/${translation.translation_id}`,
    {
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY'
      }
    }
  );
  const { data: status } = await statusResponse.json();
  
  if (status.status === 'completed') {
    console.log('Translation complete!');
  } else if (status.status === 'processing') {
    setTimeout(checkStatus, 5000); // Check again in 5 seconds
  }
};

checkStatus();

Error Handling

Common error responses:

// Invalid language code
{
  "success": false,
  "error": {
    "code": "INVALID_LANGUAGE",
    "message": "Language code 'xx' is not supported"
  }
}
// Text too long
{
  "success": false,
  "error": {
    "code": "TEXT_TOO_LONG",
    "message": "Text exceeds maximum length of 10,000 characters"
  }
}

Rate Limits

Translation endpoints have specific rate limits:

  • Text translation: 100 requests per minute
  • Document translation: 10 requests per minute
  • Batch translation: 20 requests per minute

Rate limit information is included in response headers.

Related Topics