This blog post provides instructions for using the official OpenAI .NET library to create a console application with the latest OpenAI Responses API.

The official OpenAI .NET library is developed in collaboration with Microsoft, and the Azure SDK team announced that future releases of the Azure SDK will include the official OpenAI .NET library.

Responses API

The OpenAI Responses API is the latest and most advanced offering from OpenAI. It aims to become a comprehensive tool that integrates all functionalities into one library. Users of the Assistants API should plan to migrate to the Responses API once it matches feature parity, as OpenAI will deprecate the Assistants API in early 2026.

Before you start

To use the OpenAI .NET library, you need to create an OpenAI account and purchase credit to make API calls.

After setting up your account, create a new project and generate an API Key. The API Key will be used to authenticate to the OpenAI service.

Install the Official OpenAI .NET Library

Create a C# Console application and run this command using .NET CLI to install the official OpenAI .NET library.

dotnet add package OpenAI –prerelease

NUnit is being installed for unit testing.

dotnet add package NUnit –version 4.3.2

Setup Console Application

To configure the console application to use the service, open Program.cs and insert the following code.

Create Environment Variable for the API-Key

To run the application, add the API Key as an environment variable. For PowerShell, use the following command.

$Env: OPENAI_API_KEY = “Key-Details”

Select Model

In the above code we need to set the LLM model we would like the application to use. We set the model in the following line.

OpenAIResponseClient client = new(“o3-mini”, Environment.GetEnvironmentVariable(“OPENAI_API_KEY”));

We are using o3-mini. To switch models, visit the page and select one.

https://platform.openai.com/settings/organization/limits

Run the Program

To run the program, simply save the code and run using the following command.

dotnet run

The result should be:


Discover more from CPI Consulting Pty Ltd Experts in Cloud, AI and Cybersecurity

Subscribe to get the latest posts sent to your email.