Ein Endpunkt. JSON rein, Übersetzung raus.
Authentifizieren Sie sich mit einem Bearer-Schlüssel, senden Sie einen Text, erhalten Sie eine Übersetzung. Bekannte Texte werden mit HTTP 200 aus dem Gedächtnis beantwortet; neue liefern 202 und kommen per Webhook.
Ihre erste Anfrage
Kopieren, Schlüssel einfügen, ausführen.
{
"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
}
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"])
Drei Antworten, die Sie behandeln müssen
Im Gedächtnis gefunden — verwenden Sie die Übersetzung sofort.
Neuer Text in der Warteschlange — zeigen Sie das Original an, warten Sie auf den Webhook oder fragen Sie nach Retry-After erneut ab.
Rate- oder Tariflimit — warten Sie gemäß Retry-After und X-RateLimit-Reset.
Endpunkte
| Endpunkt | Zweck |
|---|---|
POST/api/v1/translate | Einen Text übersetzen |
POST/api/v1/translations/batch | Viele Texte in einem Aufruf übersetzen |
GET/api/v1/translations/{id} | Status einer ausstehenden Übersetzung |
GET/api/v1/memory | Gedächtnis in einen lokalen Cache exportieren (Cursor) |
POST/api/v1/memory | Vorhandene Übersetzungen importieren |
GET/api/v1/languages | Aktive Sprachen und Projektsprachen |
GET/api/v1/usage | Nutzung im aktuellen Zeitraum und Trefferquote |
POST/api/v1/webhooks/test | Test-Webhook senden |
Webhooks, denen Sie vertrauen können
Ergebnisse werden mit HMAC-SHA256-Signatur, einer Zustellungs-ID und automatischen Wiederholungen nach 1, 5, 15, 60 und 360 Minuten an Ihren Endpunkt gesendet.
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
<?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
Funktioniert mit jeder Programmiersprache
Einfaches HTTPS und JSON. Referenz-Clients für PHP, JavaScript und Python passen in eine Datei; für WordPress gibt es ein Plugin.
- PHP 8
- JavaScript
- Node.js
- Python
- WordPress
- cURL
Zahlen Sie nicht zweimal für denselben Satz.
Erstellen Sie ein kostenloses Konto, holen Sie sich einen API-Schlüssel und senden Sie Ihre erste Anfrage in wenigen Minuten.