Machine Translation API
API Description
The machine translation API translates text between Tibetan and Chinese.
Request Description
URL
https://openapi.sys303.com/api/cognitive/translation
Parameters
Header Parameters
| Parameter | Value |
|---|---|
| Content-Type | application/json |
| X-Secret | Get it here |
Body Parameters
| Parameter | Required | Type | Possible Values | Description |
|---|---|---|---|---|
| sourceLang | Yes | int | - | Source language type [0: Tibetan, 1: Chinese] |
| destLang | Yes | int | 0 | Target language type [0: Tibetan, 1: Chinese] |
| inputText | Yes | string | 0 | Text to translate [Unicode, max 3000 characters] |
Request Example
- bash
- python
- C#
- Java
curl --request POST \
--url https://openapi.sys303.com/api/cognitive/translation \
--header 'Content-Type: application/json' \
--header 'X-Secret: {X-Secret}' \
--data '{
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}'
import requests
url = "https://openapi.sys303.com/api/cognitive/translation"
headers = {
"Content-Type": "application/json",
"X-Secret": "your X-Secret"
}
data = {
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.text)
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var url = "https://openapi.sys303.com/api/cognitive/translation";
var secret = "your X-Secret";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-Secret", secret);
var json = """
{
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}
""";
var content = new StringContent(
json,
Encoding.UTF8,
"application/json"
);
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {response.StatusCode}");
Console.WriteLine(result);
}
}
import okhttp3.*;
import java.io.IOException;
public class TranslationDemo {
public static void main(String[] args) throws IOException {
String url = "https://openapi.sys303.com/api/cognitive/translation";
String secret = "your X-Secret";
OkHttpClient client = new OkHttpClient();
String json = """
{
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}
""";
RequestBody body = RequestBody.create(
json,
MediaType.parse("application/json")
);
Request request = new Request.Builder()
.url(url)
.addHeader("Content-Type", "application/json")
.addHeader("X-Secret", secret)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println("Status: " + response.code());
System.out.println(response.body().string());
}
}
}
Return Explanation
Parameter Description
| Field | Required | Type | Status | Description |
|---|---|---|---|---|
| traceId | Yes | String | - | Unique traceId for troubleshooting |
| msgId | Yes | String | - | Business status code |
| msg | Yes | String | Error description | |
| data | Yes | String | - | Translation result |
Return Example
Success
{
"traceId": "0HNL06O44AV58:00000001",
"msgId": "2000000",
"msg": "success",
"data": "