Skip to main content
A
Docs

API Reference

Complete API reference for the Anar Translate sovereign translation engine.

Base URL

http://localhost:8012/api/v1

All endpoints require Bearer token authentication in the Authorization header.

Translation

Translate Text

POST
/api/v1/translate

Translate a single text segment with domain specialization.

Request Body:

{
  "text": "يجب على جميع الجهات الحكومية الالتزام بمعايير الأمن السيبراني",
  "source_lang": "ar",
  "target_lang": "en",
  "domain": "administrative"
}
FieldTypeRequiredDescription
textstringYesText to translate (1-50,000 characters)
source_langstringNoSource language: ar, en, auto (default: auto)
target_langstringNoTarget language: ar, en (default: en)
domainstringNoDomain: general, legal, technical, administrative, medical, financial

Response:

{
  "id": "tr-a1b2c3",
  "source_text": "يجب على جميع الجهات الحكومية الالتزام بمعايير الأمن السيبراني",
  "translated_text": "All government entities must comply with cybersecurity standards",
  "source_lang": "ar",
  "target_lang": "en",
  "domain": "administrative",
  "quality_score": 0.92,
  "model_used": "llama-3.3-70b-versatile",
  "tokens_used": 156,
  "created_at": "2024-01-15T10:30:00Z"
}

Batch Translate

POST
/api/v1/translate/batch

Translate multiple text segments in a single request (max 50 segments).

Request Body:

{
  "texts": [
    "First segment to translate",
    "Second segment to translate"
  ],
  "source_lang": "auto",
  "target_lang": "ar",
  "domain": "legal"
}

Response:

{
  "translations": [...],
  "total": 2,
  "domain": "legal"
}

Translate Document

POST
/api/v1/translate/document

Upload a document file for end-to-end translation. Accepts multipart/form-data.

Form Fields:

FieldTypeRequiredDescription
filebinaryYesDocument file (PDF, DOCX, TXT)
source_langstringNoSource language (default: auto)
target_langstringNoTarget language (default: en)
domainstringNoDomain (default: general)

Response:

{
  "id": "doc-a1b2c3",
  "filename": "contract.pdf",
  "source_lang": "ar",
  "target_lang": "en",
  "domain": "legal",
  "status": "completed",
  "total_segments": 120,
  "translated_segments": 120,
  "translated_text": "...",
  "created_at": "2024-01-15T10:30:00Z",
  "completed_at": "2024-01-15T10:30:25Z"
}

Detect Language

POST
/api/v1/translate/detect

Detect the language of input text.

Request Body:

{
  "text": "All government entities must comply with cybersecurity standards"
}

Response:

{
  "language": "en",
  "confidence": 0.98,
  "script": "Latin"
}

Translation History

GET
/api/v1/translate/history

List past translations with pagination and filtering.

Query Parameters:

ParameterTypeDefaultDescription
domainstring-Filter by domain
pageinteger1Page number
page_sizeinteger20Results per page (max 100)

Translation Memory

Create TM Entry

POST
/api/v1/translation-memory

Add a translation pair to the memory.

List TM Entries

GET
/api/v1/translation-memory

Browse TM entries with filtering by language, domain, and search.

Get TM Entry

GET
/api/v1/translation-memory/{entry_id}

Update TM Entry

PUT
/api/v1/translation-memory/{entry_id}

Delete TM Entry

DELETE
/api/v1/translation-memory/{entry_id}

Requires admin role.

Export TMX

GET
/api/v1/translation-memory/export

Export translation memory as a TMX XML file.

Import TMX

POST
/api/v1/translation-memory/import

Import a TMX file to bulk-load TM entries. Requires admin role. Accepts .tmx or .xml files via multipart/form-data.

Glossaries

Create Glossary

POST
/api/v1/glossaries

List Glossaries

GET
/api/v1/glossaries

Get Glossary

GET
/api/v1/glossaries/{glossary_id}

Update Glossary

PUT
/api/v1/glossaries/{glossary_id}

Delete Glossary

DELETE
/api/v1/glossaries/{glossary_id}

Requires admin role.

Create Glossary Entry

POST
/api/v1/glossaries/{glossary_id}/entries

List Glossary Entries

GET
/api/v1/glossaries/{glossary_id}/entries

Update Glossary Entry

PUT
/api/v1/glossaries/{glossary_id}/entries/{entry_id}

Delete Glossary Entry

DELETE
/api/v1/glossaries/{glossary_id}/entries/{entry_id}

Requires admin role.

Health

Health Check

GET
/api/v1/health

Returns service health status and version information.