API documentation
Translation Cloud API v1: a JSON REST API that answers from Translation Memory first and uses AI only for texts it has never seen.
https://translator.coreinfra.eu/api/v1
Version v1 is stable: its behaviour does not change. New features arrive as optional parameters or as /api/v2.
Getting started
Every request is authenticated with a project API key and sends JSON. The API answers from Translation Memory whenever it can; texts it does not know yet are queued, translated by AI once and stored for good.
- Create a free account and a project in the panel.
- Generate an API key (Project → API keys). The full key is shown only once.
- Send POST /translate. HTTP 200 = translation ready, HTTP 202 = queued (arrives by webhook or polling).
- Optionally add a webhook URL to receive translation.completed events.
curl -X POST "https://translator.coreinfra.eu/api/v1/translate" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Dodaj produkt do koszyka", "source_lang": "pl", "target_lang": "en"}'
<?php
$ch = curl_init('https://translator.coreinfra.eu/api/v1/translate');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('TC_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'text' => 'Dodaj produkt do koszyka',
'source_lang' => 'pl',
'target_lang' => 'en',
]),
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status === 200) {
echo $body['translation']; // "Add product to cart"
} elseif ($status === 202) {
// Pending: show the original text, the result arrives by webhook
$id = $body['translation_id'];
}
const res = await fetch("https://translator.coreinfra.eu/api/v1/translate", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TC_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ text: "Dodaj produkt do koszyka", source_lang: "pl", target_lang: "en" }),
});
const data = await res.json();
if (res.status === 200) console.log(data.translation); // "Add product to cart"
if (res.status === 202) console.log("pending", data.translation_id, data.retry_after);
import os, requests
r = requests.post(
"https://translator.coreinfra.eu/api/v1/translate",
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
json={"text": "Dodaj produkt do koszyka", "source_lang": "pl", "target_lang": "en"},
timeout=10,
)
data = r.json()
if r.status_code == 200:
print(data["translation"]) # "Add product to cart"
elif r.status_code == 202:
print("pending", data["translation_id"], data["retry_after"])
One text = one request, also inside a batch. Answers from memory never consume AI characters.
Authentication
Send the key in the Authorization header as a Bearer token (recommended) or in the X-API-Key header. Keys are accepted only in headers — never in the URL or body, so they do not end up in server logs or browser history.
# Recommended
Authorization: Bearer tc_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Alternative
X-API-Key: tc_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
tc_live_…— Live key (tc_live_…) — production traffic, counted towards your plan.tc_test_…— Test key (tc_test_…) — for development: lower default rate limit (30 requests/minute), responses carry "livemode": false, memory import is not allowed.
Each key belongs to one project. You can restrict it to IP addresses, set an expiry date and a per-key rate limit, revoke or regenerate it in the panel.
Never use the API key in browser JavaScript or a mobile app. Call the API from your backend (or the WordPress plugin).
Translate
/api/v1/translateTranslates a single text. The response depends on whether the text is already in memory.
| Field | Type | Description |
|---|---|---|
textrequired | string | Text to translate (plain text or HTML fragment). Maximum length depends on your plan. |
source_langoptional | string | Source language code (e.g. "pl"). Defaults to the project’s default source language. |
target_langrequired | string | Target language code (e.g. "en"). Must be active. |
contextoptional | string | Short context that distinguishes identical texts, e.g. "checkout", "button". Part of the memory key; a match without context is used as a fallback. |
domainoptional | string | Optional domain (e.g. "legal", "shop") — separate memory entries per domain. |
typeoptional | string | Hint for AI about the kind of text, e.g. "ui", "email", "product". |
callback_urloptional | string (https) | HTTPS URL that receives the webhook for this particular text (in addition to project webhooks). |
Statuses and HTTP codes
HTTP 200 — translation ready. Use it right away.
HTTP 202 — queued. Show the original text; the translation arrives by webhook or polling.
HTTP 202 — the AI is translating the text right now.
HTTP 200 with status "failed" — translation failed after all retries. HTTP 429 with error AI_QUOTA_EXCEEDED when the AI character quota is exhausted.
Response: found in memory (200)
{
"status": "found",
"translation": "Add product to cart",
"cached": true,
"source": "global_memory",
"match": "exact",
"translation_id": "c6b8c562-01c4-4bd1-b78a-8b2946d2b2a2",
"quality": { "origin": "global", "reviewed": true, "confidence": 100 },
"livemode": true
}
Response: queued (202)
HTTP/1.1 202 Accepted
Retry-After: 60
{
"translation_id": "2028a8a7-df11-4325-9ccc-2af16c74b084",
"status": "pending",
"translation": null,
"cached": false,
"retry_after": 60
}
Response fields
| Field | Description |
|---|---|
status | found, pending, processing or failed. |
translation | Translated text (null while pending). |
cached | true when the answer comes from memory. |
source | Where the answer came from: project_memory, global_memory, glossary or identity (same language / empty text). |
match | exact, context_fallback (same text without context), numbers (same words, different numbers — the request numbers are inserted into the translation), similar (normalized match) or segments (text assembled from stored sentences). |
translation_id | Identifier to use with GET /translations/{id} and in webhooks. |
quality | origin (ai, human, global, import), reviewed (bool), confidence (0–100). |
retry_after | Seconds after which it makes sense to check the status (also in the Retry-After header). |
Batch
/api/v1/translations/batchTranslates many texts in one call. Known texts return at once; the rest are queued together. The maximum number of items per call depends on your plan (BATCH_TOO_LARGE otherwise).
Send an object with "items" (each item: text, optional id, context, and per-item overrides) and shared defaults, or a bare array of strings with source_lang and target_lang in the query string.
curl -X POST "https://translator.coreinfra.eu/api/v1/translations/batch" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_lang": "pl",
"target_lang": "en",
"context": "checkout",
"items": [
{"id": "cart", "text": "Koszyk"},
{"id": "save", "text": "Zapisz"}
]
}'
# Short form: a bare array + languages in the query string
curl -X POST "https://translator.coreinfra.eu/api/v1/translations/batch?source_lang=pl&target_lang=en" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '["Szukaj", "Kontakt"]'
<?php
$payload = [
'source_lang' => 'pl',
'target_lang' => 'en',
'items' => [
['id' => 'cart', 'text' => 'Koszyk'],
['id' => 'save', 'text' => 'Zapisz'],
],
];
$ch = curl_init('https://translator.coreinfra.eu/api/v1/translations/batch');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TC_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$res = json_decode(curl_exec($ch), true);
foreach ($res['items'] as $item) {
echo $item['id'], ': ', $item['status'] === 'found' ? $item['translation'] : '(pending)', PHP_EOL;
}
const res = await fetch("https://translator.coreinfra.eu/api/v1/translations/batch", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.TC_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
source_lang: "pl",
target_lang: "en",
items: [{ id: "cart", text: "Koszyk" }, { id: "save", text: "Zapisz" }],
}),
});
const { items, summary } = await res.json();
console.log(summary); // { total: 2, found: 2, pending: 0, ... }
r = requests.post(
"https://translator.coreinfra.eu/api/v1/translations/batch",
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
json={
"source_lang": "pl",
"target_lang": "en",
"items": [{"id": "cart", "text": "Koszyk"}, {"id": "save", "text": "Zapisz"}],
},
timeout=15,
)
for item in r.json()["items"]:
print(item["id"], item["status"], item.get("translation"))
Your "id" is echoed in the response so you can match results. Each text counts as one request.
Response
{
"items": [
{
"id": "cart",
"status": "found",
"translation": "Cart",
"cached": true,
"source": "global_memory",
"match": "exact",
"translation_id": "8c9f22cb-3371-46fe-bcf9-b24b95b98b07",
"quality": { "origin": "global", "reviewed": true, "confidence": 100 }
},
{
"id": "new-1",
"translation_id": "5b0e2c1a-7d44-4f7e-9f5e-0c1f3d2a9b10",
"status": "pending",
"translation": null,
"cached": false,
"retry_after": 60
}
],
"summary": { "total": 2, "found": 1, "pending": 1, "processing": 0, "failed": 0, "error": 0 },
"livemode": true
}
Translation status
/api/v1/translations/{id}Returns the current state of a translation by translation_id. Only translations of the key’s project are visible.
curl "https://translator.coreinfra.eu/api/v1/translations/2028a8a7-df11-4325-9ccc-2af16c74b084" \
-H "Authorization: Bearer $TC_API_KEY"
<?php
$ch = curl_init('https://translator.coreinfra.eu/api/v1/translations/' . $translationId);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TC_API_KEY')],
]);
$t = json_decode(curl_exec($ch), true);
if ($t['status'] === 'found') { echo $t['translation']; }
const res = await fetch(`https://translator.coreinfra.eu/api/v1/translations/${translationId}`, {
headers: { "Authorization": `Bearer ${process.env.TC_API_KEY}` },
});
const t = await res.json();
if (t.status === "found") console.log(t.translation);
r = requests.get(
f"https://translator.coreinfra.eu/api/v1/translations/{translation_id}",
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
timeout=10,
)
t = r.json()
if t["status"] == "found":
print(t["translation"])
{
"translation_id": "2028a8a7-df11-4325-9ccc-2af16c74b084",
"status": "found",
"source_lang": "pl",
"target_lang": "en",
"text": "Zamów teraz za {price} zł",
"translation": "Order now for {price} PLN",
"created_at": "2026-09-30T12:39:57Z",
"completed_at": "2026-09-30T12:40:03Z",
"cached": true,
"memory_id": "ed7c6604-4707-47a3-babf-0752d7373ebb",
"quality": { "origin": "ai", "reviewed": false, "confidence": 78 }
}
{
"translation_id": "2028a8a7-df11-4325-9ccc-2af16c74b084",
"status": "failed",
"translation": null,
"error": { "code": "TRANSLATION_FAILED", "message": "Translation failed" }
}
Poll no more often than Retry-After says — or better, use webhooks.
Translation Memory
Translation Memory is the heart of the service. Every translation is stored with its version history, origin and quality score.
How a text is matched
- Normalization: Unicode form (NFC), whitespace including non-breaking spaces, line endings and HTML tag case are unified, so trivial differences do not create new entries. Similar match additionally ignores letter case and trailing punctuation.
- Placeholders ({name}, {{count}}, %s, :price, HTML tags and entities) are replaced with locked tokens before AI and must be present in the result.
- Lookup order: Project Memory (exact, then without context) → Global Memory → similar match → AI queue.
- Entries reviewed by a human are never overwritten by AI.
Export: GET /memory
/api/v1/memory?source_lang&target_lang&updated_since&cursor&limitDownload project memory in pages (limit up to 1000, next_cursor) to keep a local cache — a page that is already translated then needs no API call at all. Filter with source_lang, target_lang and updated_since for incremental syncs.
# First page
curl "https://translator.coreinfra.eu/api/v1/memory?source_lang=pl&target_lang=en&limit=500" \
-H "Authorization: Bearer $TC_API_KEY"
# Next page: pass next_cursor; incremental sync: updated_since
curl "https://translator.coreinfra.eu/api/v1/memory?cursor=136&updated_since=2026-09-01T00:00:00Z" \
-H "Authorization: Bearer $TC_API_KEY"
<?php
// Sync project memory to a local key-value cache (e.g. APCu, Redis, a JSON file)
$cursor = 0;
do {
$url = 'https://translator.coreinfra.eu/api/v1/memory?' . http_build_query(['target_lang' => 'en', 'limit' => 1000, 'cursor' => $cursor]);
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TC_API_KEY')]]);
$page = json_decode(curl_exec($ch), true);
foreach ($page['items'] as $row) {
$cache[$row['source_lang'] . ':' . $row['target_lang'] . ':' . $row['text']] = $row['translation'];
}
$cursor = $page['next_cursor'];
} while ($cursor !== null);
const cache = new Map();
let cursor = 0;
do {
const url = `https://translator.coreinfra.eu/api/v1/memory?target_lang=en&limit=1000&cursor=${cursor}`;
const page = await (await fetch(url, { headers: { "Authorization": `Bearer ${process.env.TC_API_KEY}` } })).json();
for (const row of page.items) cache.set(`${row.source_lang}:${row.target_lang}:${row.text}`, row.translation);
cursor = page.next_cursor;
} while (cursor !== null);
cache, cursor = {}, 0
while cursor is not None:
page = requests.get(
"https://translator.coreinfra.eu/api/v1/memory",
params={"target_lang": "en", "limit": 1000, "cursor": cursor},
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
timeout=30,
).json()
for row in page["items"]:
cache[f"{row['source_lang']}:{row['target_lang']}:{row['text']}"] = row["translation"]
cursor = page["next_cursor"]
{
"items": [
{
"id": "ef602640-61d9-47f7-a7f5-9e66562e10f2",
"source_lang": "pl",
"target_lang": "en",
"context": "",
"text": "Witaj {{name}}, masz {{count}} produktów w koszyku.",
"translation": "Hello {{name}}, you have {{count}} products in your cart.",
"origin": "ai",
"reviewed": false,
"updated_at": "2026-09-30T12:27:34Z"
}
],
"next_cursor": 136
}
Import: POST /memory
/api/v1/memoryLoad existing translations (e.g. from .po or JSON files) — up to 500 items per request, live key only. Imported entries are served from memory immediately.
curl -X POST "https://translator.coreinfra.eu/api/v1/memory" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_lang": "pl",
"target_lang": "en",
"items": [
{"text": "Moje zamówienia", "translation": "My orders"},
{"text": "Zamów", "translation": "Place order", "context": "checkout"}
]
}'
# HTTP 201
{ "result": { "created": 2, "updated": 0, "skipped": 0, "invalid": 0 } }
Usage
/api/v1/usageReturns usage in the current billing period for the account and the key’s project, including the cache hit rate.
curl "https://translator.coreinfra.eu/api/v1/usage" -H "Authorization: Bearer $TC_API_KEY"
{
"period": { "start": "2026-09-30T12:20:45Z", "end": "2026-10-14T12:20:45Z" },
"plan": { "name": "Business", "slug": "business", "overage_enabled": false },
"account": {
"requests": { "used": 15, "limit": 50000 },
"ai_characters": { "used": 118, "limit": 100000 }
},
"project": {
"requests": 15,
"batch_requests": 3,
"cache_hits": 10,
"cache_misses": 4,
"cache_hit_rate": 66.67
}
}
Languages
/api/v1/languagesReturns active languages and the languages configured for the key’s project. Use it instead of hard-coding codes: new languages are switched on without changes to the API.
curl "https://translator.coreinfra.eu/api/v1/languages" -H "Authorization: Bearer $TC_API_KEY"
{
"languages": [
{ "code": "en", "name": "English", "native_name": "English", "direction": "ltr" },
{ "code": "pl", "name": "Polish", "native_name": "Polski", "direction": "ltr" }
],
"project": {
"default_source_lang": "pl",
"languages": [
{ "code": "en", "source": false, "target": true },
{ "code": "pl", "source": true, "target": false }
]
}
}
Webhooks
Webhooks push results to your server so you never have to poll. Configure URLs per project in the panel or pass callback_url with a request.
Events
translation.completed | A queued translation is ready (also when it was completed from memory in the meantime). |
translation.failed | A translation failed after all retries. |
webhook.test | Test delivery sent from the panel or POST /webhooks/test. |
Headers
X-TC-Event | Event name. |
X-TC-Delivery | Unique delivery id — use it to ignore duplicates. |
X-TC-Signature | t=<unix time>,v1=<hex(HMAC-SHA256(secret, t + "." + body))> |
POST /your/webhook HTTP/1.1
Content-Type: application/json
X-TC-Event: translation.completed
X-TC-Delivery: 4812
X-TC-Signature: t=1790772003,v1=5f2b9c…e41a
Payload: translation.completed
{
"event": "translation.completed",
"translation_id": "2028a8a7-df11-4325-9ccc-2af16c74b084",
"memory_id": "ed7c6604-4707-47a3-babf-0752d7373ebb",
"project_id": "0b6f3f9e-5a0c-4c1b-8a57-3c2d1e9f7a21",
"source_lang": "pl",
"target_lang": "en",
"text": "Zamów teraz za {price} zł",
"translation": "Order now for {price} PLN",
"context": "checkout",
"created_at": "2026-09-30T12:40:03Z"
}
Payload: translation.failed
{
"event": "translation.failed",
"translation_id": "2028a8a7-df11-4325-9ccc-2af16c74b084",
"source_lang": "pl",
"target_lang": "en",
"error": { "code": "TRANSLATION_FAILED", "message": "Translation failed" },
"created_at": "2026-09-30T13:02:11Z"
}
Verifying the signature
Compute the HMAC over the raw request body with your project’s webhook secret (panel → Webhooks), compare in constant time and reject deliveries older than 5 minutes.
<?php
$secret = getenv('TC_WEBHOOK_SECRET');
$body = file_get_contents('php://input'); // raw body, before json_decode
$header = $_SERVER['HTTP_X_TC_SIGNATURE'] ?? '';
if (!preg_match('/^t=(\d+),v1=([a-f0-9]{64})$/', $header, $m)
|| abs(time() - (int) $m[1]) > 300 // reject old deliveries (replay)
|| !hash_equals(hash_hmac('sha256', $m[1] . '.' . $body, $secret), $m[2])) {
http_response_code(400);
exit;
}
$event = json_decode($body, true);
// … save $event['translation'] under $event['translation_id']
http_response_code(200);
// Node.js (Express): use the raw body for the signature
import crypto from "node:crypto";
import express from "express";
const app = express();
app.post("/webhooks/tc", express.raw({ type: "application/json" }), (req, res) => {
const m = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(req.get("X-TC-Signature") || "");
if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return res.sendStatus(400);
const expected = crypto.createHmac("sha256", process.env.TC_WEBHOOK_SECRET)
.update(`${m[1]}.${req.body}`).digest("hex");
if (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(m[2]))) return res.sendStatus(400);
const event = JSON.parse(req.body);
res.sendStatus(200);
});
import hmac, hashlib, os, re, time
from flask import Flask, request, abort
app = Flask(__name__)
@app.post("/webhooks/tc")
def tc_webhook():
body = request.get_data() # raw bytes
m = re.fullmatch(r"t=(\d+),v1=([a-f0-9]{64})", request.headers.get("X-TC-Signature", ""))
if not m or abs(time.time() - int(m[1])) > 300:
abort(400)
expected = hmac.new(os.environ["TC_WEBHOOK_SECRET"].encode(), m[1].encode() + b"." + body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, m[2]):
abort(400)
event = request.get_json()
return "", 200
Retries
Respond with any 2xx status within a few seconds. Otherwise the delivery is retried after 1, 5, 15, 60 and 360 minutes; the log of every attempt is visible in the panel.
Test: POST /webhooks/test
Sends a webhook.test event to the project’s active webhooks, or to the https URL given in the body.
curl -X POST "https://translator.coreinfra.eu/api/v1/webhooks/test" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/webhooks/tc"}'
SDKs & plugins
The API is plain HTTPS + JSON, so any HTTP client works. Below are reference clients in one file each — copy them into your project.
PHP
PHP 8.1+, ext-curl, no Composer dependencies.
JavaScript / Node.js
Node.js 18+ (built-in fetch). Server-side only.
Python
Python 3.8+ with requests.
WordPress plugin
Available in the panel for the Start plan and above. It translates theme and plugin strings through the API and keeps a local cache synced with GET /memory.
<?php
final class TranslationCloud
{
public function __construct(private string $key, private string $base = 'https://translator.coreinfra.eu/api/v1') {}
public function translate(string $text, string $to, string $from = 'pl', array $opt = []): array
{
return $this->call('POST', '/translate', ['text' => $text, 'source_lang' => $from, 'target_lang' => $to] + $opt);
}
public function batch(array $items, string $to, string $from = 'pl'): array
{
return $this->call('POST', '/translations/batch', ['items' => $items, 'source_lang' => $from, 'target_lang' => $to]);
}
public function status(string $id): array
{
return $this->call('GET', '/translations/' . rawurlencode($id));
}
private function call(string $method, string $path, ?array $body = null): array
{
$ch = curl_init($this->base . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $this->key, 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => $body !== null ? json_encode($body) : null,
]);
$json = json_decode((string) curl_exec($ch), true) ?? [];
return ['http' => curl_getinfo($ch, CURLINFO_HTTP_CODE)] + $json;
}
}
$tc = new TranslationCloud(getenv('TC_API_KEY'));
echo $tc->translate('Koszyk', 'en')['translation']; // "Cart"
export class TranslationCloud {
constructor(key, base = "https://translator.coreinfra.eu/api/v1") { this.key = key; this.base = base; }
async call(method, path, body) {
const res = await fetch(this.base + path, {
method,
headers: { "Authorization": `Bearer ${this.key}`, "Content-Type": "application/json" },
body: body ? JSON.stringify(body) : undefined,
});
return { http: res.status, ...(await res.json()) };
}
translate(text, to, from = "pl", opt = {}) { return this.call("POST", "/translate", { text, source_lang: from, target_lang: to, ...opt }); }
batch(items, to, from = "pl") { return this.call("POST", "/translations/batch", { items, source_lang: from, target_lang: to }); }
status(id) { return this.call("GET", `/translations/${encodeURIComponent(id)}`); }
}
const tc = new TranslationCloud(process.env.TC_API_KEY);
console.log((await tc.translate("Koszyk", "en")).translation); // "Cart"
import os, requests
class TranslationCloud:
def __init__(self, key, base="https://translator.coreinfra.eu/api/v1"):
self.base = base
self.s = requests.Session()
self.s.headers["Authorization"] = f"Bearer {key}"
def _call(self, method, path, body=None):
r = self.s.request(method, self.base + path, json=body, timeout=15)
return {"http": r.status_code, **r.json()}
def translate(self, text, to, src="pl", **opt):
return self._call("POST", "/translate", {"text": text, "source_lang": src, "target_lang": to, **opt})
def batch(self, items, to, src="pl"):
return self._call("POST", "/translations/batch", {"items": items, "source_lang": src, "target_lang": to})
def status(self, translation_id):
return self._call("GET", f"/translations/{translation_id}")
tc = TranslationCloud(os.environ["TC_API_KEY"])
print(tc.translate("Koszyk", "en")["translation"]) # "Cart"
Examples
Complete examples of the most common task: translate a text and handle both answers. Switch the language tab — your choice is remembered on all code blocks.
curl -X POST "https://translator.coreinfra.eu/api/v1/translate" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Dodaj produkt do koszyka", "source_lang": "pl", "target_lang": "en"}'
<?php
$ch = curl_init('https://translator.coreinfra.eu/api/v1/translate');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('TC_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'text' => 'Dodaj produkt do koszyka',
'source_lang' => 'pl',
'target_lang' => 'en',
]),
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status === 200) {
echo $body['translation']; // "Add product to cart"
} elseif ($status === 202) {
// Pending: show the original text, the result arrives by webhook
$id = $body['translation_id'];
}
const res = await fetch("https://translator.coreinfra.eu/api/v1/translate", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TC_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ text: "Dodaj produkt do koszyka", source_lang: "pl", target_lang: "en" }),
});
const data = await res.json();
if (res.status === 200) console.log(data.translation); // "Add product to cart"
if (res.status === 202) console.log("pending", data.translation_id, data.retry_after);
import os, requests
r = requests.post(
"https://translator.coreinfra.eu/api/v1/translate",
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
json={"text": "Dodaj produkt do koszyka", "source_lang": "pl", "target_lang": "en"},
timeout=10,
)
data = r.json()
if r.status_code == 200:
print(data["translation"]) # "Add product to cart"
elif r.status_code == 202:
print("pending", data["translation_id"], data["retry_after"])
Batch
curl -X POST "https://translator.coreinfra.eu/api/v1/translations/batch" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_lang": "pl",
"target_lang": "en",
"context": "checkout",
"items": [
{"id": "cart", "text": "Koszyk"},
{"id": "save", "text": "Zapisz"}
]
}'
# Short form: a bare array + languages in the query string
curl -X POST "https://translator.coreinfra.eu/api/v1/translations/batch?source_lang=pl&target_lang=en" \
-H "Authorization: Bearer $TC_API_KEY" \
-H "Content-Type: application/json" \
-d '["Szukaj", "Kontakt"]'
<?php
$payload = [
'source_lang' => 'pl',
'target_lang' => 'en',
'items' => [
['id' => 'cart', 'text' => 'Koszyk'],
['id' => 'save', 'text' => 'Zapisz'],
],
];
$ch = curl_init('https://translator.coreinfra.eu/api/v1/translations/batch');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TC_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$res = json_decode(curl_exec($ch), true);
foreach ($res['items'] as $item) {
echo $item['id'], ': ', $item['status'] === 'found' ? $item['translation'] : '(pending)', PHP_EOL;
}
const res = await fetch("https://translator.coreinfra.eu/api/v1/translations/batch", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.TC_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
source_lang: "pl",
target_lang: "en",
items: [{ id: "cart", text: "Koszyk" }, { id: "save", text: "Zapisz" }],
}),
});
const { items, summary } = await res.json();
console.log(summary); // { total: 2, found: 2, pending: 0, ... }
r = requests.post(
"https://translator.coreinfra.eu/api/v1/translations/batch",
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
json={
"source_lang": "pl",
"target_lang": "en",
"items": [{"id": "cart", "text": "Koszyk"}, {"id": "save", "text": "Zapisz"}],
},
timeout=15,
)
for item in r.json()["items"]:
print(item["id"], item["status"], item.get("translation"))
Polling a pending translation
curl "https://translator.coreinfra.eu/api/v1/translations/2028a8a7-df11-4325-9ccc-2af16c74b084" \
-H "Authorization: Bearer $TC_API_KEY"
<?php
$ch = curl_init('https://translator.coreinfra.eu/api/v1/translations/' . $translationId);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TC_API_KEY')],
]);
$t = json_decode(curl_exec($ch), true);
if ($t['status'] === 'found') { echo $t['translation']; }
const res = await fetch(`https://translator.coreinfra.eu/api/v1/translations/${translationId}`, {
headers: { "Authorization": `Bearer ${process.env.TC_API_KEY}` },
});
const t = await res.json();
if (t.status === "found") console.log(t.translation);
r = requests.get(
f"https://translator.coreinfra.eu/api/v1/translations/{translation_id}",
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
timeout=10,
)
t = r.json()
if t["status"] == "found":
print(t["translation"])
Syncing memory to a local cache
# First page
curl "https://translator.coreinfra.eu/api/v1/memory?source_lang=pl&target_lang=en&limit=500" \
-H "Authorization: Bearer $TC_API_KEY"
# Next page: pass next_cursor; incremental sync: updated_since
curl "https://translator.coreinfra.eu/api/v1/memory?cursor=136&updated_since=2026-09-01T00:00:00Z" \
-H "Authorization: Bearer $TC_API_KEY"
<?php
// Sync project memory to a local key-value cache (e.g. APCu, Redis, a JSON file)
$cursor = 0;
do {
$url = 'https://translator.coreinfra.eu/api/v1/memory?' . http_build_query(['target_lang' => 'en', 'limit' => 1000, 'cursor' => $cursor]);
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TC_API_KEY')]]);
$page = json_decode(curl_exec($ch), true);
foreach ($page['items'] as $row) {
$cache[$row['source_lang'] . ':' . $row['target_lang'] . ':' . $row['text']] = $row['translation'];
}
$cursor = $page['next_cursor'];
} while ($cursor !== null);
const cache = new Map();
let cursor = 0;
do {
const url = `https://translator.coreinfra.eu/api/v1/memory?target_lang=en&limit=1000&cursor=${cursor}`;
const page = await (await fetch(url, { headers: { "Authorization": `Bearer ${process.env.TC_API_KEY}` } })).json();
for (const row of page.items) cache.set(`${row.source_lang}:${row.target_lang}:${row.text}`, row.translation);
cursor = page.next_cursor;
} while (cursor !== null);
cache, cursor = {}, 0
while cursor is not None:
page = requests.get(
"https://translator.coreinfra.eu/api/v1/memory",
params={"target_lang": "en", "limit": 1000, "cursor": cursor},
headers={"Authorization": f"Bearer {os.environ['TC_API_KEY']}"},
timeout=30,
).json()
for row in page["items"]:
cache[f"{row['source_lang']}:{row['target_lang']}:{row['text']}"] = row["translation"]
cursor = page["next_cursor"]
Errors
Errors always use the same JSON shape and an appropriate HTTP status. Branch on error.code — messages may change.
HTTP/1.1 422 Unprocessable Entity
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"details": { "fields": { "text": "The \"text\" field is required and must be a string" } }
}
}
| Code | HTTP | Meaning |
|---|---|---|
INVALID_JSON | 400 | The request body is not valid JSON. |
UNAUTHORIZED | 401 | No API key in the request. |
INVALID_API_KEY | 401 | The key does not exist. |
API_KEY_REVOKED | 401 | The key has been revoked. |
API_KEY_EXPIRED | 401 | The key has expired. |
ACCOUNT_SUSPENDED | 403 | The account is suspended (e.g. unpaid invoice). |
PROJECT_INACTIVE | 403 | The project is paused or deleted. |
IP_NOT_ALLOWED | 403 | The request comes from an IP outside the key’s allowlist. |
TEST_KEY_FORBIDDEN | 403 | The operation requires a live key. |
NOT_FOUND | 404 | The resource does not exist (or belongs to another project). |
PAYLOAD_TOO_LARGE | 413 | The request body is too large. |
VALIDATION_ERROR | 422 | Invalid or missing fields — see details.fields. |
BATCH_TOO_LARGE | 422 | More items than your plan allows — see details.max_batch_size. |
TEXT_TOO_LONG | 422 | The text exceeds the per-text character limit of your plan. |
UNSUPPORTED_LANGUAGE | 422 | The language code is unknown or inactive. |
INVALID_CALLBACK_URL | 422 | callback_url must be a valid https:// URL. |
RATE_LIMITED | 429 | Too many requests per minute — wait Retry-After seconds. |
PLAN_LIMIT_REACHED | 429 | Monthly request limit reached — upgrade or enable additional usage. |
AI_QUOTA_EXCEEDED | 429 | AI character quota exhausted; texts from memory still work. |
INTERNAL_ERROR | 500 | Unexpected server error — it has been logged. Retry later. |
SERVICE_UNAVAILABLE | 503 | Temporary unavailability (e.g. database). Retry with backoff. |
In a batch, per-item problems (e.g. TEXT_TOO_LONG, UNSUPPORTED_LANGUAGE) are returned inside that item with status "error"; the rest of the batch is processed normally.
Rate limits
Limits apply per API key, per project and per account (plan). Every response carries the headers below; when a limit is exceeded you receive HTTP 429 RATE_LIMITED.
| Header | Description |
|---|---|
X-RateLimit-Limit | Requests allowed in the current one-minute window. |
X-RateLimit-Remaining | Requests left in the window. |
X-RateLimit-Reset | Unix time when the window resets. |
Retry-After | Seconds to wait (on 429 and 202 responses). |
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 1200
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1790772060
Retry-After: 42
{
"error": {
"code": "RATE_LIMITED",
"message": "Too many requests. Slow down and retry after the reset time.",
"details": { "limit": 1200, "scope": "c" }
}
}
Back off using Retry-After, add jitter, and prefer batch requests for bulk work. The monthly plan limit (PLAN_LIMIT_REACHED) is separate from the per-minute rate limit.