Building AI Chatbots with Azure OpenAI and .NET (2026 Guide)

By Sachin Tanwar, founder 11 min read

Most businesses no longer ask whether they should add AI to their product. They ask how to add a chatbot or AI assistant that answers from their own documents, stays inside their security rules and does not leak customer data. The answer depends heavily on the platform you build on.

This guide explains the pieces in plain terms: what OpenAI is, what Azure OpenAI adds, what Microsoft Foundry (formerly Azure AI Foundry) does, how retrieval-augmented generation (RAG) works on Azure, and why .NET is a strong, secure choice for enterprise AI chatbots and AI-enabled apps.

What is OpenAI?

OpenAI is the company behind the GPT family of large language models and the ChatGPT product. It is worth separating two things that often get mixed up:

  • ChatGPT is a finished chat app for people. Your team can use it, but you cannot plug your product's data, permissions and workflows into it in a controlled way.
  • The OpenAI API gives developers direct access to the same models. You send a prompt, the model returns a response, and you pay per token (roughly, per piece of a word) for input and output.

The API is what you build products on. The question for most companies is where that API runs and who controls the data around it.

What is Azure OpenAI?

Azure OpenAI gives you OpenAI's models running inside Microsoft Azure, under your Azure subscription. Today it is offered as part of the Foundry Models catalog in Microsoft Foundry, but the idea is the same: the models you know, with Azure's enterprise controls around them.

What that means in practice:

  • Your data stays in your Azure environment. Microsoft states that prompts and completions are not used to train, retrain or improve the base models, and are not shared with OpenAI.
  • You choose where it runs. Models are deployed to Azure regions or data zones you select, which helps with data-residency requirements.
  • Private networking. You can lock the endpoint behind Private Endpoints and virtual networks so it is never exposed to the public internet.
  • Keyless sign-in. Apps authenticate with Microsoft Entra ID and Managed Identity instead of API keys stored in config files.
  • Built-in content filtering. Harmful content and common prompt-attack patterns can be filtered on the way in and out.
  • Enterprise support and Azure's compliance programme. The service sits under the same compliance and support agreements as the rest of your Azure estate.

One detail to check for regulated workloads: by default Microsoft may keep prompts for a limited time for abuse monitoring. Eligible customers can apply to change that. Read Microsoft's current data-privacy page for Azure OpenAI before you sign off on a design.

OpenAI vs Azure OpenAI: which should you use?

Both give you access to the same family of models. The difference is everything around the model.

  • Model access: OpenAI's own API usually gets brand-new models first. Azure OpenAI adds them shortly after, region by region.
  • Data handling: both say API data is not used for training by default. Azure OpenAI adds data residency in your chosen region and keeps processing inside your Azure tenant.
  • Networking: the OpenAI API is a public endpoint. Azure OpenAI supports Private Endpoints and virtual network isolation.
  • Identity: the OpenAI API uses API keys. Azure OpenAI supports Entra ID, Managed Identity and role-based access control.
  • Compliance: Azure OpenAI inherits Azure's compliance certifications and contracts, which procurement and security teams usually already trust.
  • Billing: OpenAI bills you directly. Azure OpenAI goes on your existing Azure invoice and can use your Azure commitments.
  • Best fit: OpenAI's API suits startups and prototypes that want the newest models fast. Azure OpenAI suits companies with customer data, compliance needs or an existing Microsoft stack.

For most B2B products, internal assistants and anything touching personal or financial data, Azure OpenAI is the safer default.

What is Microsoft Foundry (formerly Azure AI Foundry)?

Microsoft Foundry is Microsoft's platform for building AI apps and agents on Azure. It was called Azure AI Studio, then Azure AI Foundry, and was renamed Microsoft Foundry in late 2025. If you search for Azure AI Foundry today, this is what you end up in.

Think of it as the workshop around the models:

  • A model catalog that includes OpenAI's GPT models alongside others such as Meta Llama, Mistral and Microsoft's Phi models, so you can pick the right model for cost and quality.
  • An agent service for building assistants that can call tools, search your data and take actions.
  • Evaluation tools to measure answer quality, groundedness and safety before you go live.
  • Content safety controls, tracing and monitoring for production.
  • Foundry Tools (previously Azure AI Services) for speech, vision, translation and document processing.

Azure OpenAI is one part of Foundry: the OpenAI models. Foundry is the wider set of tools you use to turn those models into a reliable, measurable product.

How a RAG chatbot works on Azure

A plain language model only knows what it learned in training. It does not know your product manuals, policies or support history. Retrieval-augmented generation (RAG) fixes that by finding the right pieces of your own content and giving them to the model with each question.

A typical Azure RAG pipeline looks like this:

  1. Ingest your content: PDFs, web pages, SharePoint, a database or your help centre.
  2. Split it into chunks and turn each chunk into an embedding (a numeric fingerprint of its meaning) with an Azure OpenAI embedding model.
  3. Store the chunks in Azure AI Search, which supports keyword, vector and hybrid search plus semantic ranking.
  4. When a user asks a question, search for the most relevant chunks, filtered by what that user is allowed to see.
  5. Send the question and those chunks to the chat model with instructions to answer only from the supplied content.
  6. Return the answer with citations, so users can check the source.

Done well, RAG gives you answers grounded in your data, far fewer made-up answers, and no need to fine-tune a model every time a document changes. For a deeper look at chunking, evaluation and the common mistakes, read our practical RAG playbook.

Why .NET is a strong choice for enterprise AI apps

Python dominates AI research and model training. But most business AI work is not training models. It is building secure, reliable applications around them: APIs, permissions, integrations, background jobs and dashboards. That is exactly where .NET is strong.

  • First-party Azure support. Microsoft builds and maintains the Azure SDKs for .NET, including Azure OpenAI, Azure AI Search, Key Vault and Entra ID, so new features arrive with proper support.
  • Modern AI building blocks. Microsoft.Extensions.AI gives .NET a standard way to talk to chat and embedding models through one interface, so you can switch models or providers without rewriting your app.
  • Agents built in. Microsoft Agent Framework, the successor to Semantic Kernel and AutoGen, lets .NET apps build agents that call tools, use memory and run multi-step workflows.
  • Performance. ASP.NET Core is one of the fastest mainstream web frameworks, which matters when a chatbot streams answers to thousands of users at once.
  • Type safety and maintainability. C#'s strong typing catches whole classes of bugs at compile time, which is valuable in code that handles sensitive data.
  • Long-term support. .NET 10 is a long-term support release, so your AI app runs on a supported, patched platform for years.
  • It fits what you already run. Many companies already have .NET systems, Microsoft 365 and Azure. An AI feature built in .NET plugs into the same identity, logging and deployment pipelines.

Python still has its place, for example in data pipelines or custom model work, and our Python and AI developers handle those parts. For the production app around the model, .NET is often the more secure and maintainable choice. If you are still on the old .NET Framework, see our guide to moving to .NET 10 without a big-bang rewrite.

Security checklist for AI chatbots in .NET

A chatbot that can read your documents is a new way into your data, so treat it like any other system with access to sensitive information. This is the checklist we work through on every build:

  • No keys in code. Use Managed Identity and Entra ID to call Azure OpenAI and Azure AI Search. Store any remaining secrets in Azure Key Vault.
  • Private networking. Put Azure OpenAI, AI Search and storage behind Private Endpoints so they are not reachable from the internet.
  • Security trimming. Filter search results by the user's permissions, so the bot never quotes a document the user could not open themselves.
  • Prompt-injection defences. Keep system instructions separate from user input and retrieved text, enable content filters and Prompt Shields, and never let the model run sensitive actions without checks.
  • PII handling. Mask or remove personal data before it is indexed or logged, where the use case allows.
  • Least-privilege tools. If the assistant can call APIs, give it narrow, read-only permissions wherever possible and require confirmation for anything that changes data.
  • Rate limiting and quotas. Protect your token budget and stop abuse with per-user limits in ASP.NET Core.
  • Audit logging and monitoring. Log questions, sources used and actions taken, and watch quality and safety metrics after launch.

What the code looks like

The core of an Azure OpenAI chatbot in C# is short. In ASP.NET Core you register a chat client for your Azure OpenAI deployment once, authenticate with DefaultAzureCredential (so there is no API key anywhere in your code or config), and inject the client wherever you need it.

A chat endpoint then does three things: it looks up relevant chunks in Azure AI Search for the signed-in user, builds a message list with your system instructions, those chunks and the user's question, and streams the model's answer back to the browser. Because the chat client sits behind the standard Microsoft.Extensions.AI interface, you can swap models, add caching or add logging without touching the endpoint itself.

Most of the real work is not in that call. It is in the ingestion pipeline, permissions, evaluation and the user interface, which is where an experienced team saves you months.

Use cases that work well

  • Customer support assistant that answers from your help centre and hands off to a human with full context.
  • Internal knowledge assistant for policies, SOPs, contracts and technical documentation.
  • Document Q&A over PDFs, reports and scanned files, combined with document intelligence for extraction.
  • Sales and pre-sales assistant that drafts answers to RFPs and security questionnaires from approved content.
  • AI features inside an existing app: summaries, smart search, ticket classification, email drafting and data extraction.

What affects the cost and timeline of an AI chatbot

There is no single price for an AI chatbot, because the model call is the cheap part. What drives cost and timeline:

  • How much content there is, in how many formats, and how often it changes.
  • How many systems it has to connect to, such as your CRM, ERP, SharePoint or ticketing tool.
  • Which models you use and how many questions users ask, since usage is billed per token.
  • Permission rules and security reviews, including private networking and compliance sign-off.
  • Whether it only answers questions or also takes actions as an agent.
  • How much evaluation and testing your use case needs before launch.

A focused proof of concept on a small set of documents is usually the fastest way to learn what a full rollout will need. For a scoped estimate, request a quote.

How HatchDesk builds AI chatbots and AI-enabled apps

We build AI features the same way we build any production software: small steps, measured results and security from day one.

  1. Discovery: we agree on the use case, the content sources, the users and what a good answer looks like.
  2. Proof of concept: a working assistant on a sample of your data, usually within a few weeks, with an evaluation set to measure answer quality.
  3. Pilot: security hardening, permissions, monitoring and a rollout to a small group of real users.
  4. Production and improvement: full rollout, cost tracking and ongoing tuning based on real questions.

Our team combines AI and LLM development with deep .NET development experience on Azure. If you need engineers to join your own team, you can also hire dedicated .NET developers who have shipped Azure OpenAI and RAG projects.

Frequently asked questions

Is Azure OpenAI the same as ChatGPT?

No. ChatGPT is OpenAI's chat app for people. Azure OpenAI gives developers the underlying GPT models inside Microsoft Azure, so you can build your own chatbot or AI feature with your data, your security rules and your branding.

Does Azure OpenAI use my data to train its models?

Microsoft states that prompts, completions and your data are not used to train, retrain or improve the base models, and are not made available to OpenAI. Always check Microsoft's current data-privacy documentation for the details that apply to your setup, including abuse-monitoring retention.

Is Azure AI Foundry the same as Microsoft Foundry?

Yes. Azure AI Foundry was renamed Microsoft Foundry in late 2025. It is Microsoft's platform for building AI apps and agents, and Azure OpenAI's models are available through it.

Can I build an AI chatbot in C# and .NET?

Yes. .NET has first-party Azure SDKs, Microsoft.Extensions.AI for working with models, and Microsoft Agent Framework for agents. ASP.NET Core is a fast, secure base for chat APIs and streaming responses.

Do I need RAG or fine-tuning?

For most business chatbots, start with RAG. It lets the model answer from your current documents, shows sources and updates as soon as your content changes. Fine-tuning is useful for adjusting tone or format, but it is not a good way to teach a model facts that change.

How long does it take to build an AI chatbot?

A focused proof of concept can often be ready within a few weeks. A production rollout with integrations, permissions and security reviews takes longer, depending on how many systems and documents are involved.

How much does an AI chatbot cost?

It depends on content volume, integrations, model choice, usage and security requirements. The best way to get a realistic number is a short discovery call. Request a quote and we will come back with a scoped estimate.

Ready to build your AI chatbot?

If you are planning an AI chatbot, a RAG assistant or AI features inside an existing .NET application, we can help you choose the right Azure setup and get to a working proof of concept quickly. Start with our AI and LLM development services or book a free consultation through the contact page.

AI
Share this article
Written by Sachin Tanwar

Senior engineers who design, build and run .NET, React and mobile products for clients in the US, UK and Australia. We write about what we’ve learned shipping them.

Meet the team

Have a project in mind?

Get a free 30-minute consultation with a senior engineer — no strings attached.

Let's Turn Your Idea Into Reality.

From idea to launch, we build innovative software solutions that
help businesses grow faster.