Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
406 changes: 296 additions & 110 deletions api/OpenAI.net8.0.cs

Large diffs are not rendered by default.

387 changes: 284 additions & 103 deletions api/OpenAI.netstandard2.0.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/Responses/Example01_SimpleResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public partial class ResponseExamples
[Test]
public void Example01_SimpleResponse()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

OpenAIResponse response = client.CreateResponse("Say 'this is a test.'");
ResponseResult response = client.CreateResponse(new ([ResponseItem.CreateUserMessageItem("Say 'this is a test.'")]));

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
}
Expand Down
4 changes: 2 additions & 2 deletions examples/Responses/Example01_SimpleResponseAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public partial class ResponseExamples
[Test]
public async Task Example01_SimpleResponseAsync()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

OpenAIResponse response = await client.CreateResponseAsync("Say 'this is a test.'");
ResponseResult response = await client.CreateResponseAsync(new ([ResponseItem.CreateUserMessageItem("Say 'this is a test.'")]));

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
}
Expand Down
4 changes: 2 additions & 2 deletions examples/Responses/Example02_SimpleResponseStreaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public partial class ResponseExamples
[Test]
public void Example02_SimpleResponseStreaming()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

CollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreaming("Say 'this is a test.'");
CollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreaming(new ([ResponseItem.CreateUserMessageItem("Say 'this is a test.'")]));

Console.Write($"[ASSISTANT]: ");
foreach (StreamingResponseUpdate update in responseUpdates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public partial class ResponseExamples
[Test]
public async Task Example02_SimpleResponseStreamingAsync()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

AsyncCollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreamingAsync("Say 'this is a test.'");
AsyncCollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreamingAsync(new ([ResponseItem.CreateUserMessageItem("Say 'this is a test.'")]));

Console.Write($"[ASSISTANT]: ");
await foreach (StreamingResponseUpdate update in responseUpdates)
Expand Down
6 changes: 3 additions & 3 deletions examples/Responses/Example03_FunctionCalling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ private static string GetCurrentWeather(string location, string unit = "celsius"
[Test]
public void Example03_FunctionCalling()
{
OpenAIResponseClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

List<ResponseItem> inputItems =
[
ResponseItem.CreateUserMessageItem("What's the weather like today for my current location?"),
];

ResponseCreationOptions options = new()
CreateResponseOptions options = new(inputItems)
{
Tools = { getCurrentLocationTool, getCurrentWeatherTool },
};
Expand All @@ -81,7 +81,7 @@ public void Example03_FunctionCalling()
do
{
requiresAction = false;
OpenAIResponse response = client.CreateResponse(inputItems, options);
ResponseResult response = client.CreateResponse(options);

inputItems.AddRange(response.OutputItems);

Expand Down
6 changes: 3 additions & 3 deletions examples/Responses/Example03_FunctionCallingAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public partial class ResponseExamples
[Test]
public async Task Example03_FunctionCallingAsync()
{
OpenAIResponseClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

List<ResponseItem> inputItems =
[
ResponseItem.CreateUserMessageItem("What's the weather like today for my current location?"),
];

ResponseCreationOptions options = new()
CreateResponseOptions options = new(inputItems)
{
Tools = { getCurrentLocationTool, getCurrentWeatherTool },
};
Expand All @@ -38,7 +38,7 @@ public async Task Example03_FunctionCallingAsync()
do
{
requiresAction = false;
OpenAIResponse response = await client.CreateResponseAsync(inputItems, options);
ResponseResult response = await client.CreateResponseAsync(options);

inputItems.AddRange(response.OutputItems);

Expand Down
6 changes: 3 additions & 3 deletions examples/Responses/Example04_FunctionCallingStreaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public partial class ResponseExamples
[Test]
public void Example04_FunctionCallingStreaming()
{
OpenAIResponseClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

List<ResponseItem> inputItems =
[
ResponseItem.CreateUserMessageItem("What's the weather like today for my current location?"),
];

ResponseCreationOptions options = new()
CreateResponseOptions options = new(inputItems)
{
Tools = { getCurrentLocationTool, getCurrentWeatherTool },
};
Expand All @@ -38,7 +38,7 @@ public void Example04_FunctionCallingStreaming()
do
{
requiresAction = false;
CollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreaming(inputItems, options);
CollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreaming(options);

foreach (StreamingResponseUpdate update in responseUpdates)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public partial class ResponseExamples
[Test]
public async Task Example04_FunctionCallingStreamingAsync()
{
OpenAIResponseClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new("gpt-5", Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

List<ResponseItem> inputItems =
[
ResponseItem.CreateUserMessageItem("What's the weather like today for my current location?"),
];

ResponseCreationOptions options = new()
CreateResponseOptions options = new(inputItems)
{
Tools = { getCurrentLocationTool, getCurrentWeatherTool },
};
Expand All @@ -39,7 +39,7 @@ public async Task Example04_FunctionCallingStreamingAsync()
do
{
requiresAction = false;
AsyncCollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreamingAsync(inputItems, options);
AsyncCollectionResult<StreamingResponseUpdate> responseUpdates = client.CreateResponseStreamingAsync(options);

await foreach (StreamingResponseUpdate update in responseUpdates)
{
Expand Down
8 changes: 5 additions & 3 deletions examples/Responses/Example05_RemoteMcp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public partial class ResponseExamples
[Test]
public void Example05_RemoteMcp()
{
ResponseCreationOptions options = new()
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Roll 2d4+1")
])
{
Tools = {
new McpTool(serverLabel: "dmcp", serverUri: new Uri("https://dmcp-server.deno.dev/sse"))
Expand All @@ -24,9 +26,9 @@ public void Example05_RemoteMcp()
}
};

OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

OpenAIResponse response = client.CreateResponse("Roll 2d4+1", options);
ResponseResult response = client.CreateResponse(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
}
Expand Down
8 changes: 5 additions & 3 deletions examples/Responses/Example05_RemoteMcpAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public partial class ResponseExamples
[Test]
public async Task Example05_RemoteMcpAsync()
{
ResponseCreationOptions options = new()
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Roll 2d4+1")
])
{
Tools = {
new McpTool(serverLabel: "dmcp", serverUri: new Uri("https://dmcp-server.deno.dev/sse"))
Expand All @@ -25,9 +27,9 @@ public async Task Example05_RemoteMcpAsync()
}
};

OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

OpenAIResponse response = await client.CreateResponseAsync("Roll 2d4+1", options);
ResponseResult response = await client.CreateResponseAsync(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
}
Expand Down
7 changes: 4 additions & 3 deletions examples/Responses/Example06_RemoteMcpAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public partial class ResponseExamples
[Test]
public void Example06_RemoteMcpAuthentication()
{
ResponseCreationOptions options = new()
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Create a payment link for $20")])
{
Tools = {
new McpTool(serverLabel: "stripe", serverUri: new Uri("https://mcp.stripe.com"))
Expand All @@ -23,9 +24,9 @@ public void Example06_RemoteMcpAuthentication()
}
};

OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

OpenAIResponse response = client.CreateResponse("Create a payment link for $20", options);
ResponseResult response = client.CreateResponse(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public partial class ResponseExamples
[Test]
public async Task Example06_RemoteMcpAuthenticationAsync()
{
ResponseCreationOptions options = new()
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Create a payment link for $20")
])
{
Tools = {
new McpTool(serverLabel: "stripe", serverUri: new Uri("https://mcp.stripe.com"))
Expand All @@ -24,9 +26,9 @@ public async Task Example06_RemoteMcpAuthenticationAsync()
}
};

OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

OpenAIResponse response = await client.CreateResponseAsync("Create a payment link for $20", options);
ResponseResult response = await client.CreateResponseAsync(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
}
Expand Down
10 changes: 6 additions & 4 deletions examples/Responses/Example07_InputAdditionalProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ public partial class ResponseExamples
[Test]
public void Example07_InputAdditionalProperties()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

// Add extra request fields using Patch.
// Patch lets you set fields like `reasoning.effort` and `text.verbosity` that aren’t modeled on ResponseCreationOptions in the request payload.
// Patch lets you set fields like `reasoning.effort` and `text.verbosity` that aren’t modeled on CreateResponseOptions in the request payload.
// See the API docs https://platform.openai.com/docs/api-reference/responses/create for supported additional fields.
ResponseCreationOptions options = new();
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("What is the answer to the ultimate question of life, the universe, and everything?")
]);
options.Patch.Set("$.reasoning.effort"u8, "high");
options.Patch.Set("$.text.verbosity"u8, "medium");

OpenAIResponse response = client.CreateResponse("What is the answer to the ultimate question of life, the universe, and everything?", options);
ResponseResult response = client.CreateResponse(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");

Expand Down
10 changes: 6 additions & 4 deletions examples/Responses/Example07_InputAdditionalPropertiesAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ public partial class ResponseExamples
[Test]
public async Task Example07_InputAdditionalPropertiesAsync()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

// Add extra request fields using Patch.
// Patch lets you set fields like `reasoning.effort` and `text.verbosity` that aren’t modeled on ResponseCreationOptions in the request payload.
// Patch lets you set fields like `reasoning.effort` and `text.verbosity` that aren’t modeled on CreateResponseOptions in the request payload.
// See the API docs https://platform.openai.com/docs/api-reference/responses/create for supported additional fields.
ResponseCreationOptions options = new();
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("What is the answer to the ultimate question of life, the universe, and everything?")
]);
options.Patch.Set("$.reasoning.effort"u8, "high");
options.Patch.Set("$.text.verbosity"u8, "medium");

OpenAIResponse response = await client.CreateResponseAsync("What is the answer to the ultimate question of life, the universe, and everything?", options);
ResponseResult response = await client.CreateResponseAsync(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");

Expand Down
8 changes: 5 additions & 3 deletions examples/Responses/Example08_OutputAdditionalProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public partial class ResponseExamples
[Test]
public void Example08_OutputAdditionalProperties()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

ResponseCreationOptions options = new()
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Generate an image of gray tabby cat hugging an otter with an orange scarf")
])
{
Tools =
{
Expand All @@ -28,7 +30,7 @@ public void Example08_OutputAdditionalProperties()
}
};

OpenAIResponse response = client.CreateResponse("Generate an image of gray tabby cat hugging an otter with an orange scarf", options);
ResponseResult response = client.CreateResponse(options);
ImageGenerationCallResponseItem imageGenResponse = (ImageGenerationCallResponseItem)response.OutputItems[1];
BinaryData bytes = imageGenResponse.ImageResultBytes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ public partial class ResponseExamples
[Test]
public async Task Example08_OutputAdditionalPropertiesAsync()
{
OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

ResponseCreationOptions options = new()
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Generate an image of gray tabby cat hugging an otter with an orange scarf")
])
{
Tools =
{
Expand All @@ -29,7 +31,7 @@ public async Task Example08_OutputAdditionalPropertiesAsync()
}
};

OpenAIResponse response = await client.CreateResponseAsync("Generate an image of gray tabby cat hugging an otter with an orange scarf", options);
ResponseResult response = await client.CreateResponseAsync(options);
ImageGenerationCallResponseItem imageGenResponse = (ImageGenerationCallResponseItem)response.OutputItems[1];
BinaryData bytes = imageGenResponse.ImageResultBytes;

Expand Down
10 changes: 6 additions & 4 deletions examples/Responses/Example09_ModelOverridePerRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ public partial class ResponseExamples
[Test]
public void Example09_ModelOverridePerRequest()
{
OpenAIResponseClient client = new(model: "gpt-4o", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-4o", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

// Add extra request fields using Patch.
// Patch lets you set fields like `model` that aren't exposed on ResponseCreationOptions.
// Patch lets you set fields like `model` that aren't exposed on CreateResponseOptions.
// This overrides the model set on the client just for the request where this options instance is used.
// See the API docs https://platform.openai.com/docs/api-reference/responses/create for supported additional fields.
ResponseCreationOptions options = new();
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Say 'this is a test.")
]);
options.Patch.Set("$.model"u8, "gpt-5");

OpenAIResponse response = client.CreateResponse("Say 'this is a test.", options);
ResponseResult response = client.CreateResponse(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}, [Mode]: {response.Model}");
}
Expand Down
10 changes: 6 additions & 4 deletions examples/Responses/Example09_ModelOverridePerRequestAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ public partial class ResponseExamples
[Test]
public async Task Example09_ModelOverridePerRequestAsync()
{
OpenAIResponseClient client = new(model: "gpt-4o", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
ResponsesClient client = new(model: "gpt-4o", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

// Add extra request fields using Patch.
// Patch lets you set fields like `model` that aren't exposed on ResponseCreationOptions.
// Patch lets you set fields like `model` that aren't exposed on CreateResponseOptions.
// This overrides the model set on the client just for the request where this options instance is used.
// See the API docs https://platform.openai.com/docs/api-reference/responses/create for supported additional fields.
ResponseCreationOptions options = new();
CreateResponseOptions options = new([
ResponseItem.CreateUserMessageItem("Say 'this is a test.")
]);
options.Patch.Set("$.model"u8, "gpt-5");

OpenAIResponse response = await client.CreateResponseAsync("Say 'this is a test.", options);
ResponseResult response = await client.CreateResponseAsync(options);

Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}, [Mode]: {response.Model}");
}
Expand Down
Loading
Loading