---
title: "Deploy Translation API | (Just Updated) LibreTranslate-Compatible, 400+ Languages, API Key Pre-Set"
description: "MADLAD-400 translation API on CTranslate2, LibreTranslate-compatible"
category: "AI/ML"
url: https://railway.com/deploy/translation-api-or-just-updated-libretra
---

# Deploy Translation API | (Just Updated) LibreTranslate-Compatible, 400+ Languages, API Key Pre-Set

MADLAD-400 translation API on CTranslate2, LibreTranslate-compatible

**[Deploy Translation API | (Just Updated) LibreTranslate-Compatible, 400+ Languages, API Key Pre-Set on Railway](https://railway.com/template/translation-api-or-just-updated-libretra)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/translation-api-or-just-updated-libretra/manifest.json

- **Creator:** SuperSlowSloth
- **Category:** AI/ML

## Template content

### translate

- **Image:** ghcr.io/bon5co/ctranslate-madlad-railway:1.0.0@sha256:f17d6ec5629ddc37a75499fb492e99b98c09b3999b74b10e4834129b37eab3d4
- **Health check:** /health
- **Public domain:** Yes

## Documentation

# 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 the `translate` service)
- Private URL: `http://translate.railway.internal:8080`
- Credentials: the `API_KEY` variable of the `translate` service
- Auth: send `Authorization: Bearer $API_KEY` on every route except `GET /health` (LibreTranslate's JSON `api_key` field is also accepted); a call without the key or with a wrong one answers `401`
- Health: `GET /health` returns 200 once the model is loaded (503 while it loads)

```bash
# 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 `/translate` and `/languages` and 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](https://github.com/OpenNMT/CTranslate2) — the inference engine, MIT, version 4.9.0
- [google/madlad400-3b-mt](https://huggingface.co/google/madlad400-3b-mt) — the MADLAD-400 3B translation model, Apache-2.0
- [santhosh/madlad400-3b-ct2](https://huggingface.co/santhosh/madlad400-3b-ct2) — the int8 CTranslate2 conversion of that model, Apache-2.0, pinned to commit c32ad0cf118807ea6258d14be137547155842723
- [bon5co/ctranslate-madlad-railway](https://github.com/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-mt` and `santhosh/madlad400-3b-ct2` declare `license: apache-2.0`; CTranslate2 is released under the MIT licence. The notices travel with the image at `/app/NOTICE`.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/translation-api-or-just-updated-libretra
