DocsREST API

Projects

Projects and their settings, statistics, API keys, translation instructions and glossary.

On this page

A project is one translatable product: a set of source strings, target locales, translations, files and keys.

The project object

{
  "id": "prj_abc123",
  "orgId": "org_77bqm…",
  "name": "Web app",
  "defaultLocale": "en",
  "locales": ["es", "fr", "ja"],
  "cdnEnabled": true,
  "requiresReview": false,
  "model": "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
  "createdAt": "2026-11-30T10:00:00.000Z",
  "updatedAt": "2026-11-30T10:00:00.000Z"
}
Field Meaning
defaultLocale The language your source text is written in.
locales Target locales. Batch jobs and publishing default to this list.
cdnEnabled When false, the project’s /cdn/… URLs return 404.
requiresReview When true, only approved translations are published.
model The model used to translate. Must be one of the ids in models from GET / (or, if the deployment has an Anthropic key configured, a claude-… id). New projects get the deployment’s default model.

List and create projects

GET /v1/orgs/:orgId/projects returns an array of projects. Session token, viewer role.

POST /v1/orgs/:orgId/projects creates one. Session token, admin role.

curl -X POST https://generic-translation-api.jacobfv123.workers.dev/v1/orgs/org_77bqm/projects \
  -H "authorization: Bearer $GENERIC_TRANSLATION_SESSION" \
  -H "content-type: application/json" \
  -d '{ "name": "Web app", "defaultLocale": "en", "locales": ["es", "fr", "ja"] }'
Field Type Required Default
name string yes
defaultLocale string no "en"
locales string[] no []

Returns the project with status 201. Locale codes are canonicalized (pt_br becomes pt-BR), de-duplicated, and the default locale is removed from locales. New projects have cdnEnabled: true and requiresReview: false. Errors: 400 invalid_request for an invalid locale code or empty name.

Get, update or delete a project

Route Key permission Notes
GET /v1/projects/:projectId project:read :projectId may be current with an API key.
PATCH /v1/projects/:projectId project:write Any of name, defaultLocale, locales, cdnEnabled, requiresReview, model.
DELETE /v1/projects/:projectId session, admin Deletes strings, translations, files and keys. Cannot be undone.
curl -X PATCH https://generic-translation-api.jacobfv123.workers.dev/v1/projects/current \
  -H "authorization: Bearer $GENERIC_TRANSLATION_API_KEY" \
  -H "content-type: application/json" \
  -d '{ "locales": ["es", "fr", "ja", "de"], "requiresReview": true }'

Setting cdnEnabled also takes effect on the CDN immediately. DELETE returns { "ok": true } and also removes the project’s published CDN files. Errors: 400 invalid_request (including a model that is not allowed), 403 permission_missing, 404 not_found.

Adding a locale does not translate anything by itself. Run generic-translation translate or submit entries again; everything already translated is served from cache and only the new locale is worked on.

Stats

GET /v1/projects/:projectId/stats (project:read)

{
  "strings": 1382,
  "locales": [
    { "locale": "es", "translated": 1382, "approved": 1200, "total": 1382, "percent": 100 },
    { "locale": "ja", "translated": 1290, "approved": 0, "total": 1382, "percent": 93 }
  ],
  "lastPublishedAt": "2026-11-30T10:15:00.000Z",
  "files": 4
}

strings counts source strings, files counts uploaded files, and percent is translated ÷ total rounded to a whole number. Only the project’s current target locales are listed. lastPublishedAt is null for a project that has never been published.

API keys

Key management needs a session token: listing needs the viewer role, creating and deleting need admin. A key cannot manage keys.

List keys

GET /v1/projects/:projectId/keys

Returns key records without the secret.

[
  {
    "id": "key_1c9d0…",
    "projectId": "prj_abc123",
    "name": "CI",
    "prefix": "gt-api-3fK9x",
    "permissions": ["project:read", "translations:enqueue", "translations:write"],
    "createdAt": "2026-11-30T10:00:00.000Z",
    "lastUsedAt": "2026-11-30T12:41:07.000Z"
  }
]

prefix is the first 12 characters of the key, to help you recognise it. lastUsedAt is null for a key that was never used and is updated at most every five minutes.

Create a key

POST /v1/projects/:projectId/keys

curl -X POST https://generic-translation-api.jacobfv123.workers.dev/v1/projects/prj_abc123/keys \
  -H "authorization: Bearer $GENERIC_TRANSLATION_SESSION" \
  -H "content-type: application/json" \
  -d '{ "name": "CI", "permissions": ["project:read", "translations:enqueue", "translations:write"] }'
{
  "key": "gt-api-…",
  "id": "key_1c9d0…",
  "projectId": "prj_abc123",
  "name": "CI",
  "prefix": "gt-api-3fK9x",
  "permissions": ["project:read", "translations:enqueue", "translations:write"],
  "createdAt": "2026-11-30T10:00:00.000Z",
  "lastUsedAt": null
}

Status 201. key is returned only in this response. Store it in a secret manager now. permissions is optional; when omitted the key gets all nine permissions. (The dashboard pre-selects a smaller default set.) See API keys for the permissions and for recipes. An empty permissions array is rejected with 400 invalid_request.

Delete a key

DELETE /v1/projects/:projectId/keys/:keyId revokes it immediately and returns { "ok": true }. An unknown key id returns 404 not_found.

Translation instructions

Free-text guidance given to the model with every translation in the project: who the audience is, the tone, formality, things to avoid.

Route Permission
GET /v1/projects/:projectId/context context:read
PUT /v1/projects/:projectId/context context:write

Instructions are limited to 8,000 characters.

curl -X PUT https://generic-translation-api.jacobfv123.workers.dev/v1/projects/current/context \
  -H "authorization: Bearer $GENERIC_TRANSLATION_API_KEY" \
  -H "content-type: application/json" \
  -d '{ "instructions": "A budgeting app for freelancers. Friendly, concise, informal second person. Never translate the product name Ledgerly." }'

Both return { "instructions": "…" }.

Glossary

Terms with fixed translations or a do-not-translate rule.

Route Permission
GET /v1/projects/:projectId/glossary context:read
POST /v1/projects/:projectId/glossary context:write
PATCH /v1/projects/:projectId/glossary/:termId context:write
DELETE /v1/projects/:projectId/glossary/:termId context:write
POST /v1/projects/:projectId/glossary/apply context:write

Create a term

{
  "term": "workspace",
  "definition": "A shared area that holds a team's projects.",
  "translations": { "es": "espacio de trabajo", "fr": "espace de travail" },
  "caseSensitive": false,
  "doNotTranslate": false
}
Field Type Required Meaning
term string yes The word or phrase in the source language.
definition string no What it means in your product. Helps the model choose a sense.
translations object no Fixed translation per locale. Locales not listed are left to the model, guided by the definition.
caseSensitive boolean no Match only the exact casing. Default false.
doNotTranslate boolean no Keep the term in the source language everywhere, such as a brand name. Default false.

Returns the term with its gls_… id and status 201. term is 1 to 200 characters, definition up to 1,000. translations maps a locale to a fixed translation; lookup tries the exact locale, a case-insensitive match, then any locale of the same language. Terms match on whole words (case-insensitive unless caseSensitive). PATCH accepts any subset of the same fields. GET returns an array ordered by term; DELETE returns { "ok": true }; an unknown term id returns 404 not_found.

The returned term looks like this:

{
  "id": "gls_8h2kd…",
  "projectId": "prj_abc123",
  "term": "workspace",
  "definition": "A shared area that holds a team's projects.",
  "translations": { "es": "espacio de trabajo" },
  "caseSensitive": false,
  "doNotTranslate": false,
  "createdAt": "2026-11-30T10:00:00.000Z",
  "updatedAt": "2026-11-30T10:00:00.000Z"
}

Apply the glossary to existing translations

POST /v1/projects/:projectId/glossary/apply

Glossary changes affect new translations. To bring existing ones in line, this endpoint re-translates every string whose source contains a glossary term, in every target locale. Only machine translations are replaced: anything a person edited or approved is left alone.

The response has status 202:

{
  "jobId": "job_9x2ab…",
  "job": { "id": "job_9x2ab…", "projectId": "prj_abc123", "type": "glossary", "status": "queued", "total": 42, "completed": 0, "failed": 0, "createdAt": "2026-11-30T10:00:00.000Z", "updatedAt": "2026-11-30T10:00:00.000Z" }
}

Poll the job as described under jobs. If nothing matches, total is 0 and the job is already finished. The key needs context:write; sessions need the member role.

Something wrong or unclear on this page? Open an issue.

Type to search the documentation.