Text Analytics API Reference
This document provides detailed reference information for the Azure Text Analytics API. This service enables you to analyze text using natural language processing (NLP) capabilities.
Features Supported
- Sentiment Analysis
- Key Phrase Extraction
- Named Entity Recognition (NER)
- Language Detection
- Personally Identifiable Information (PII) Detection
- Healthcare Text Analytics (Preview) Preview
API Endpoints
Analyzes the sentiment of a given text.
Extracts key phrases from a given text.
Recognizes entities in a given text.
Detects the language of a given text.
Detects Personally Identifiable Information (PII) in a given text.
Analyzes healthcare-specific text. Preview
Authentication
Requests to the Text Analytics API are authenticated using a subscription key. You can obtain a key from the Azure portal.
Include your subscription key in the request header as follows:
Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY
Request Body Structure
Most Text Analytics operations accept a JSON payload containing an array of documents to be processed. Each document requires a unique ID and the text content.
{
"documents": [
{
"id": "1",
"language": "en",
"text": "This is a sample document."
},
{
"id": "2",
"language": "es",
"text": "Este es otro documento de ejemplo."
}
]
}
Common Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
documents |
Array of Document | A list of documents to be analyzed. | Yes |
id |
String | Unique identifier for the document. | Yes |
language |
String | The ISO 639-1 language code of the text. If not specified, the service will attempt to detect the language. | No |
text |
String | The text content to analyze. | Yes |
stringIndexType |
String | Specifies the index type used for string offsets. Can be 'TextElements' or 'UnicodeCodeUnit'. Defaults to 'UnicodeCodeUnit'. | No |
Example: Sentiment Analysis Request
Here's an example of sending a POST request to the sentiment analysis endpoint:
POST https://YOUR_TEXT_ANALYTICS_ENDPOINT/text/analytics/v3.0/sentiment?showStats=true
Content-Type: application/json
Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY
{
"documents": [
{
"id": "sentimentDoc1",
"language": "en",
"text": "The weather today is beautiful and sunny!"
},
{
"id": "sentimentDoc2",
"language": "en",
"text": "I am not happy with the service I received."
}
]
}
Response Structure
The API returns a JSON object containing the results for each document submitted, organized by operation.
{
"sentimentDocuments": [
{
"id": "sentimentDoc1",
"sentiment": "positive",
"confidenceScores": {
"positive": 0.98,
"neutral": 0.01,
"negative": 0.01
},
"warnings": []
},
{
"id": "sentimentDoc2",
"sentiment": "negative",
"confidenceScores": {
"positive": 0.05,
"neutral": 0.10,
"negative": 0.85
},
"warnings": []
}
],
"errors": [],
"modelVersion": "2020-04-01"
}
Refer to the specific API operation documentation for detailed response structures.