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:
1. Single-String Translation (Sync)
POST /v1/translate
Performs an immediate, synchronous translation of a single string.
Request Parameters (application/json)
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)
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
idis 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}untilstatusisdone. - Download:
GET /v1/translate/file/{id}/downloadto 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:
Beta Languages
Beta coverage is supported between English and the beta language:
[!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": ""
}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.