Prompt
How do I automatically detect language and translate text in one API call?
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
You can usually do this by using a single translation API endpoint that supports source-language auto-detection. The request includes the target language, and the service detects the input language internally before translating.
General pattern
- Send the text to the translation endpoint
- Set the source language to
"auto"or omit it if the API supports auto-detect - Specify the target language
- The API returns:
- the translated text
- often the detected source language as metadata
Example concept
Request
{
"q": "Bonjour tout le monde",
"source": "auto",
"target": "en",
"format": "text"
}
Response
{
"translatedText": "Hello everyone",
"detectedSourceLanguage": "fr"
}
If you’re using a specific provider
- Google Cloud Translation: supports auto-detection when source language is not set, or by using detect/translate workflows depending on API version.
- DeepL: supports
source_langomitted for auto-detection in many cases. - Microsoft Translator: can auto-detect and translate in a single call.
Practical notes
- Auto-detection may be less reliable for very short strings like
"OK"or"No" - For best results, provide enough context or longer text
- You may want to inspect the detected language returned by the API if you need to log or branch logic
If you tell me which translation API you’re using, I can give you the exact one-call request format.