Table of Contents

Class ChatCompletion

Response from a LLM (Large Language Model) for a chat completion request.

This class contains a list of ChatChoice objects, each representing a message generated by the model in response to a chat prompt.
Message can be accessed through the ChatChoice (e.g., Choices[0].Message).
If 'n' used in the request is greater than 1, this can contain multiple choices. Otherwise, it will always contain a single choice.

If this is a streamed response, the ChatChoice objects will contain MessageDelta instead of Message.

public class ChatCompletion : OpenAIObject, IGeneratedOutput, IStreamEvent
Inheritance
object
ChatCompletion
Implements
IStreamEvent
Derived
Inherited Members
Extension Methods

Properties

Choices

A list of chat completion choices. Can be more than one if n is greater than 1.

If this is 'ChatCompletionChunk' which is a streamed response, This can also be empty for the last chunk if you set stream_options: {"include_usage": true}.

public ChatChoice[] Choices { get; set; }

Property Value

ChatChoice[]

Count

public int Count { get; }

Property Value

int

CreatedAt

The Unix timestamp (in seconds) of when this object was created.

public UnixTime CreatedAt { get; set; }

Property Value

UnixTime

IsEmpty

public bool IsEmpty { get; }

Property Value

bool

Metadata

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.

public ServerDictionary Metadata { get; set; }

Property Value

ServerDictionary

Model

ID of the model.

public string Model { get; set; }

Property Value

string

SystemFingerprint

OpenAI: Represents the backend configuration that the model runs with.
Can be used in conjunction with the seed request parameter to understand when backend changes have been made that might impact determinism.

xAI: Used to indicate xAI system configuration changes.

public string SystemFingerprint { get; set; }

Property Value

string

Usage

How much tokens were used for the request.

public UsageMetadata Usage { get; set; }

Property Value

UsageMetadata

Methods

CreateEvent(MessageDelta, UsageMetadata)

public static ChatCompletion CreateEvent(MessageDelta delta, UsageMetadata usage = null)

Parameters

delta MessageDelta
usage UsageMetadata

Returns

ChatCompletion

GetOutputFiles()

public List<IFile> GetOutputFiles()

Returns

List<IFile>

GetOutputTexts()

public List<string> GetOutputTexts()

Returns

List<string>

GetUsage()

public UsageMetadata GetUsage()

Returns

UsageMetadata

IsFinal()

public bool IsFinal()

Returns

bool

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToStringArray(Func<string, string>)

public string[] ToStringArray(Func<string, string> textProcessor = null)

Parameters

textProcessor Func<string, string>

Returns

string[]

Operators

implicit operator MessageContent(ChatCompletion)

public static implicit operator MessageContent(ChatCompletion chat)

Parameters

chat ChatCompletion

Returns

MessageContent

implicit operator string(ChatCompletion)

public static implicit operator string(ChatCompletion chat)

Parameters

chat ChatCompletion

Returns

string