Translate API

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

FieldTypeRequiredDescription
textstringYesText to translate. Max 5,000 characters.
target_langstringNoTarget language code. Defaults to en-US.
source_langstringNoSource language code. Auto-detected if omitted.
workspacestringNoWorkspace slug or id. Required when the token can access multiple workspaces.
project_slugstringNoProject slug within the resolved workspace. Applies the project's glossaries.
project_idstringNoDeprecated: 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

FieldTypeDescription
translatedTextstringThe translated output
detectedSourceLanguagestring | nullSource 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
providerstringTranslation provider used
modelstringModel identifier
inputCharactersnumberInput character count
outputCharactersnumberOutput character count
promptTokensnumberLLM prompt tokens consumed
completionTokensnumberLLM completion tokens consumed
latencyMsnumberProvider latency in milliseconds
logIdstringLog 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"

On this page