Document Directory

Translation Task API

Translation text

POST/v1/translation/translateTexts

Translate text and synchronously return translation results.

Complete Address
https://deploy-demo.otranslator.com/api/v1/translation/translateTexts
Authentication
API Key needs to be passed in the Authorization request header
Content-Type
application/json
Error Format
{ "error": "Invalid API key." }

Notes

This endpoint temporarily saves the input text as a JSON document and processes it synchronously, suitable for real-time translation of small batches of text.

Account credit balance must be at least 2 credits. If the actual cost exceeds the balance, the API will return taskId and price, and prompt insufficient balance.

Example

1curl -X POST 'https://deploy-demo.otranslator.com/api/v1/translation/translateTexts' \
2--header 'Authorization: [yourSecretKey]' \
3--header 'Content-Type: application/json' \
4--data '{
5  "texts": [
6    "string"
7  ],
8  "fromLang": "[string]",
9  "toLang": "[string]"
10}'

Request Parameters

ParametersTypeDefaultDescriptionExample
Required: textsString[]-

Text to be translated

-
Required: fromLangString-
  • Source language; the source language cannot be the same as the target language
  • Supported languages: Query
-
Required: toLangString-
  • Target language; the target language cannot be the same as the source language
  • Supported languages: Query
-
modelString-
  • AI model for translation
  • Supported models: Query
-
fileDescriptionString-

Document description: Enhance translation quality by providing additional information, such as document background context and other translation requirements

-

Response

ParametersTypeDefaultDescriptionExample
taskIdString-

Task ID

-
translatedTextsString[]-

Translated text

-
priceInteger-

Total credits required for translation

-
usedCreditsInteger-

Number of credits used by translation task

-

Common Errors

401 Missing API key.

The Authorization request header is required.

401 Invalid API key.

The API key does not exist, has been deleted, or is no longer valid.

402 Insufficient credits balance.

The account does not have enough credits to translate the texts.

400 Missing required parameter: fromLang.

Provide fromLang using a language returned by /api/v1/languages.

400 Missing required parameter: toLang.

Provide toLang using a language returned by /api/v1/languages.

400 Missing required parameter: texts.

Provide a non-empty texts array.

400 Failed to translate texts.

The text translation task could not be processed.

Translation Task API
Restart translation task