Lewati ke konten utama

API Terjemahan Teks

Terjemahkan teks menggunakan GPT Translator API.

Endpoint​

POST https://api.gpttranslator.co/v1/translation/text-translation/api

Autentikasi​

Tambahkan kunci API Anda di header permintaan:

x-api-key: YOUR_API_KEY
Content-Type: application/json

Body Permintaan​

Field wajib:

  • text string: Teks sumber yang akan diterjemahkan
  • sourceLang string: Kode bahasa sumber
  • targetLang string: Kode bahasa target
  • model string: Nama model terjemahan

Field opsional:

  • domain string: Spesialisasi domain
  • writingStyle string: Preferensi gaya penulisan
  • tone string: Preferensi nada
  • customPrompt string: Instruksi terjemahan khusus

Kode bahasa didokumentasikan terpisah di Bahasa yang Didukung. Model yang didukung didokumentasikan di Model yang Didukung.

Aturan Validasi​

  • text: Wajib. Tidak boleh kosong.
  • sourceLang, targetLang: Harus cocok dengan ^[a-zA-Z]+(-[a-zA-Z]+)?$, minimal 2 karakter, maksimal 11 karakter. Harus berupa kode dari Bahasa yang Didukung.
  • model: Harus salah satu nilai di Model yang Didukung.

Contoh​

cURL​

curl --location 'https://api.gpttranslator.co/v1/translation/text-translation/api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"text": "hello world",
"sourceLang": "en",
"targetLang": "fr",
"model": "gpt-4.1-mini-2025-04-14"
}'

JavaScript​

const response = await fetch(
"https://api.gpttranslator.co/v1/translation/text-translation/api",
{
method: "POST",
headers: {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "hello world",
sourceLang: "en",
targetLang: "fr",
model: "gpt-4.1-mini-2025-04-14",
}),
},
);

const data = await response.json();
console.log(data);

Python​

import requests

url = "https://api.gpttranslator.co/v1/translation/text-translation/api"
headers = {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"text": "hello world",
"sourceLang": "en",
"targetLang": "fr",
"model": "gpt-4.1-mini-2025-04-14"
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())

Jenis Respons​

Berhasil 200​

{
"message": "Text translation completed successfully",
"error": null,
"data": {
"translatedText": "bonjour le monde",
"originalText": "hello world",
"totalWords": 2,
"isRTL": false,
"tokensConsumed": 3
},
"statusCode": 200
}

Kesalahan Validasi Permintaan 400​

Kesalahan middleware validasi dikembalikan dalam format ini:

{
"error": "Invalid source language. Please select a supported language."
}

Kemungkinan kesalahan validasi lainnya:

  • Invalid target language. Please select a supported language.
  • Invalid model type. Please enter a valid model type e.g. ...
  • Text cannot be empty.
  • Text is required.

Kunci API Tidak Ada/Header Tidak Valid 401​

{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 401,
"data": null
}

Kesalahan Kunci API atau Pengaturan Pengguna 400​

Kunci tidak valid di database:

{
"message": "Invalid api key",
"error": "Invalid api key",
"statusCode": 400,
"data": null
}

Pengguna tidak aktif:

{
"message": "User not found or user is not active",
"error": "User not found or user is not active",
"statusCode": 400,
"data": null
}

Organisasi tidak ada:

{
"message": "Organization Id not found for the user",
"error": "Organization Id not found for the user",
"statusCode": 400,
"data": null
}

Batasan Paket 402​

{
"message": "only subscribed users are allowed to use this model",
"error": "only subscribed users are allowed to use this model",
"data": null,
"statusCode": 402
}

Batas Token Tercapai 402​

{
"message": "You have reached the limit of words for translation. Please upgrade your plan to continue using this feature.",
"error": "You have reached the limit of words for translation. Please upgrade your plan to continue using this feature.",
"data": {
"requiredTokens": 123,
"tokens": 45
},
"statusCode": 402
}

Kesalahan Pemrosesan/Server 500​

{
"message": "Error in text translation for api",
"error": "Detailed server error message",
"data": null,
"statusCode": 500
}