AI chatbots are becoming a major part of modern applications. Businesses now use AI-powered assistants for:
Customer support
Internal automation
Knowledge management
Productivity tools
Enterprise workflows
For .NET developers, modern AI platforms and orchestration frameworks make chatbot development much easier than before.
In this article, we will learn how to create AI chatbots in C# using:
OpenAI APIs
Microsoft Azure AI
Semantic Kernel
ASP.NET Core
Why Use Semantic Kernel?
Semantic Kernel is an AI orchestration framework developed by Microsoft that helps developers integrate AI models into .NET applications.
It simplifies:
Prompt management
AI workflows
Function calling
Memory integration
AI agent orchestration
Semantic Kernel works with multiple AI providers, including OpenAI and Azure AI.
Common AI Chatbot Use Cases
Modern AI chatbots are used in:
| Use Case | Example |
|---|
| Customer Support | AI help desk |
| Enterprise Search | Internal knowledge assistant |
| Productivity Tools | AI workflow assistant |
| Developer Tools | Coding assistants |
| SaaS Platforms | AI-powered support systems |
AI chatbots are now becoming part of enterprise software ecosystems.
Creating a New ASP.NET Core Project
Create a new Web API project:
dotnet new webapi -n AIChatbotDemo
Navigate to the project folder:
cd AIChatbotDemo
Installing Required Packages
Install Semantic Kernel and OpenAI packages.
dotnet add package Microsoft.SemanticKernel
dotnet add package Microsoft.SemanticKernel.Connectors.OpenAI
These packages allow AI integration inside ASP.NET Core applications.
Configuring API Keys
Add API settings inside appsettings.json.
{
"OpenAI": {
"ApiKey": "YOUR_API_KEY",
"Model": "gpt-4o-mini"
}
}
Store API keys securely using secret managers or environment variables.
Creating the Semantic Kernel Service
Create a chatbot service using Semantic Kernel.
using Microsoft.SemanticKernel;
public class ChatbotService
{
private readonly Kernel _kernel;
public ChatbotService(IConfiguration configuration)
{
var builder = Kernel.CreateBuilder();
builder.AddOpenAIChatCompletion(
modelId: configuration["OpenAI:Model"],
apiKey: configuration["OpenAI:ApiKey"]);
_kernel = builder.Build();
}
public async Task<string> AskAsync(string prompt)
{
var result = await _kernel.InvokePromptAsync(prompt);
return result.ToString();
}
}
This service sends prompts to the AI model and returns responses.
Registering the Service
Register the chatbot service in Program.cs.
builder.Services.AddSingleton<ChatbotService>();
Creating the API Controller
Create a controller to expose chatbot functionality.
[ApiController]
[Route("api/chatbot")]
public class ChatbotController : ControllerBase
{
private readonly ChatbotService _chatbotService;
public ChatbotController(
ChatbotService chatbotService)
{
_chatbotService = chatbotService;
}
[HttpPost]
public async Task<IActionResult> Chat(string prompt)
{
var response = await _chatbotService
.AskAsync(prompt);
return Ok(response);
}
}
This creates a simple AI chatbot API endpoint.
Running the Application
Run the application:
dotnet run
Test the chatbot endpoint using:
Swagger
Postman
REST clients
Example prompt:
{
"prompt": "Explain dependency injection in ASP.NET Core"
}
Adding Azure OpenAI Support
Semantic Kernel also supports Azure OpenAI services.
Replace OpenAI configuration with Azure AI settings.
builder.AddAzureOpenAIChatCompletion(
deploymentName: "gpt-model",
endpoint: "https://your-endpoint.openai.azure.com/",
apiKey: "YOUR_AZURE_KEY");
This allows enterprise applications to integrate with Azure AI infrastructure.
Enhancing the Chatbot
Modern enterprise chatbots often include:
Conversation memory
Document search
RAG architecture
AI agents
Function calling
Workflow automation
Semantic Kernel simplifies these advanced AI patterns.
Benefits of AI Chatbots in ASP.NET Core
Faster Development
Developers can build AI-powered applications quickly using cloud AI APIs.
Enterprise Scalability
Cloud AI services scale automatically based on workload demand.
Flexible AI Integration
Semantic Kernel supports multiple AI providers and orchestration patterns.
Better User Experience
AI chatbots improve customer interaction and automation capabilities.
Challenges of AI Chatbots
Despite their advantages, AI chatbots also introduce challenges.
AI Hallucinations
AI-generated responses may sometimes be inaccurate.
Security Risks
Applications must protect sensitive enterprise data carefully.
API Costs
High-volume AI workloads can increase operational expenses.
Context Management
Maintaining long conversations and memory requires proper architecture planning.
The Future of AI Chatbots
AI chatbots are rapidly evolving into intelligent AI agents.
Future trends may include:
AI-powered conversational systems will continue growing across enterprise applications.
Conclusion
Creating AI chatbots in C# has become much easier with OpenAI APIs, Azure AI services, and Semantic Kernel.
By combining ASP.NET Core with modern AI orchestration frameworks, developers can build scalable and intelligent chatbot systems for enterprise and cloud-native applications.
As AI adoption continues to grow, chatbot development and AI orchestration are becoming important skills for modern .NET developers.