Skip to main content

Overview

Use /v1/translations for text-to-text translation.
This endpoint is different from Audio Translation, which accepts an audio file and always outputs English text.
For agent workflows, discover the current recommended translation models first:
curl "https://api.tokenlab.sh/v1/models?recommended_for=translation" \
  -H "Authorization: Bearer sk-your-api-key"
Then explicitly send the chosen model to /v1/translations.
recommended_for=translation applies only to text translation (POST /v1/translations). It does not apply to audio translation.

Request Body

model
string
required
Translation model ID returned by /v1/models?recommended_for=translation.
text
string
required
Source text to translate.
target_language
string
required
Target language code or language name, depending on model support.
source_language
string
Optional source language hint.
mime_type
string
default:"text/plain"
Source text format. Supported values: text/plain, text/html.
user
string
Optional end-user identifier for abuse monitoring and request tracing.

Response

text
string
Translated text.
model
string
Model that generated the translation.
source_language
string | null
Source language detected or accepted by the model.
target_language
string
Target language used for the request.
curl -X POST "https://api.tokenlab.sh/v1/translations" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seed-translation",
    "text": "你好,欢迎使用 TokenLab。",
    "target_language": "en"
  }'
from openai import OpenAI
import requests

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.tokenlab.sh/v1"
)

response = requests.post(
    "https://api.tokenlab.sh/v1/translations",
    headers={
        "Authorization": "Bearer sk-your-api-key",
        "Content-Type": "application/json",
    },
    json={
        "model": "doubao-seed-translation",
        "text": "你好,欢迎使用 TokenLab。",
        "target_language": "en",
    },
    timeout=30,
)

print(response.json()["text"])
{
  "text": "Hello, welcome to TokenLab.",
  "model": "doubao-seed-translation",
  "source_language": "zh",
  "target_language": "en"
}