DocsOperate
Self-hosting
Run the Generic Translation API and CDN on your own Cloudflare account and point the libraries and CLI at it.
On this page
The hosted Generic Translation API is one Cloudflare Worker (generic-translation-api) built with Hono. You can deploy your own copy to your Cloudflare account and point every library and the CLI at it. This page describes what the Worker needs and how to deploy it.
What you need
- A Cloudflare account with Workers, D1, KV and Workers AI available.
- Node 20 or newer and pnpm.
- The API source: the
services/apidirectory of the Generic Translation repository. At the time of writing that repository (generic-translation-api) is private, so you need access to it; the libraries and CLI are public.
Bindings and settings
Defined in services/api/wrangler.jsonc:
| Name | Kind | Purpose |
|---|---|---|
DB |
D1 database (generic-translation-db) |
Users, sessions, organizations, projects, keys, strings, translations and history, jobs, files, usage, audit log, webhooks and deliveries, rate limits, and the billing, SSO, SCIM and GitHub tables. Schema in migrations/0001_init.sql and migrations/0002_billing_sso_scim_github.sql. |
CDN |
KV namespace | Published translation maps and manifests, served at /cdn/{projectId}/{locale}.json. Also holds the per-project CDN disabled flag. |
CACHE |
KV namespace (the maintainers call it generic-translation-cache) |
Short-lived state: SSO login state and nonces (10 minutes), cached OIDC discovery documents and signing keys (1 hour) and GitHub installation tokens. Required: SSO and the GitHub agent use it. |
AI |
Workers AI binding | Runs the translation models. |
Cron trigger * * * * * |
Scheduled handler | Resumes unfinished jobs, retries failed webhook deliveries, runs auto-reload and GitHub runs, flushes CDN request counters, and runs housekeeping every 15 minutes. |
nodejs_compat |
Compatibility flag | Required. |
Variables (vars) and secrets:
| Name | Kind | Default | Meaning |
|---|---|---|---|
DEFAULT_MODEL |
var | @cf/zai-org/glm-5.3 |
Model used when a project does not choose one, and the fallback for unknown selections. |
RATE_LIMIT_AUTH_PER_MIN |
var | 30 |
Auth requests per minute per client IP. |
RATE_LIMIT_TRANSLATE_PER_MIN |
var | 300 |
Runtime translate requests per minute per key or user. |
DASHBOARD_URL |
var | https://generic-translation-dashboard.jacobfv123.workers.dev |
Where the SSO callback sends the browser. Set it to your own dashboard’s origin. |
ENCRYPTION_KEY |
secret | none | Derives the AES-256-GCM key that encrypts stored SSO client secrets. Set it before anyone configures SSO. Generate one with openssl rand -base64 48 | npx wrangler secret put ENCRYPTION_KEY. Changing it later makes stored SSO client secrets unreadable, so they must be entered again. |
BILLING_FREE_TOKENS, BILLING_BATCH_RATE_CENTS, BILLING_RUNTIME_RATE_CENTS |
vars | 100000, 2, 4 |
Free source tokens per organization per month, and cents per 1,000 source tokens for batch jobs and runtime translate. They only matter once billing is on. |
STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET |
secrets, optional | none | Set both to switch billing on; see Billing. Without them the instance runs in preview mode: usage is counted, nothing is charged or blocked. |
GITHUB_APP_ID, GITHUB_APP_SLUG, GITHUB_APP_PRIVATE_KEY, GITHUB_WEBHOOK_SECRET |
secrets, optional | none | Set all four to switch the GitHub agent on. |
ANTHROPIC_API_KEY |
secret, optional | none | When set, a project whose model starts with claude- is translated through the Anthropic API; when unset such projects fall back to DEFAULT_MODEL on Workers AI. |
The default configuration needs no secrets except ENCRYPTION_KEY if you want SSO. Per-project model values accepted for Workers AI are @cf/meta/llama-3.3-70b-instruct-fp8-fast, @cf/meta/llama-4-scout-17b-16e-instruct, @cf/mistralai/mistral-small-3.1-24b-instruct, @cf/google/gemma-4-26b-a4b-it, @cf/qwen/qwen3.8-27b, @cf/openai/gpt-oss-120b, @cf/openai/gpt-oss-20b, @cf/deepseek-ai/deepseek-v4.1-flash-1017, @cf/zai-org/glm-5.3, @cf/zai-org/glm-4.7-flash and @cf/thinkingmachines/inkling-2-small. GET / on your API lists the current set. If a Workers AI model is rate limited or erroring, the call is retried once on @cf/meta/llama-3.3-70b-instruct-fp8-fast.
Deploy
The database_id and KV id values in the committed wrangler.jsonc belong to the maintainers’ account. Replace them with your own.
cd services/api
pnpm install
export CLOUDFLARE_ACCOUNT_ID=<your account id>
npx wrangler login
# 1. create the database and the two KV namespaces, then paste the ids into wrangler.jsonc
npx wrangler d1 create generic-translation-db
npx wrangler kv namespace create CDN
npx wrangler kv namespace create CACHE
# 2. apply the schema (both migrations) to the remote database
pnpm migrate:remote # wrangler d1 migrations apply generic-translation-db --remote
# 3. secrets: the encryption key for SSO client secrets, and optionally Claude models
openssl rand -base64 48 | npx wrangler secret put ENCRYPTION_KEY
npx wrangler secret put ANTHROPIC_API_KEY # optional
# 4. set DASHBOARD_URL (and any BILLING_* values) under "vars" in wrangler.jsonc, then deploy
pnpm run deploy # wrangler deploy
Steps 1 to 3 create resources in your account, so check them before running. To check the configuration and bundle without creating or changing anything, run pnpm run build, which is wrangler deploy --dry-run --outdir dist and lists every binding it found. Use pnpm run deploy rather than pnpm deploy: deploy is also the name of a built-in pnpm command in some pnpm versions.
Change name in wrangler.jsonc if you want a different worker name. With workers_dev enabled the API is served at https://<name>.<your-subdomain>.workers.dev. To use a custom domain, add a routes entry as described in the Cloudflare documentation.
Check it:
curl https://<your-worker-url>/health
curl https://<your-worker-url>/openapi.json | head
For local development, pnpm dev runs wrangler dev and pnpm migrate:local applies the schema to the local D1 database. pnpm test runs the test suite.
Optional: turn on billing
Billing stays off until both Stripe secrets exist; before that checkout, the portal and /webhooks/stripe answer 501 billing_not_configured. Set STRIPE_SECRET_KEY (a secret or restricted key) and STRIPE_WEBHOOK_SECRET with npx wrangler secret put, activate the Stripe customer portal once, and add a webhook endpoint at https://<your-worker-url>/webhooks/stripe for checkout.session.completed, checkout.session.async_payment_succeeded, payment_intent.succeeded and payment_intent.payment_failed. Prices are the BILLING_* vars, since Checkout uses inline price data. Test with a Stripe test key first. The Stripe path has been tested against a mocked Stripe only. See Billing.
Optional: register the GitHub App
The GitHub agent needs a GitHub App that you register once per instance, then four secrets: GITHUB_APP_ID, GITHUB_APP_SLUG, GITHUB_APP_PRIVATE_KEY (the PEM GitHub generates; the PKCS#1 BEGIN RSA PRIVATE KEY form is accepted) and GITHUB_WEBHOOK_SECRET. Register the App with:
- repository permissions Contents read and write, Pull requests read and write, Metadata read-only;
- the Push event subscribed (installation events are always delivered);
- webhook URL
https://<your-worker-url>/webhooks/github, with a secret you generate; - callback and setup URL
<your dashboard>/github/setup, with redirect on update ticked; - installable by any account.
Then GET https://<your-worker-url>/v1/github/app returns configured: true with the install URL. An installation can be linked to an organization only within 24 hours of being created or changed, and only to one organization. The step-by-step guide, including a manifest-based registration, is docs/github-app.md in the (private) API repository.
Create the first account
There is no admin console; sign up through the API (or the CLI), which creates your personal organization:
generic-translation login --signup --email you@example.com --name You --api-url https://<your-worker-url>
Then create a project and a key with generic-translation projects create and generic-translation keys create, or use the dashboard. The hosted dashboard at https://generic-translation-dashboard.jacobfv123.workers.dev talks to the hosted API; to use a dashboard against your own API, build and deploy the dashboard from apps/dashboard pointed at your API URL.
Point clients at your API
The base URL is taken from, in order: the explicit option or flag, GENERIC_TRANSLATION_API_URL, then the config, then the hosted default.
export GENERIC_TRANSLATION_API_URL=https://<your-worker-url>
{ "projectId": "prj_…", "baseUrl": "https://<your-worker-url>" }
import { GenericTranslation } from "@generic-translation/core";
const genericTranslation = new GenericTranslation({ baseUrl: "https://<your-worker-url>", projectId, apiKey });
The CDN lives on the same origin: https://<your-worker-url>/cdn/{projectId}/{locale}.json. Libraries that read the CDN (for example @generic-translation/node) use the same baseUrl.
Operating notes
- Published translations are served from KV; the CDN path does not read D1. Publishing writes one KV entry per locale plus a manifest.
- Jobs are advanced by polling
GET /v1/jobs/:jobIdand by the one-minute cron, so keep the cron trigger. - Data is stored in your D1 database: account emails, password hashes, source strings and translations, plus (if you use them) SSO settings with encrypted client secrets, hashed SCIM tokens, billing ledgers and GitHub installation records. You are responsible for backups (
wrangler d1 export), retention, and access control for your instance. - Costs and limits come from your Cloudflare plan (Workers AI, D1, KV, Workers requests). A self-hosted instance runs in preview mode unless you set the Stripe secrets, so by default nothing is metered against anyone and nothing is charged. If you do switch billing on, it is your Stripe account and your prices.
- Upgrading means pulling a newer source, running
pnpm migrate:remotefor any new migrations, thenpnpm run deploy. An instance created before the second migration needs theCACHEnamespace andENCRYPTION_KEYadded before SSO or the GitHub agent will work.
Something wrong or unclear on this page? Open an issue.