REST API

LiteTranslate API

Free Chinese ↔ English translation (Beta). One JSON contract for the anonymous Playground and API-key callers; every response uses the same envelope `{ code, message, data }`.

Updated 2026-11-08

Quick start

Translate anonymously (no key; per-IP quota 10/hour):

curl -X POST https://translate.litelake.com/api/public/translate \
  -H "Content-Type: application/json" \
  -d '{"text":"你好,世界","source":"auto","target":"en"}'

Translate with an API key (per-user quota 100/hour):

curl -X POST https://translate.litelake.com/api/open/translate \
  -H "X-API-Key: ltr_prod_xxx" \
  -H "Content-Type: application/json" \
  -d '{"text":"你好,世界","source":"auto","target":"en","format":"text"}'

Authentication

CallerEndpointCredentialQuota counted
Anonymous PlaygroundPOST /api/public/translatenone (rate-limited per IP)per IP: 10/hour + 5/minute
API keyPOST /api/open/translateX-API-Key: ltr_{env}_{32hex} headerkey owner: 100/hour + 20/minute

Keys are issued on the Account page (3 active per user) and shown once. A revoked or unknown key always returns 401 with code 40101 — the API never degrades to anonymous access.

Endpoints

POST /api/open/translate

The data-plane translation endpoint.

Request body:

FieldTypeDescription
textstringText to translate. 1–5000 characters; longer input → 40021.
sourcezh / en / autoSource language. Default auto (CJK ratio ≥ 30% → zh).
targetzh / enTarget language. Required; must differ from an explicit source (else 40022).
formattext / markdownOutput mode. Default text. See Markdown mode below.

Response data:

FieldTypeDescription
translationstringThe translated text.
detected_sourcezh / enResult of detection when source=auto.
char_countnumberCharacter count of the input.
formattext / markdownEcho of the requested format.
usageobject{ channel, used_this_hour, limit_this_hour, reset_at } — quota snapshot after this call.

GET /api/open/languages

{ "languages": [{ "code": "zh" }, { "code": "en" }], "formats": ["text", "markdown"] }

GET /api/open/usage

Quota snapshot for the calling key: { channel, used_this_hour, limit_this_hour, remaining_this_hour, reset_at, tier, key_prefix }. Super keys (ltrs_ prefix) return limit_this_hour: 0 meaning unlimited.

GET /api/public/info

Product info plus the current IP's anonymous quota status (Playground use).

GET /api/user/usage?window=hour|day

Signed-in user usage (session cookie): { window, used, limit, remaining, reset_at }. hour resets on the hour; day is calendar-day bucketed and uncapped in Beta (limit: 0).

Rate-limit headers

Every translation response carries:

HeaderMeaning
X-RateLimit-LimitQuota bucket size for this call (100 user / 10 anonymous).
X-RateLimit-RemainingCalls left in the current hourly window.
X-RateLimit-ResetUnix time when the window resets.
Retry-AfterSeconds to wait — present on 429 responses only.

Markdown mode

Set "format": "markdown" to preserve document structure. The server counts fenced code blocks (```/~~~), links [text](url) and images ![alt](url) before and after translation. If counts drift, it retries once; if the structure still does not match, it returns 500 / 50023 and does not count the call — switch to text for that input.

Counting rules

Only successful translations are counted. Parameter errors (400xx), auth failures, upstream errors (50021/50022), Markdown structure rejections (50023) and storage-unavailable responses (50024) are free of charge.

Error codes

HTTPCodeMeaningWhat to do
40040001Invalid parametersCheck required fields (text, target) and format value.
40040021Text too longSplit the input at 5000 characters.
40040022Unsupported language pairOnly Chinese ↔ English; source must differ from target.
40140101API key invalid / revoked / expiredIssue a new key on the Account page.
40140102Not signed inThe /api/user/* endpoint needs a UC session.
40340301User bannedContact support via the Contact page.
42942901Quota exceededWait for Retry-After seconds; reset times are in the headers.
50050021Upstream errorRetry with backoff; the call was not counted.
50450022Upstream timeout (180s)Retry with a shorter text; the call was not counted.
50050023Markdown structure check failedUse format: "text"; the call was not counted.
50350024Quota storage unavailableFail-closed protection — retry in a moment.

Agent Skill

Prefer a CLI? Install the Agent Skill from the Skill page — it wraps this API with the same error codes and adds an offline self-check.

Get an API key

Sign in and issue a free key on the account page — the key inherits your 100/hour quota. Open the account page