- Added a
StoredOutputEnabled
property toChatCompletionOptions
(store
in the REST API). (b0f9e5c)- Use this property to indicate whether or not to store the output of the chat completion for use in model distillation or evals.
- Added a
Metadata
property toChatCompletionOptions
(metadata
in the REST API). (b0f9e5c)- Use this property to add custom tags and values to the chat completions for filtering in the OpenAI dashboard.
- Added an
InputTokenDetails
property toChatTokenUsage
(usage.prompt_token_details
in the REST API). (b0f9e5c)- The property is of a new type called
ChatInputTokenUsageDetails
, which contains properties forAudioTokenCount
andCachedTokenCount
for usage with supported models.
- The property is of a new type called
- Added an
AudioTokenCount
property toChatOutputTokenUsageDetails
(usage.completion_token_details
in the REST API). Audio support in chat completions is coming soon. (b0f9e5c) - Added
Illicit
andIllicitViolent
propertiesModerationResult
to represent these two new moderation categories. (b0f9e5c) - Made improvements to the experimental Realtime API. Please note this features area is currently under rapid development and not all changes may be reflected here. (b0f9e5c)
- Several types have been renamed for consistency and clarity.
ConversationRateLimitsUpdate
(previouslyConversationRateLimitsUpdatedUpdate
) now includes namedRequestDetails
andTokenDetails
properties, mapping to the corresponding named items in the underlyingrate_limits
command payload.
- Fixed serialization and deserialization of
ConversationToolChoice
literal values (such as"required"
). (9de3709)
- Updated the
System.ClientModel
dependency to version1.2.1
. (b0f9e5c)- This updates the
System.Text.Json
transitive dependency to version6.0.10
, which includes a security compliance fix for CVE-2024-43485. Please note that the OpenAI library was not impacted by this vulnerability since it does not use the[JsonExtensionData]
feature.
- This updates the
With this updated preview library release, we're excited to bring early support for the newly-announced /realtime
beta API. You can read more about /realtime
here: https://openai.com/index/introducing-the-realtime-api/
Given the scope and recency of the feature area, the new RealtimeConversationClient
is subject to substantial refinement and change over the coming weeks -- this release is purely intended to empower early development against gpt-4o-realtime-preview
as quickly and efficiently as possible.
- Added a new
RealtimeConversationClient
in a corresponding scenario namespace. (ff75da4)- This maps to the new
/realtime
beta endpoint and is thus marked with a new[Experimental("OPENAI002")]
diagnostic tag. - This is a very early version of the convenience surface and thus subject to significant change
- Documentation and samples will arrive soon; in the interim, see the scenario test files for basic usage
- You can also find an external sample employing this client, together with Azure OpenAI support, at https://github.com/Azure-Samples/aoai-realtime-audio-sdk/tree/main/dotnet/samples/console
- This maps to the new
Note
First stable version of the official OpenAI library for .NET.
- Support for OpenAI's latest flagship models, including GPT-4o, GPT-4o mini, o1-preview, and o1-mini
- Support for the entire OpenAI REST API, including:
- Structured outputs
- Reasoning tokens
- Experimental support for Assistants beta v2
- Support for sync and async APIs
- Convenient APIs to facilitate working with streaming chat completions and assistants
- Tons of other quality-of-life features for ease of use and productivity
Note
The following breaking changes only apply when upgrading from the previous 2.0.0-beta.* versions.
- Implemented
ChatMessageContent
to encapsulate the representation of content parts inChatMessage
,ChatCompletion
, andStreamingChatCompletionUpdate
. (31c2ba6) - Changed the representation of function arguments to
BinaryData
inChatToolCall
,StreamingChatToolCallUpdate
,ChatFunctionCall
, andStreamingChatFunctionCallUpdate
. (31c2ba6) - Renamed
OpenAIClientOptions
'sApplicationId
toUserAgentApplicationId
. (31c2ba6) - Renamed
StreamingChatToolCallUpdate
'sId
toToolCallId
. (31c2ba6) - Renamed
StreamingChatCompletionUpdate
'sId
toCompletionId
. (31c2ba6) - Replaced
Auto
andNone
in the deprecatedChatFunctionChoice
withCreateAutoChoice()
andCreateNoneChoice()
. (31c2ba6) - Replaced the deprecated
ChatFunctionChoice(ChatFunction)
constructor withCreateNamedChoice(string functionName)
. (31c2ba6) - Renamed
FileClient
toOpenAIFileClient
and the correspondingGetFileClient()
method inOpenAIClient
toGetOpenAIFileClient()
. (31c2ba6) - Renamed
ModelClient
toOpenAIModelClient
and the correspondingGetModelClient()
method inOpenAIClient
toGetOpenAIModelClient()
. (31c2ba6)
- Refactored
ModerationResult
by mergingModerationCategories
andModerationCategoryScores
into individualModerationCategory
properties, each withFlagged
andScore
properties. (19ceae4) - Renamed type
OpenAIFileInfo
toOpenAIFile
andOpenAIFileInfoCollection
toOpenAIFileCollection
. (19ceae4) - Renamed type
OpenAIModelInfo
toOpenAIModel
andOpenAIModelInfoCollection
toOpenAIModelCollection
. (19ceae4) - Renamed type
Embedding
toOpenAIEmbedding
andEmbeddingCollection
toOpenAIEmbeddingCollection
. (19ceae4) - Renamed property
ImageUrl
toImageUri
and methodFromImageUrl
toFromImageUri
in theMessageContent
type. (19ceae4) - Renamed property
ParallelToolCallsEnabled
toAllowParallelToolCalls
in theRunCreationOptions
,ThreadRun
, andChatCompletionOptions
types. (19ceae4) - Renamed properties
PromptTokens
toInputTokenCount
,CompletionTokens
toOutputTokenCount
, andTotalTokens
toTotalTokenCount
in theRunTokenUsage
andRunStepTokenUsage
types. (19ceae4) - Renamed properties
InputTokens
toInputTokenCount
andTotalTokens
toTotalTokenCount
in theEmbeddingTokenUsage
type. (19ceae4) - Renamed properties
MaxPromptTokens
toMaxInputTokenCount
andMaxCompletionTokens
toMaxOutputTokenCount
in theThreadRun
,RunCreationOptions
, andRunIncompleteReason
types. (19ceae4) - Removed the
virtual
keyword from thePipeline
property across all clients. (75eded5) - Renamed the
Granularities
property ofAudioTranscriptionOptions
toTimestampGranularities
. (a330c2e) - Changed
AudioTranscriptionFormat
from an enum to an "extensible enum". (a330c2e) - Changed
AudioTranslationFormat
from an enum to an "extensible enum". (a330c2e) - Changed
GenerateImageFormat
from an enum to an "extensible enum". (a330c2e) - Changed
GeneratedImageQuality
from an enum to an "extensible enum". (a330c2e) - Changed
GeneratedImageStyle
from an enum to an "extensible enum". (a330c2e) - Removed method overloads in
AssistantClient
andVectorStoreClient
that take complex parameters in favor of methods that take simple string IDs. (a330c2e) - Updated the
TokenIds
property type in theTranscribedSegment
type fromIReadOnlyList<int>
toReadOnlyMemory<int>
. (a330c2e) - Updated the
inputs
parameter type in theGenerateEmbeddings
andGenerateEmbeddingsAsync
methods ofEmbeddingClient
fromIEnumerable<IEnumerable<int>>
toIEnumerable<ReadOnlyMemory<int>>
. (a330c2e) - Changed
ChatMessageContentPartKind
from an extensible enum to an enum. (a330c2e) - Changed
ChatToolCallKind
from an extensible enum to an enum. (a330c2e) - Changed
ChatToolKind
from an extensible enum to an enum. (a330c2e) - Changed
OpenAIFilePurpose
from an extensible enum to an enum. (a330c2e) - Changed
OpenAIFileStatus
from an extensible enum to an enum. (a330c2e) - Renamed
OpenAIFilePurpose
toFilePurpose
. (a330c2e) - Renamed
OpenAIFileStatus
toFileStatus
. (a330c2e) - Removed constructors that take string API key and options. (a330c2e)
- The library now includes support for the new OpenAI o1 model family. (2ab1a94)
ChatCompletionOptions
will automatically apply itsMaxOutputTokenCount
value (renamed fromMaxTokens
) to the newmax_completion_tokens
request body propertyUsage
includes a newOutputTokenDetails
property with aReasoningTokenCount
value that will reflecto1
model use of this new subcategory of output tokens.- Note that
OutputTokenCount
(completion_tokens
) is the sum of displayed tokens generated by the model and (when applicable) these new reasoning tokens
- Assistants file search now includes support for
RankingOptions
. (2ab1a94)- Use of the
include[]
query string parameter and retrieval of run step detail result content is currently only available via protocol methods
- Use of the
- Added support for the Uploads API in
FileClient
. ThisExperimental
feature allows uploading large files in multiple parts. (2ab1a94)- The feature is supported by the
CreateUpload
,AddUploadPart
,CompleteUpload
, andCancelUpload
protocol methods.
- The feature is supported by the
- Renamed
ChatMessageContentPart
'sCreateTextMessageContentPart
factory method toCreateTextPart
. (2ab1a94) - Renamed
ChatMessageContentPart
'sCreateImageMessageContentPart
factory method toCreateImagePart
. (2ab1a94) - Renamed
ChatMessageContentPart
'sCreateRefusalMessageContentPart
factory method toCreateRefusalPart
. (2ab1a94) - Renamed
ImageChatMessageContentPartDetail
toChatImageDetailLevel
. (2ab1a94) - Removed
ChatMessageContentPart
'sToString
overload. (2ab1a94) - Renamed the
MaxTokens
property inChatCompletionOptions
toMaxOutputTokenCount
. (2ab1a94) - Renamed properties in
ChatTokenUsage
: - Removed the common
ListOrder
enum from the top-levelOpenAI
namespace in favor of individual enums in their corresponding sub-namespace. (2ab1a94) - Renamed the
PageSize
property toPageSizeLimit
. (2ab1a94) - Updated deletion methods to return a result object instead of a
bool
. Affected methods: - Removed setters from collection properties. (2ab1a94)
- Renamed
ChatTokenLogProbabilityInfo
toChatTokenLogProbabilityDetails
. (2ab1a94) - Renamed
ChatTokenTopLogProbabilityInfo
toChatTokenTopLogProbabilityDetails
. (2ab1a94) - Renamed the
Utf8ByteValues
properties ofChatTokenLogProbabilityDetails
andChatTokenTopLogProbabilityDetails
toUtf8Bytes
and changed their type fromIReadOnlyList<int>
toReadOnlyMemory<byte>?
. (2ab1a94) - Renamed the
Start
andEnd
properties ofTranscribedSegment
andTranscribedWord
toStartTime
andEndTime
. (2ab1a94) - Changed the type of
TranscribedSegment
'sAverageLogProbability
andNoSpeechProbability
properties fromdouble
tofloat
. (2ab1a94) - Changed the type of
TranscribedSegment
'sSeekOffset
property fromlong
toint
. (2ab1a94) - Changed the type of
TranscribedSegment
'sTokenIds
property fromIReadOnlyList<long>
toIReadOnlyList<int>
. (2ab1a94) - Updated the
Embedding.Vector
property to theEmbedding.ToFloats()
method. (2ab1a94) - Removed the optional parameter from the constructors of
VectorStoreCreationHelper
,AssistantChatMessage
, andChatFunction
. (2ab1a94) - Removed the optional
purpose
parameter fromFileClient.GetFilesAsync
andFileClient.GetFiles
methods, and added overloads wherepurpose
is required. (2ab1a94) - Renamed
ModerationClient
'sClassifyTextInput
methods toClassifyText
. (2ab1a94) - Removed duplicated
Created
property fromGeneratedImageCollection
. (2ab1a94)
- Addressed an issue that caused multi-page queries of fine-tuning jobs, checkpoints, and events to fail. (2ab1a94)
ChatCompletionOptions
can now be serialized viaModelReaderWriter.Write()
prior to callingCompleteChat
using the options. (2ab1a94)
- Added support for
CancellationToken
toModelClient
methods. (2ab1a94) - Applied the
Obsolete
attribute where appropriate to align with the existing deprecations in the REST API. (2ab1a94)
- Added the
OpenAIChatModelFactory
in theOpenAI.Chat
namespace (a static class that can be used to instantiate OpenAI models for mocking in non-live test scenarios). (79014ab)
- Updated fine-tuning pagination methods
GetJobs
,GetEvents
, andGetJobCheckpoints
to returnIEnumerable<ClientResult>
instead ofClientResult
. (5773292) - Updated the batching pagination method
GetBatches
to returnIEnumerable<ClientResult>
instead ofClientResult
. (5773292) - Changed
GeneratedSpeechVoice
from an enum to an "extensible enum". (79014ab) - Changed
GeneratedSpeechFormat
from an enum to an "extensible enum". (cc9169a) - Renamed
SpeechGenerationOptions
'sSpeed
property toSpeedRatio
. (cc9169a)
- Corrected an internal deserialization issue that caused recent updates to Assistants
file_search
to fail when streaming a run. Strongly typed support forranking_options
is not included but will arrive soon. (cc9169a) - Mitigated a .NET runtime issue that prevented
ChatResponseFormat
from serializing correct on targets including Unity. (cc9169a)
- Reverted the removal of the version path parameter "v1" from the default endpoint URL. (583e9f6)
- Added the
Experimental
attribute to the following APIs:
- Renamed
AudioClient
'sGenerateSpeechFromText
methods to simplyGenerateSpeech
. (d84bf54) - Changed the type of
OpenAIFileInfo
'sSizeInBytes
property fromlong?
toint?
. (d84bf54)
- Fixed a newly introduced bug (#185) where providing
OpenAIClientOptions
to a top-levelOpenAIClient
did not carry over to scenario clients (e.g.ChatClient
) created via that top-level client (d84bf54)
- Removed the version path parameter "v1" from the default endpoint URL. (d84bf54)
- Added support for the new structured outputs response format feature, which enables chat completions, assistants, and tools on each of those clients to provide a specific JSON Schema that generated content should adhere to. (3467b53)
- To enable top-level structured outputs for response content, use
ChatResponseFormat.CreateJsonSchemaFormat()
andAssistantResponseFormat.CreateJsonSchemaFormat()
as theResponseFormat
in method options likeChatCompletionOptions
- To enable structured outputs for function tools, set
StrictParameterSchemaEnabled
totrue
on the tool definition - For more information, please see the new section in readme.md
- To enable top-level structured outputs for response content, use
- Chat completions: the request message types of
AssistantChatMessage
,SystemChatMessage
, andToolChatMessage
now support array-based content part collections in addition to simple string input. (3467b53) - Added the following model factories (static classes that can be used to instantiate OpenAI models for mocking in non-live test scenarios):
OpenAIAudioModelFactory
in theOpenAI.Audio
namespace (3284295)OpenAIEmbeddingsModelFactory
in theOpenAI.Embeddings
namespace (3284295)OpenAIFilesModelFactory
in theOpenAI.Files
namespace (b1ce397)OpenAIImagesModelFactory
in theOpenAI.Images
namespace (3284295)OpenAIModelsModelFactory
in theOpenAI.Models
namespace (b1ce397)OpenAIModerationsModelFactory
in theOpenAI.Moderations
namespace (b1ce397)
- Removed client constructors that do not explicitly take an API key parameter or an endpoint via an
OpenAIClientOptions
parameter, making it clearer how to appropriately instantiate a client. (13a9c68) - Removed the endpoint parameter from all client constructors, making it clearer that an alternative endpoint must be specified via the
OpenAIClientOptions
parameter. (13a9c68) - Removed
OpenAIClient
'sEndpoint
protected
property. (13a9c68) - Made
OpenAIClient
's constructor that takes aClientPipeline
parameterprotected internal
instead of justprotected
. (13a9c68) - Renamed the
User
property in applicable Options classes toEndUserId
, making its purpose clearer. (13a9c68)
- The
Assistants
namespaceVectorStoreCreationHelper
type now properly includes aChunkingStrategy
property. (3467b53)
ChatCompletion.ToString()
will no longer throw an exception when no content is present, as is the case for tool calls. Additionally, if a tool call is present with no content,ToString()
will return the serialized form of the first available tool call. (3467b53)
- Changed name of return types from methods returning streaming collections from
ResultCollection
toCollectionResult
. (7bdecfd) - Changed return types from methods returning paginated collections from
PageableCollection
toPageCollection
. (7bdecfd) - Users must now call
GetAllValues
on the collection of pages to enumerate collection items directly. Corresponding protocol methods returnIEnumerable<ClientResult>
where each collection item represents a single service response holding a page of values. (7bdecfd) - Updated
VectorStoreFileCounts
andVectorStoreFileAssociationError
types fromreadonly struct
toclass
. (58f93c8)
- (#49) Fixed a bug with extensible enums implementing case-insensitive equality but case-sensitive hash codes. (0c12500)
- (#57) Fixed a bug with requests URIs with query string parameter potentially containing a malformed double question mark (
??
) on .NET Framework (net481). (0c12500) - Added optional
CancellationToken
parameters to methods forAssistantClient
andVectorStore
client, consistent with past changes in 19a65a0. (d77539c) - Fixed Assistants
FileSearchToolDefinition
'sMaxResults
parameter to appropriately serialize and deserialize the value (d77539c) - Added missing
[EditorBrowsable(EditorBrowsableState.Never)]
attributes toAssistantClient
protocol methods, which should improve discoverability of the strongly typed methods. (d77539c)
- Removed the usage of
init
and updated properties to useset
. (58f93c8)
- (#84) Fixed a
NullReferenceException
thrown when adding the custom headers policy whileOpenAIClientOptions
is null (0b97311)
OrganizationId
andProjectId
are now present onOpenAIClientOptions
. When instantiating a client, providing an instance ofOpenAIClientOptions
with these properties set will cause the client to add the appropriate request headers for org/project, eliminating the need to manually configure the headers. (9ee7dff)
- (#72) Fixed
filename
request encoding in operations usingmultipart/form-data
, includingfiles
andaudio
(2ba8e69) - (#79) Fixed hard-coded
user
role for caller-created Assistants API messages on threads (d665b61) - Fixed non-streaming Assistants API run step details not reporting code interpreter logs when present (d665b61)
Assistants (beta):
AssistantClient.CreateMessage()
and the explicit constructor forThreadInitializationMessage
now require aMessageRole
parameter. This properly enables the ability to create an Assistant message representing conversation history on a new thread. (d665b61)
- API updates, current to openai/openai-openapi@dd73070b (1af6569)
- This includes
MaxResults
for AssistantsFileSearchToolDefinition
,ParallelToolCallsEnabled
for function tools in Assistants and Chat, andFileChunkingStrategy
for Assistants VectorStores
- This includes
- Optional
CancellationToken
parameters are now directly present on most methods, eliminating the need to use protocol methods (19a65a0)
- (#30) Mitigated a .NET runtime issue that prevented chat message content and several other types from serializing correct on targets including mono and wasm (896b9e0)
- Assistants: Fixed an issue that threw an exception when receiving code interpreter run step logs when streaming a run (207d597)
- Fixed a concurrency condition that could cause
multipart/form-data
requests to no longer generate random content part boundaries (no direct scenario impact) (7cacdee)
Assistants (beta):
InputQuote
is removed from AssistantsTextAnnotation
andTextAnnotationUpdate
, per openai/openai-openapi@dd73070b (1af6569)
- Added an environment-variable-based test project to the repository with baseline scenario coverage (db6328a)
- Build/analyzer warnings cleaned up throughout the project (45fc4d7, b1fa082, 22ab606)
- Proactively aligned library's implementation of server-sent event (SSE) handling with the source of the incoming
System.Net.ServerSentEvents
namespace (674e0f7)
- Added new, built-in helpers to simplify the use of text-only message content (1c40de6)
- Optimized embedding deserialization and addressed correctness on big endian systems (e28b5a7)
- Optimized b64_json message parsing via regex (efd76b5)
- Removed a vestigial package reference (5874f53)
This is the official OpenAI client library for C# / .NET. It provides convenient access to the OpenAI REST API from .NET applications and supports all the latest features. It is generated from our OpenAPI specification in collaboration with Microsoft.
If you are a user migrating from version 1.11.0 or earlier, we will soon share a migration guide to help you get started.
- Addendum: the migration guide is now available.