.NET + OpenAI API: comparing Chat Completions and Agents
How to implement OpenAI in .NET and make an informed choice between Chat Completions and Agents. Practical guidance, implementation patterns, costs, limits and security for development teams.
Tomasz Soroka
OpenAI API at a glance
For years, OpenAI has been pushing the boundaries of artificial intelligence, developing language models that have revolutionised the way we work with text. From the debut of GPT-1 in 2018 to the qualitative leap of GPT-3 in 2020 with 175 billion parameters, the evolution of these models has opened the way to content generation, translation and even code creation. The core idea remains unchanged: to make advanced AI useful and accessible in real-world applications.
This development trajectory has delivered tools that make it possible to build solutions close to natural conversation, capable of maintaining context and understanding language nuances. Today, integrating these capabilities into .NET projects is easier than ever.
OpenAI-DotNet: a quick start in .NET
OpenAI-DotNet is a lightweight library that streamlines working with OpenAI API in the .NET environment. Installation via NuGet takes just a moment: use the Install-Package OpenAI command in the Package Manager Console and add the package to your project.
Configuration comes down to securely storing the API key. In .NET, you can conveniently do this via Secret Manager or environment variables, and in cloud environments via Azure Key Vault, AWS Secrets Manager or GCP Secret Manager. Load the key from configuration and initialise the API client during application startup.
Interaction with the API involves selecting a model (e.g. gpt-4) and building a request. In a typical scenario, you pass a system instruction, user messages and optional domain context, and the model returns a response ready to use in your application. The library’s GitHub repository includes call examples and best practices that will help you get started faster.
Chat Completions in practice
Chat Completions is a proven foundation for conversational use cases. The model operates on a list of messages with system, user and assistant roles. The system role defines the assistant’s behaviour, the user asks questions, and responses are generated contextually, taking into account the entire conversation history, which you maintain on the application side.

In .NET, you build a message collection, select a model and receive a response. For more advanced scenarios, you can use function calling and streaming to return content to the user in real time. This pattern works particularly well for chatbots, Q&A, translations, summaries or content generation, where you want full control over state and the prompt.
When to choose Chat Completions
- When interactions are short or medium-length and conversation state is kept on the client or service side - When you need maximum control over prompt engineering, context and logic - When low latency and implementation simplicity matter - When you manage tools and function-call orchestration yourself - When you want to optimise costs and tokens with precision
Agents: broadening the spectrum of interactions
Agents introduce a server-side management layer for longer, more complex interactions. They allow you to create conversation threads, attach files and tools, execute multi-step tasks and maintain a coherent conversational flow without having to manually stitch together the entire context in the application.
In practice, this means less code for state management and orchestration, and greater flexibility in designing user experiences. Agents are particularly useful when conversations are long-running, require multiple steps, and the assistant should independently decide on the next actions based on goals and available tools.
When to choose Agents
- When you need long, multi-step processes with server-side memory - When the assistant is expected to use multiple tools, files or external actions within a single flow - When you want to simplify your own orchestration and iterate faster on assistant logic - When you are planning advanced conversational applications with personalisation and persistent threads - When the team values rapid production readiness without building an extensive glue code layer
Chat Completions vs Agents: a quick comparison

- State - Chat Completions: application-side state; full control over history - Agents: state and conversation flow maintained server-side
- Complexity - Chat Completions: simpler integration, more work on the client side - Agents: broader capabilities, slightly higher conceptual complexity
- Control - Chat Completions: precise control over the prompt and tools - Agents: declarative goals and policies, less orchestration code
- Latency and costs - Chat Completions: usually lower latency and cost per request - Agents: scenario-dependent; benefits increase with longer threads and more complex tasks
- Scaling - Chat Completions: scales well in microservices maintaining their own state - Agents: less traffic between services, more logic on the platform side
Implementation patterns in .NET
- Client configuration - Initialise the OpenAI client in the startup component and inject it via DI. Parameterise the model, timeouts and retry policy.
- Secure secrets - Store keys in Secret Manager locally, and in production in Azure Key Vault, AWS Secrets Manager or GCP Secret Manager. Avoid keeping keys in the repository.
- Chat Completions - Build a list of messages with system, user and assistant roles. Consider response streaming and function calling for tool integrations.

- Agents - Create an agent, initialise threads, add messages and run executions. Handle events and tool results on the server side.
- Resilience and limits - Implement exponential backoff for 429/5xx, set time limits, measure token usage and cache repeatable responses.
- Observability - Add telemetry: latency and cost metrics, response quality indicators, prompt version tracking and policy tracking.
Costs, limits and practical guidance
- Model selection - Choose a model appropriate to the required quality and cost. Not every use case needs gpt-4.
- Context management - For long conversations, use context windows, summaries and selective replay of relevant fragments.
- Prompt hygiene - Define a clear role in the system prompt, limit the scope of responsibility and add safety rules.
- Sensitive data - Minimise sending PII, mask logs, apply access control and encryption at rest and in transit.
- Testing and quality - Create prompt regression test suites, evaluate responses automatically and manually, and version configurations.
Summary
Chat Completions provides speed and full control over the conversation flow, making it ideal for simpler and moderately complex tasks. Agents delivers server-side management of threads and tools, reducing the time needed to build complex assistants. In the .NET ecosystem, both approaches are easy to implement through OpenAI-DotNet. The key is making a conscious architectural choice based on your requirements: conversation length and complexity, control over state, costs, and product iteration speed.
Need technology support?
Let’s talk about your project — from discovery to implementation.
Book a consultationWould you like to know more?
Explore other articles or let’s discuss your project
All articles Let’s design your AI application