POST /translate
Translate a text string using the Translation API.
POST /translate
Translate a text string. Requires authentication.
Request
POST /api/v1/translate
Authorization: Bearer opt_your-token
Content-Type: application/json
{
"text": "Bonjour le monde",
"source_lang": "fr",
"target_lang": "en-US",
"workspace": "my-workspace",
"project_slug": "marketing"
}Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | Text to translate. Max 5,000 characters. |
target_lang | string | No | Target language code. Defaults to en-US. |
source_lang | string | No | Source language code. Auto-detected if omitted. |
workspace | string | No | Workspace slug or id. Required when the token can access multiple workspaces. |
project_slug | string | No | Project slug within the resolved workspace. Applies the project's glossaries. |
project_id | string | No | Deprecated: use project_slug. Project ID to scope the translation. |
If the token is narrowed to specific projects, project_slug is required. Translation requires the owner or admin role in the target workspace.
Response (200)
{
"translatedText": "Hello world",
"provider": "openai",
"model": "translate",
"inputCharacters": 17,
"outputCharacters": 11,
"promptTokens": 48,
"completionTokens": 4,
"latencyMs": 287,
"logId": "log_abc123"
}Response Fields
| Field | Type | Description |
|---|---|---|
translatedText | string | The translated output |
detectedSourceLanguage | string | null | Source language when source_lang is omitted/auto and detection is reliable (Translate code such as fr, or ISO 639-1 for unsupported languages). Omitted otherwise. Use /detect to detect without translating |
provider | string | Translation provider used |
model | string | Model identifier |
inputCharacters | number | Input character count |
outputCharacters | number | Output character count |
promptTokens | number | LLM prompt tokens consumed |
completionTokens | number | LLM completion tokens consumed |
latencyMs | number | Provider latency in milliseconds |
logId | string | Log record ID for auditing |
Example
curl -X POST https://your-domain.com/api/v1/translate \
-H "Authorization: Bearer opt_your-token" \
-H "Content-Type: application/json" \
-d '{"text":"Bonjour le monde","source_lang":"fr","target_lang":"en-US"}'const res = await fetch("https://your-domain.com/api/v1/translate", {
method: "POST",
headers: {
"Authorization": "Bearer opt_your-token",
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "Bonjour le monde",
source_lang: "fr",
target_lang: "en-US",
}),
});
const data = await res.json();
console.log(data.translatedText); // "Hello world"import requests
response = requests.post(
"https://your-domain.com/api/v1/translate",
headers={
"Authorization": "Bearer opt_your-token",
"Content-Type": "application/json",
},
json={
"text": "Bonjour le monde",
"source_lang": "fr",
"target_lang": "en-US",
},
)
print(response.json()["translatedText"]) # "Hello world"