Module azure.textanalytics

ballerinax/azure.textanalytics Ballerina library



This is a generated connector for Azure Text Analytics API v1 OpenAPI specification. The Text Analytics API is a suite of natural language processing (NLP) services built with best-in-class Microsoft machine learning algorithms. The API can be used to analyze unstructured text for tasks such as sentiment analysis, key phrase extraction and language detection. Functionality for analysis of text specific to the healthcare domain and personal information are also available in the API. Further documentation can be found here

This module supports Azure Text Analytics API v1.


Before using this connector in your Ballerina application, complete the following:


To use the Azure Text Analytics connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/azure.textanalytics module into the Ballerina project.

import ballerinax/azure.textanalytics;

Step 2: Create a new connector instance

You can now make the connection configuration using Ocp-Apim-Subscription-Key.

You can do this step in two ways. You can use any one of this.

  • Option 1 : Configure API Keys in ballerina file directly.

    nalytics:ApiKeysConfig apiKeyConfig = {
    ubscriptionKey: "<Subscription Key>"
    nalytics:Client myClient = check new Client(apiKeyConfig, serviceUrl = "https://<REGION>");
  • Option 2 : Configure API Keys in Config.toml file and configure it in ballerina file, using configurables.

    1. Set up API Keys in Config.toml as shown below.
    ocpApimSubscriptionKey = "<AZURE_API_KEY>"
    subscriptionKey = "<Subscription Key>"
    1. Configure the client in ballerina file as shown below.
    configurable ApiKeysConfig & readonly apiKeyConfig = ?;
    textanalytics:Client myClient = check new Client(apiKeyConfig, serviceUrl = "https://<REGION>");

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector. Note that they are in the form of remote operations.

    Following is an example on how to use sentiment prediction. The API returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and Neutral) for the document and each sentence within it.

    Sentiment Prediction

    public function main() returns error? {
        textanalytics:MultiLanguageBatchInput payload = {
            "documents": [
                "id": "string",
                "text": "string",
                "language": "string"
        textanalytics:SentimentResponse res = check baseClient->sentiment(payload);
  2. Use bal run command to compile and run the Ballerina program.


import ballerinax/azure.textanalytics;Copy


Released date: 10 months ago

Version: 1.5.1

License: Apache-2.0


Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes

Pull count


Current verison: 0

Weekly downloads

Source repository


IT Operations/Cloud Services


Other versions

See more...