- Sep 16, 2025
Building a Text Summarization API with Azure AI and .NET Core
- DevTechie Inc
- Azure Computer Vision
In a world flooded with information, summarization is no longer a luxury — it’s a necessity. Whether you’re building accessibility tools, content previews, or simplifying dense documents, Azure AI’s Text Analytics service offers a powerful way to distill long-form text into concise summaries.
In this article, we’ll walk through how to build a .NET Core Web API that uses Azure’s Extractive Summarization feature to convert verbose input into short, readable output. We’ll cover:
What to set up in Azure
How the .NET Core wrapper API works
How to test it using Swagger or Postman
Step 1: Azure Setup — Provision the Language Service
Before writing any code, you need to provision the Azure AI Language Service, which powers the summarization engine.
What to do:
Go to the Azure Portal
Create a new Azure AI Language resource
Choose a supported region like
East USorSweden Central(required for preview features)Select the Standard S pricing tier
After deployment, copy:
Endpoint URL
API Key
These credentials will be used to authenticate your API calls.
🧑💻 Step 2: .NET Core API — Wrapping Azure Summarization
Below is the code snippet:
[HttpPost("summarize")]
public async Task<IActionResult> SummarizeText([FromBody] SummarizationRequest request)
{
if (string.IsNullOrWhiteSpace(request.Text))
return BadRequest("Text is required.");
var result = await SummarizeTextAsync(request.Text);
var allSentences = new List<string>();
await foreach (var docGroup in result.Value)
{
foreach (var doc in docGroup)
{
foreach (var sentence in doc.Sentences)
{
allSentences.Add(sentence.Text);
}
}
}
var summary = string.Join(" ", allSentences);
return Ok(new { summary });
}
private async Task<Azure.AI.TextAnalytics.ExtractiveSummarizeOperation> SummarizeTextAsync(string inputText)
{
var endpoint = new Uri(AzureAIConstants.LanguageEndpoint);
var credential = new AzureKeyCredential(AzureAIConstants.LanguageApiKey);
var _client = new TextAnalyticsClient(endpoint, credential);
var options = new ExtractiveSummarizeOptions
{
MaxSentenceCount = 3,
OrderBy = ExtractiveSummarySentencesOrder.Rank
};
var document = new TextDocumentInput("1", inputText)
{
Language = "en"
};
var response = await _client.ExtractiveSummarizeAsync(
WaitUntil.Completed,
new[] { document },
options
);
return response;
}
public class SummarizationRequest
{
public string Text { get; set; }
}Controller Endpoint:
[HttpPost("summarize")]
public async Task<IActionResult> SummarizeText([FromBody] SummarizationRequest request)This endpoint accepts a POST request with a JSON body containing Text the to summarize. It validates the input and calls the SummarizeTextAsync method.
Azure Client Setup
var endpoint = new Uri(AzureAIConstants.LanguageEndpoint);
var credential = new AzureKeyCredential(AzureAIConstants.LanguageApiKey);
var _client = new TextAnalyticsClient(endpoint, credential);Here, the Azure Text Analytics client is initialized using the endpoint and key from your Azure resource.
Summarization Options : This configures the summarization behavior:
• MaxSentenceCount: Limits the number of sentences in the summary
• OrderBy: Ranks sentences by relevance
Document Input
var document = new TextDocumentInput("1", inputText)
{
Language = "en"
};
Azure expects a TextDocumentInput object with a unique ID and language code ( for English).
API Call to Azure
var response = await _client.ExtractiveSummarizeAsync(
WaitUntil.Completed,
new[] { document },
options
);This sends the document to Azure and waits for the summarization operation to complete.
Extracting Summary Sentences
var allSentences = new List<string>();
await foreach (var docGroup in result.Value)
{
foreach (var doc in docGroup)
{
foreach (var sentence in doc.Sentences)
{
allSentences.Add(sentence.Text);
}
}
}
var summary = string.Join(" ", allSentences);
return Ok(new { summary });This loops through the nested response structure and collects the summary sentences into a single string.
Step 3: Testing the API with Swagger or Postman
Once your API is running locally or deployed, you can test it using:
Swagger UI
If you’ve enabled Swagger in your project, navigate to:
http://localhost:<port>/swaggerFind the POST/summarize endpoint, enter a long text, and hit “Execute”. You’ll see the summarized output in the response.
Response:
Final Thoughts
This API is a great starting point for building intelligent content workflows. You can plug it into transcription pipelines, accessibility tools, or even voice narration systems using Azure Speech. With just a few lines of code, you’ve unlocked the power of summarization — and made your content more digestible for everyone.



