
Deploy Translation API | (Just Updated) LibreTranslate-Compatible, 400+ Languages, API Key Pre-Set
MADLAD-400 translation API on CTranslate2, LibreTranslate-compatible
Just deployed
Deploy and Host Translation API (CTranslate2 + MADLAD-400) on Railway
A self-hosted machine translation API translates text between hundreds of languages without sending it to a hosted service. This template serves Google's MADLAD-400-3B translation model on CTranslate2, on CPU, behind one authenticated JSON API that follows LibreTranslate's /translate request and response shape. The model is already inside the image, an API key is generated for you at deploy, and no GPU is needed.
About Hosting Translation API
This template runs CTranslate2 4.9.0 with the int8 conversion of google/madlad400-3b-mt behind a small FastAPI server. POST /translate takes {"q": "text", "source": "en", "target": "de"} (or q as a list of texts) and returns {"translatedText": ...}; a list in gives a list out. 454 target languages are accepted, listed by GET /languages (add ?targets=true for the target codes). The model needs no source language, so source is ignored and "auto" works. There is no /detect route, because this model cannot detect a language. Lines stay lines, and a line over 400 characters is split at sentence ends and translated piece by piece.
The weights are baked into the image, so nothing downloads at boot and the model is ready about 4 seconds after the container starts. The service sizes its thread pools from the container's own CPU quota instead of the host's core count, handles one request at a time so memory stays bounded, and refuses a text over 20,000 characters or a list over 50 texts. The text you send is held for the length of one request and is never logged or written to disk.
Measured on Railway, 8 vCPU (two separate deploys, so a range): a single sentence of about 75 characters translates in 1.2 to 1.4 s; a 233-character paragraph takes 2.4 to 3.4 s; a 2,300-character text takes 7 to 16 s; an 11,650-character English text into Japanese took 31 to 159 s, and a 13,980-character text into German took 123 s. A list of 50 short sentences took 10 s (about 5 sentences per second). Resident memory is 5.3 GB right after boot and peaked at 6.0 GB after those requests. Speed varies with the target language (Japanese and Thai produce many more tokens than German), so split documents into pieces of about 5,000 characters or fewer: the edge proxy cuts a request off after roughly 5 minutes, and the 20,000-character limit is a safety cap, not a promise that a worst-case text finishes in time.
Translation quality was not scored here. On spot checks the output is fluent for common languages, but this model sometimes repeats or adds a clause on a very short input, so check output that matters, and treat low-resource languages as a rough draft.
Agent contract
- Public URL:
https://RAILWAY_PUBLIC_DOMAIN(the generated domain of thetranslateservice) - Private URL:
http://translate.railway.internal:8080 - Credentials: the
API_KEYvariable of thetranslateservice - Auth: send
Authorization: Bearer $API_KEYon every route exceptGET /health(LibreTranslate's JSONapi_keyfield is also accepted); a call without the key or with a wrong one answers401 - Health:
GET /healthreturns 200 once the model is loaded (503 while it loads)
# needs: RAILWAY_PUBLIC_DOMAIN, API_KEY (a variable of the translate service); also curl.
# signup: none - the API has no user accounts, only the API_KEY bearer
R="https://$RAILWAY_PUBLIC_DOMAIN"
n=0; until [ "$(curl -s -o /dev/null -w '%{http_code}' "$R/health")" = 200 ]; do n=$((n+1)); [ "$n" -le 60 ] || break; sleep 5; done
curl -s -o /dev/null -w "health: %{http_code}\n" "$R/health"
B='{"q":"Where is the nearest train station?","source":"en","target":"de"}'
curl -s -o /dev/null -w "write without key: %{http_code}\n" -X POST "$R/translate" -H "Content-Type: application/json" -d "$B"
curl -s -o /dev/null -w "write wrong key: %{http_code}\n" -X POST "$R/translate" -H "Authorization: Bearer not-the-key" -H "Content-Type: application/json" -d "$B"
curl -s -X POST "$R/translate" -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" -d "$B"
A fresh deploy prints health: 200, write without key: 401, write wrong key: 401 and {"translatedText":"..."} with the German sentence. A target that is not one of the 454 codes answers 422 with the reason, a text or list over the limit answers 413, and format other than text answers 422. The API only reads the text you send and never fetches a URL, so it cannot be pointed at an address inside your network.
Why Deploy Translation API on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying Translation API on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
- Text stays in your container — translation runs in your own service, not in a hosted translation API.
- LibreTranslate-compatible — point an existing client at
/translateand/languagesand it works, with 454 target languages. - No GPU bill and no per-character fee — you pay for the container, not for each request.
- Open weights, commercial use — MADLAD-400 and CTranslate2 are Apache-2.0 and MIT licensed.
- Private by default — a generated bearer key guards every route but the health check, and the container refuses to start without one.
Common Use Cases
- Translate app content and support text — localise strings, tickets and messages from your own backend without a per-character bill.
- Translation step for AI agents — give an LLM agent one authenticated request that translates text into any of 454 languages.
- Replace a LibreTranslate server — keep the same API shape with a larger multilingual model behind it.
Dependencies for Translation API Hosting
- A service with at least 8 GB of RAM (resident memory measured at 5.3 GB idle and 6.0 GB after a 14,000-character request) and 8 vCPU for the speeds above; fewer vCPU translate proportionally slower.
- No volume: the service keeps no state and the model is in the image (about 3.5 GB image, so the first deploy takes several minutes to pull).
Deployment Dependencies
- OpenNMT/CTranslate2 — the inference engine, MIT, version 4.9.0
- google/madlad400-3b-mt — the MADLAD-400 3B translation model, Apache-2.0
- santhosh/madlad400-3b-ct2 — the int8 CTranslate2 conversion of that model, Apache-2.0, pinned to commit c32ad0cf118807ea6258d14be137547155842723
- bon5co/ctranslate-madlad-railway — the Railway wrapper image this template deploys, Apache-2.0
- Licences: the Hugging Face model cards of both
google/madlad400-3b-mtandsanthosh/madlad400-3b-ct2declarelicense: apache-2.0; CTranslate2 is released under the MIT licence. The notices travel with the image at/app/NOTICE.
Template Content

