package
An isomorphic client library for the Azure Translator Service
npm install @azure-rest/ai-translation-textGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Latest published May 28, 2026
latest
Azure text translation is a cloud-based REST API provided by the Azure Translator service. It utilizes neural machine translation technology to deliver precise, contextually relevant, and semantically accurate real-time text translations across all supported languages.
The client library offers several key functionalities:
Retrieve the list of languages supported for translation and transliteration operations, as well as LLM models available for translations.
Perform deterministic text translation from a specified source language to a target language, with configurable parameters to ensure precision and maintain contextual integrity.
Execute transliteration by converting text from the original script to an alternative script representation.
Use LLM models to produce translation output variants that are tone-specific and gender-aware.
Please rely heavily on our REST client docs to use this library
Key links:
@azure-rest/ai-translation-text packageInstall the Azure TextTranslation REST client REST client library for JavaScript with npm:
npm install @azure-rest/ai-translation-textYou can create a Translator resource following Create a Translator resource.
To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our bundling documentation.
Interaction with the service using the client library begins with creating an instance of the TextTranslationClient class. You will need an API key or TokenCredential to instantiate a client object. For more information regarding authenticating with cognitive services, see Authenticate requests to Translator Service.
You can get the endpoint, API key and Region from the Cognitive Services resource or Translator service resource information in the Azure Portal.
Alternatively, use the Azure CLI snippet below to get the API key from the Translator service resource.
az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>TextTranslationClient using an Azure Active Directory credentialTo use an Azure Active Directory (AAD) token credential, provide an instance of the desired credential type obtained from the @azure/identity library.
To authenticate with AAD, you must first npm install @azure/identity
After setup, you can choose which type of credential from @azure/identity to use.
As an example, DefaultAzureCredential
can be used to authenticate the client.
TextTranslationClient using an API key and Region credentialOnce you have the value for the API key and Region, create an TranslatorCredential.
With the value of the TranslatorCredential you can create the TextTranslationClient:
import TextTranslationClient, { TranslatorCredential } from "@azure-rest/ai-translation-text";
const endpoint = "https://api.cognitive.microsofttranslator.com";
const key = "YOUR_SUBSCRIPTION_KEY";
const region = "westus";
const credential: TranslatorCredential = {
key,
region,
};
const translationClient = TextTranslationClient(endpoint, credential);The following section provides several code snippets using the client created above, and covers the main features present in this client library.
Gets the set of languages currently supported by other operations of the Translator.
import TextTranslationClient, {
TranslatorCredential,
isUnexpected,
} from "@azure-rest/ai-translation-text";
const endpoint = "https://api.cognitive.microsofttranslator.com";
const key = "YOUR_SUBSCRIPTION_KEY";
const region = "westus";
const credential: TranslatorCredential = {
key,
region,
};
const translationClient = TextTranslationClient(endpoint, credential);
const langResponse = await translationClient.path("/languages").get();
if (isUnexpected
Please refer to the service documentation for a conceptual discussion of languages.
Renders single source-language text to multiple target-language texts with a single request.
import TextTranslationClient, {
TranslatorCredential,
isUnexpected,
} from "@azure-rest/ai-translation-text";
const endpoint = "https://api.cognitive.microsofttranslator.com";
const key = "YOUR_SUBSCRIPTION_KEY";
const region = "westus";
const credential: TranslatorCredential = {
key,
region,
};
const translationClient = TextTranslationClient(endpoint, credential);
const input = {
text: "This is a test.",
targets: [{ language: "cs" }],
language: "en",
Please refer to the service documentation for a conceptual discussion of translate.
Converts characters or letters of a source language to the corresponding characters or letters of a target language.
import TextTranslationClient, {
TranslatorCredential,
isUnexpected,
} from "@azure-rest/ai-translation-text";
const endpoint = "https://api.cognitive.microsofttranslator.com";
const key = "YOUR_SUBSCRIPTION_KEY";
const region = "westus";
const credential: TranslatorCredential = {
key,
region,
};
const translationClient = TextTranslationClient(endpoint, credential);
const inputText = [{ text: "这是个测试。" }];
const parameters = {
language: "zh-Hans",
Please refer to the service documentation for a conceptual discussion of transliterate.
When you interact with the Translator Service using the TextTranslator client library, errors returned by the Translator service correspond to the same HTTP status codes returned for REST API requests.
For example, if you submit a translation request without a target translate language, a 400 error is returned, indicating "Bad Request".
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.
microsoft1es
npmjs@microsoft.com
Estimated unpacked size across 12 packages.
5.5 MB
Includes dependencies.
5 direct dependencies.
^2.8.1
2.9.1
^1.1.4
1.4.0
^1.9.0
1.11.0
^2.3.1
2.9.0
^1.19.0
1.25.1