翻译文本
使用 POST /v2/translate,或使用 Google v2 和 Azure v3 文本端点,翻译一个或多个字符串。
使用 POST /v2/translate 翻译文本。它的结构与 DeepL 端点相同。本页末尾的 Google Translate v2 和 Azure Translator v3 端点以各自的格式完成同样的工作。
请求
POST https://vibeql.com/v2/translate
Authorization: DeepL-Auth-Key YOUR_KEY
| 参数 | 是否必填 | 说明 |
|---|---|---|
text |
支持 | 要翻译的文本。重复该字段即可在一次请求中翻译多个字符串。最多 50 个值。 |
target_lang |
支持 | 目标语言代码,例如 DE、PT-BR 或 EN-US。请参阅 语言。 |
source_lang |
不支持 | 源语言代码,例如 EN。留空则模型会从文本中识别源语言。 |
show_billed_characters |
不支持 | 设为 true 或 1,即可在每个结果中添加 billed_characters。 |
请求体最大可达 128 KB。请以表单或 JSON 形式发送请求体。
curl https://vibeql.com/v2/translate \
-H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
-d "text=Good morning" \
-d "text=Thank you" \
-d "target_lang=ES" \
-d "source_lang=EN"curl https://vibeql.com/v2/translate \
-H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": ["Good morning", "Thank you"], "target_lang": "ES", "source_lang": "EN"}'响应
API 为每个 text 值返回一个结果,顺序与请求一致。
{
"translations": [
{ "detected_source_language": "EN", "text": "Buenos días" },
{ "detected_source_language": "EN", "text": "Gracias" }
]
}
使用 show_billed_characters=true:
{
"translations": [
{ "detected_source_language": "EN", "text": "Buenos días", "billed_characters": 12 }
]
}
其他 DeepL 参数,例如 formality、glossary_id、tag_handling 或 context,会被忽略。请参阅从 DeepL 迁移。
用量
用量按您发送的源文本字符数计算,而非译文。无论目标语言是什么,Good morning 都计为 12 个字符。您可以通过 GET /v2/usage 查看总用量。
Google Translate v2 格式
GET 或 POST https://vibeql.com/language/translate/v2。对于多个字符串,请重复 q。source 为可选;如果省略,API 会自动检测语言。
curl "https://vibeql.com/language/translate/v2?key=$VIBEQL_API_KEY" \
-d "q=Good morning" \
-d "q=Thank you" \
-d "target=es"
{
"data": {
"translations": [
{ "translatedText": "Buenos días", "detectedSourceLanguage": "en" },
{ "translatedText": "Gracias", "detectedSourceLanguage": "en" }
]
}
}
所有参数请参阅从 Google Translate 迁移。
Azure Translator v3 格式
POST https://vibeql.com/translate?api-version=3.0&to=es。发送一个包含 Text 项的 JSON 数组。to 最多可重复指定 10 种目标语言。from 为可选。
curl "https://vibeql.com/translate?api-version=3.0&to=es" \
-H "Ocp-Apim-Subscription-Key: $VIBEQL_API_KEY" \
-H "Content-Type: application/json" \
-d '[{"Text": "Good morning"}]'
[
{
"detectedLanguage": { "language": "en", "score": 1 },
"translations": [{ "text": "Buenos días", "to": "es" }]
}
]
指定多个 to 语言时,用量会按每种目标语言各计算一次源字符数。请参阅从 Azure Translator 迁移。