Mansa Platform Docs

Translate

Translate text from one supported language to another. Send `Authorization: Bearer` with your Mansa API key.

POST/v1/translate

Request example

curl --fail-with-body "$MANSA_API_BASE_URL/v1/translate" \
  -H "Authorization: Bearer $MANSA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "text": "Good morning",
  "from": "English",
  "to": "Swahili",
  "tone": "natural"
}'

Output

{
  "context": "ok",
  "data": {
    "translation": "Habari za asubuhi"
  }
}

The central guide for translating text between African languages and English using the Mansa API.


Authentication

Authenticate all API requests by providing your Mansa API key in the Authorization header:

Authorization: Bearer <YOUR_API_KEY>

Sync vs Async Workflows

Mansa provides dedicated endpoints tailored to different translation workloads:

WorkloadRecommended EndpointModeCapacity / Limits
Single stringPOST /v1/translateSynchronousImmediate response for a single text string
Multiple segments (2–100 strings)POST /v1/translate/batchAsynchronousUp to 100 segments per job; poll until complete
Documents / Files (DOCX, TXT, CSV, XLSX)POST /v1/translate/fileAsynchronousUp to 10 MB and up to 1,100 segments per file

1. Single-String Translation (Sync)

POST /v1/translate

Performs an immediate, synchronous translation of a single string.

Request Parameters (application/json)

ParameterTypeRequiredDescription
textStringYesThe source text to translate.
toStringYesTarget language name or code (e.g. sw, yor, ha, Swahili). (Alias: toLanguage)
fromStringNoSource language name or code. Defaults to "auto". (Alias: fromLanguage)
toneStringNoTranslation register: "formal", "informal", or "neutral" (default).
contextStringNoOptional domain or disambiguation hints to guide nuance.
glossaryArrayNoInline glossary array: [{"term": "source_term", "translation": "target_term"}].
creativityNumberNoSampling temperature between 0 and 1 (default: 0.7).
maxTokensIntegerNoMaximum token output limit (default: 512).

Example Request

curl -X POST https://api.mansa.ai/v1/translate \
  -H "Authorization: Bearer mansa_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Good morning, welcome to our platform.",
    "from": "en",
    "to": "sw",
    "tone": "formal"
  }'

Response (200 OK)

{
  "context": "OK",
  "data": {
    "translation": "Habari za asubuhi, karibu kwenye jukwaa letu.",
    "text": "Habari za asubuhi, karibu kwenye jukwaa letu.",
    "inputTokens": 16,
    "outputTokens": 12,
    "isValid": true,
    "needsReview": false,
    "billing": {
      "cost": 0.0028,
      "balanceBefore": 15.00,
      "balanceAfter": 14.9972,
      "pricing": {
        "rate": "per_token"
      }
    }
  },
  "meta": null
}

2. Multi-Segment & Batch Translation (Async)

When you need to translate multiple phrases, sentences, or structured UI strings (from 2 up to 100 segments), use the asynchronous Batch Translation API.

Step 1: Submit Batch Job (POST /v1/translate/batch)

Request Parameters (application/json)

ParameterTypeRequiredDescription
segmentsArrayYesArray of 1 to 100 segment objects: [{"id": "optional-id", "text": "string"}].
toStringYesTarget language name or code.
fromStringNoSource language name or code (default: "auto").
toneStringNoTranslation register: "precise", "natural" (default), "expressive", or "formal".
contextStringNoShared domain or situational context for all segments (max 1,000 characters).
glossaryArrayNoInline glossary terms for this batch: [{"term": "term", "translation": "translation"}].

Example Batch Submission

curl -X POST https://api.mansa.ai/v1/translate/batch \
  -H "Authorization: Bearer mansa_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "from": "en",
    "to": "sw",
    "segments": [
      { "id": "nav_home", "text": "Home" },
      { "id": "nav_settings", "text": "Account Settings" },
      { "id": "btn_logout", "text": "Log Out" }
    ],
    "tone": "natural",
    "context": "Mobile app navigation menu strings"
  }'

Submission Response (202 Accepted)

{
  "context": "OK",
  "data": {
    "jobId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
    "segmentCount": 3,
    "sourceChars": 27,
    "message": "Batch translation started in the background."
  },
  "meta": null
}

Step 2: Poll Batch Job Status (GET /v1/translate/batch/{id})

Poll every 2–3 seconds until status transitions from "running" to "done".

Example Status Response (200 OK when completed)

{
  "context": "OK",
  "data": {
    "status": "done",
    "stage": "completed",
    "completedSegments": 3,
    "totalSegments": 3,
    "segments": [
      {
        "id": "nav_home",
        "text": "Home",
        "translatedText": "Nyumbani"
      },
      {
        "id": "nav_settings",
        "text": "Account Settings",
        "translatedText": "Mipangilio ya Akaunti"
      },
      {
        "id": "btn_logout",
        "text": "Log Out",
        "translatedText": "Ondoka"
      }
    ],
    "error": null
  },
  "meta": null
}

[!TIP] Each segment's id is preserved in the response, enabling direct correlation back to your original data keys.


3. Document Translation (Files)

For complete files, use the Document Translation pipeline:

  • Upload: POST /v1/translate/file (multipart/form-data) supporting .docx, .txt, .csv, and .xlsx (max 10 MB, up to 1,100 segments).
  • Poll: GET /v1/translate/file/{id} until status is done.
  • Download: GET /v1/translate/file/{id}/download to retrieve the translated file maintaining format and layout.

4. Feature Deep Dive

Glossary

Use inline glossaries to enforce consistent translations for specialized domain terminology, brand names, or technical terms.

  • Format: Send an array of { "term": "...", "translation": "..." } objects.
  • Scope: The inline glossary is applied strictly to the current request (both single-string and batch).
  • Case Sensitivity: Term matching is case-insensitive, but preserves appropriate casing in the output.
{
  "text": "Check your wallet balance on the dashboard.",
  "from": "en",
  "to": "sw",
  "glossary": [
    { "term": "wallet", "translation": "pochi" },
    { "term": "dashboard", "translation": "dashibodi" }
  ]
}

Tone & Register

Set the tone to adapt formality and vocabulary to your target audience:

  • On POST /v1/translate (Single String):
    • "formal": Professional, polite, and respectful address.
    • "informal": Casual, conversational, and direct.
    • "neutral" (default): Balanced, natural phrasing.
  • On POST /v1/translate/batch (Batch):
    • "precise": Strict literal fidelity.
    • "natural" (default): Fluent, conversational phrasing.
    • "formal": Professional and polite register.
    • "expressive": Rich, localized phrasing.

Context Hints

Provide domain hints to resolve linguistic ambiguities (e.g. polysemous words):

{
  "text": "The plant requires regular maintenance.",
  "from": "en",
  "to": "yo",
  "context": "Industrial manufacturing facility, not a botanical plant"
}

Supported Languages

Languages can be specified using either ISO 639 codes or full English names.

Stable Languages

Full bidirectional translation between all stable languages and English:

LanguageCodeLanguageCode
EnglishenSwahilisw
ArabicarAfrikaansaf
AmharicamHausaha
IgboigSomaliso
XhosaxhZuluzu
YorubayoKinyarwandarw
ShonasnTswanatn
ChichewanyLugandalg
MalagasymgOromoom
SesothostSepedinso
Tsongats

Beta Languages

Beta coverage is supported between English and the beta language:

LanguageCodeLanguageCode
KirundirnNdebele (South)nr
SwatissTigrinyati
TwiakEweee
LingalalnKikongokg
BambarabmBembabem

[!IMPORTANT] Translating directly between two Beta languages is not supported. Use English as an intermediate bridge if needed.


Errors & HTTP Status Codes

All errors return RFC-7807 compliant error payloads:

{
  "type": "about:blank",
  "title": "VALIDATION_ERROR",
  "isError": true,
  "detail": "Field 'text' is required",
  "invalidParams": [],
  "context": ""
}
HTTP StatusError Category (title)Common Causes
400BAD_REQUESTUnsupported source/target language, or invalid language pair direction.
401AUTHENTICATION_ERRORMissing or invalid API key in Authorization header.
402PAYMENT_ERRORAccount balance has insufficient credits.
404NOT_FOUNDBatch job ID does not exist or belongs to another user.
422VALIDATION_ERRORMissing required parameters (text, segments, to), or invalid tone.
500SERVER_ERRORInternal server or model inference error.

Billing & Credits

Successful translations debit Mansa Credits from your account balance:

  • Rate & Estimation: Usage is priced at $0.10 per 1K characters ($100 per 1M characters).
  • Billing Calculation: Charges are calculated according to the total source volume translated (including all text across segments when using batch translation).
  • Insufficient Balance: If your wallet has insufficient credits to cover the operation, requests are rejected with HTTP 402 (PAYMENT_ERROR).

For full volume pricing tiers and wallet balance management, see Pricing.