Prompt
how to translate text via api
Latest observation
Oct 13, 2026
OpenAI APIWeb search: off
To translate text via an API, you generally:
-
Choose a translation API
- Google Cloud Translation
- DeepL API
- Microsoft Translator
- LibreTranslate
-
Get API credentials
- Create an account
- Generate an API key or token
-
Make an HTTP request
- Send the source text, source language, and target language to the API endpoint
-
Read the translated text from the response
Example using a generic REST API
cURL
curl -X POST "https://api.example.com/translate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, world!",
"source_lang": "en",
"target_lang": "es"
}'
Python
import requests
url = "https://api.example.com/translate"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"text": "Hello, world!",
"source_lang": "en",
"target_lang": "es"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
Example response
{
"translated_text": "¡Hola, mundo!"
}
If you want a real provider example
Tell me which one you want:
- Google Translate API
- DeepL
- Microsoft Translator
- LibreTranslate
and I’ll give you the exact code.