OpenAiModel

OpenAiModel(string, string)

Initializes a new instance of OpenAiModel class.

public OpenAiModel(string name, string apiKey)
ParameterTypeDescription
nameStringThe name of the model. For example, gpt-5.2-chat-latest.
apiKeyStringThe API key to use the OpenAi API.

Examples

Shows how to create an OpenAI model instance directly using an API key and model name.

string apiKey = Environment.GetEnvironmentVariable("API_KEY");
// Create an OpenAI model instance using the constructor with model name and API key.
OpenAiModel model = new OpenAiModel("gpt-4o-mini", apiKey);

Document doc = new Document(MyDir + "Big document.docx");
// Summarize the document using the OpenAI model with short summary length.
SummarizeOptions summarizeOptions = new SummarizeOptions() { SummaryLength = SummaryLength.VeryShort };
Document summary = model.Summarize(doc, summarizeOptions);

summary.Save(ArtifactsDir + "OpenAiModel.OpenAiModelConstructor.docx");

See Also


OpenAiModel(string)

Initializes a new instance of OpenAiModel class.

public OpenAiModel(string name)
ParameterTypeDescription
nameStringThe name of the model. For example, gpt-5.2-chat-latest.

See Also