Translation API
POST /v1/text/translate
Please refer to the Quickstart Guide to obtain your API key.
Replace $YOUR_API_KEY with your actual API key generated in the previous step.
import requests
import json
url = 'https://api-platform.ope.ai/v1/text/translate'
headers = {
'Authorization': 'Bearer $YOUR_API_KEY',
'Content-Type': 'application/json'
}
payload = {
"model": "$MODEL_ID",
"source_lang": "en",
"target_lang": "zh",
"stream": True,
"text": "Can antibiotics treat viral infections?"
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
model String Required
Model ID used to generate the response.
The following are all allowed callable models.
正在加载实时模型名称列表...
source_lang Language Code Required
Source language
| Language Name | Code | Note |
|---|---|---|
| English | en | Core support |
| Chinese (Simplified / Traditional) | zh | Main support |
| Korean | ko | East Asian coverage |
| Japanese | ja | East Asian coverage |
| Urdu | ur | National language of Pakistan |
| Bengali | bn | |
| Hindi | hi | |
| Portuguese | pt | |
| Filipino | tl | |
| Indonesian | id | |
| Malay | ms | |
| Cantonese | yue | |
| Spanish | es | |
| Russian | ru | Representative of Slavic languages |
| Hokkien | nan | |
| Brazilian Portuguese | pt-br |
stream Boolean or null Optional Default is false
Specify whether to use streaming output. Values:
false: The model returns the full result after all content is generated.
true: The model returns partial content as it is generated. You must read the chunks in real time to reconstruct the result.
text String Required
Text to be translated