Version: v1
Description: Sistema automatizado de traduccion con soporte para 48 idiomas
Esta API expone dos endpoints (/translate y /detect) y acepta tanto texto plano como archivos codificados en base64 como carga útil de entrada (application/json o application/x-www-form-urlencoded).
/translateMétodo: POST
Parámetros:
text (opcional) - La cadena de texto a traducir. Puede contener markdown o HTML.file (opcional) - Datos del archivo codificados en Base64. Es obligatorio si no se proporciona text. Tipos de documentos permitidos: txt, odt, odp, docx, pptx.from (obligatorio) - Código ISO de 2 letras del idioma de origen (ej., en).target (obligatorio) - Código ISO de 2 letras del idioma de destino (ej., es).Nota: Si se proporcionan tanto text como file, se priorizará text y file será ignorado.
Ejemplos de Uso:
curl -X POST https://api.latinapi.com/api/traducelo/translate \
-H "Content-Type: application/json" \
-H "X-Api-Key: TULLAVEAPI" \
-d '{
"text": "Hello World",
"from": "en",
"target": "es"
}'const translateText = async () => {
const response = await fetch('https://api.latinapi.com/api/traducelo/translate', {
method: 'POST',
headers: { 'Content-Type': 'application/json','X-Api-Key': 'TULLAVEAPI' },
body: JSON.stringify({
text: "Hello World",
from: "en",
target: "es"
})
});
const data = await response.json();
console.log(data); // { "translatedText": "Hola Mundo" }
};
translateText();
<?php
$ch = curl_init('https://api.latinapi.com/api/traducelo/translate');
$payload = json_encode([
'text' => 'Hello World',
'from' => 'en',
'target' => 'es'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-Api-Key: TULLAVEAPI',
'Content-Length: ' . strlen($payload)
]);
$result = curl_exec($ch);
curl_close($ch);
echo $result; // {"translatedText": "Hola Mundo"}
Respuesta:
{
"translatedText": "Hola Mundo"
}(También recibirás un encabezado X-Credits-Used que contiene la longitud multiplicada por 0.001 Esto quiere decir que cada caracer traducido tiene un costo de 0.001 créditos.)
curl -X POST https://api.latinapi.com/api/traducelo/translate \
-H "Content-Type: application/json" \
-H "X-Api-Key: TULLAVEAPI" \
-d '{
"file": "SGVsbG8gV29ybGQ=",
"from": "en",
"target": "es"
}'Respuesta:
{
"translatedFile": "SG9sYSBNdW5kbw=="
}/detectMétodo: POST
Parámetros:
text (opcional) - La cadena de texto de la cual detectar el idioma.file (opcional) - Datos del archivo codificados en Base64. Es obligatorio si no se proporciona text.Ejemplo de Uso (cURL):
curl -X POST https://api.latinapi.com/api/traducelo/detect \
-H "Content-Type: application/json" \
-H "X-Api-Key: TULLAVEAPI" \
-d '{
"text": "Hola Mundo"
}'const detectLanguage = async () => {
const response = await fetch('https://api.latinapi.com/api/traducelo/detect', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': 'TULLAVEAPI' },
body: JSON.stringify({ text: "Hola Mundo" })
});
const data = await response.json();
console.log(data);
};
detectLanguage();
<?php
$ch = curl_init('https://api.latinapi.com/api/traducelo/detect');
$payload = json_encode(['text' => 'Hola Mundo']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json','X-API-Key: TULLAVEAPI']);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Respuesta:
[
{
"confidence": 0.98,
"language": "es"
}
]POST permite la ejecución).base64 para los archivos son validadas.