DocsREST API
Translate
Runtime translation, batch entries, jobs and reading the latest translations.
On this page
There are two ways to ask for translations.
| Runtime | Batch | |
|---|---|---|
| Endpoint | POST /translate |
POST /entries |
| Response | Translations, in the response | A job id to poll |
| Size | Up to 50 strings, one locale | Up to 2000 entries, many locales |
| Stored as project strings | Yes, when a translation is generated (they appear in the editor) | Yes: appear in the editor and can be published |
| Permission | translations:generate |
translations:enqueue |
| Use for | Dynamic content on a server | Your app’s UI strings, from the CLI or CI |
Both are cached by content hash and locale, so asking twice costs one translation. Both register each source as a project string, so results can be reviewed in the editor and are included when you publish.
Runtime translation
POST /v1/projects/:projectId/translate
curl -X POST https://generic-translation-api.jacobfv123.workers.dev/v1/projects/current/translate \
-H "authorization: Bearer $GENERIC_TRANSLATION_API_KEY" \
-H "content-type: application/json" \
-d '{
"targetLocale": "es",
"requests": [
{ "source": "Hello <0>{name}</0>", "context": "Dashboard greeting" },
{ "source": "{count, plural, one {# file} other {# files}}" },
{ "source": "v2.1 (build 884)", "dataFormat": "STRING" }
]
}'
| Field | Type | Required | Notes |
|---|---|---|---|
targetLocale |
string | yes | |
sourceLocale |
string | no | Defaults to the project’s defaultLocale. |
requests |
array | yes | 1 to 50 items. |
requests[].source |
string | yes | An ICU message, or plain text with dataFormat: "STRING". |
requests[].context |
string | no | Disambiguating note. Part of the hash. |
requests[].dataFormat |
"ICU" | "STRING" |
no | Default "ICU". |
requests[].id |
string | no | Your label. Not part of the hash. |
{
"results": [
{ "hash": "5d1e…", "success": true, "translation": "Hola <0>{name}</0>", "cached": false },
{ "hash": "c40d…", "success": true, "translation": "{count, plural, one {# archivo} other {# archivos}}", "cached": true },
{ "hash": "a71b…", "success": true, "translation": "v2.1 (compilación 884)", "cached": false }
]
}
results is in the same order as requests. A single string can fail without failing the call:
{ "hash": "09ab…", "success": false, "cached": false, "error": "…" }
cached is true when the translation already existed. If targetLocale is the same language as the source locale, every result is returned unchanged with cached: true and nothing is stored. Sources are 1 to 10,000 characters; context up to 1,000.
The call is rate limited to 300 requests per minute per key by default; see rate limits.
Errors for the whole call: 400 invalid_request (more than 50 requests, empty requests, missing targetLocale, invalid locale), 401 unauthenticated, 403 permission_missing, 429 rate_limited.
Batch translation
POST /v1/projects/:projectId/entries
Submits source strings as project strings and queues translation into the target locales.
curl -X POST https://generic-translation-api.jacobfv123.workers.dev/v1/projects/current/entries \
-H "authorization: Bearer $GENERIC_TRANSLATION_API_KEY" \
-H "content-type: application/json" \
-d '{
"locales": ["es", "fr"],
"entries": [
{ "source": "Hello <0>{name}</0>", "context": "Dashboard greeting" },
{ "source": "Sign out", "id": "nav.signout" }
]
}'
| Field | Type | Required | Notes |
|---|---|---|---|
entries |
array | yes | 1 to 2000 items. Split larger sets across calls. |
entries[].source |
string | yes | |
entries[].context |
string | no | |
entries[].dataFormat |
"ICU" | "STRING" |
no | Default "ICU". |
entries[].id |
string | no | Shown in the editor. |
entries[].hash |
string | no | If you send it, the server checks it against its own computation. |
locales |
string[] | no | Defaults to the project’s locales. |
sourceLocale |
string | no | Defaults to the project’s defaultLocale. |
branch |
string | no | Default "main". See branches. |
force |
boolean | no | Re-translate even where a translation exists. Default false. |
{ "jobId": "job_9x2ab…", "total": 2, "cached": 2 }
The response status is 202.
totalis the number of entry × locale pairs that need translating.cachedis the number of pairs that already had a translation and were skipped.
In the example, two entries × two locales is four pairs; two were already translated, two are queued. If total is 0 the job completes immediately and a job.completed event is sent. Locales in the same language as sourceLocale are skipped. With force: true, existing translations are replaced even if a person edited or approved them; without it, existing translations are never overwritten.
Errors: 400 invalid_request (more than 2000 entries, a hash that does not match the server-computed hash, invalid locale), 401 unauthenticated, 403 permission_missing. Entries are deduplicated by hash within a call.
Jobs
GET /v1/jobs/:jobId
Any API key of the job’s project (whatever its permissions), or a session of an organization member, can read a job. An unknown id returns 404 not_found.
{
"id": "job_9x2ab…",
"projectId": "prj_abc123",
"type": "entries",
"status": "running",
"total": 240,
"completed": 180,
"failed": 0,
"createdAt": "2026-11-30T10:00:00.000Z",
"updatedAt": "2026-11-30T10:00:21.000Z"
}
| Field | Values |
|---|---|
type |
entries (batch strings), file (a file upload), glossary (glossary apply) |
status |
queued → running → completed or failed. A job is failed only when every item failed; otherwise it is completed, possibly with failed > 0. |
total, completed, failed |
Counts of entry × locale pairs. |
error |
Present when status is failed. |
completedAt |
Present once finished. |
A job with status completed may still have a non-zero failed count: those individual strings could not be translated and can be retried by submitting them again.
Polling. Poll every second or two until the status is completed or failed. Polling is not merely passive: a request to this endpoint may also advance the job’s processing, so a polled job finishes sooner than an unwatched one. Unwatched jobs are still processed in the background. For a push notification instead, subscribe to the job.completed and job.failed webhooks.
async function waitForJob(jobId: string) {
for (;;) {
const res = await fetch(`https://generic-translation-api.jacobfv123.workers.dev/v1/jobs/${jobId}`, {
headers: { authorization: `Bearer ${process.env.GENERIC_TRANSLATION_API_KEY}` },
});
const job = await res.json();
if (job.status === "completed" || job.status === "failed") return job;
await new Promise((r) => setTimeout(r, 1500));
}
}
List a project’s jobs
GET /v1/projects/:projectId/jobs?limit=20 (project:read)
Returns an array of recent jobs, newest first. limit is 1 to 200 (default 50).
Get the latest translations
GET /v1/projects/:projectId/translations/:locale?branch=main (project:read)
Returns the current translation map for a locale, including translations that have not been published and, unlike the CDN, regardless of review status. With branch, only strings that were submitted to /entries with that branch are included.
curl https://generic-translation-api.jacobfv123.workers.dev/v1/projects/current/translations/es \
-H "authorization: Bearer $GENERIC_TRANSLATION_API_KEY"
{
"5d1e7c2a90b34f6e8d1a0c3b5e7f9a24": "Hola <0>{name}</0>",
"0b8f3a6d2c1e4f7a9b5d8e0c2a4f6b81": "Cerrar sesión"
}
This is what generic-translation translate writes to your output path.
Something wrong or unclear on this page? Open an issue.