Skip to content
Merged
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
5 changes: 5 additions & 0 deletions docs/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "10.*-rc*"
}
}
27 changes: 27 additions & 0 deletions docs/quickstart/responses/analyze_images_files_file_url.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SAMPLE: Analyzes file from a file URL through Responses API
// PAGE: https://platform.openai.com/docs/quickstart?input-type=file-url#analyze-images-and-files
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Files;
using OpenAI.Responses;

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

using HttpClient http = new();
using Stream stream = await http.GetStreamAsync("https://www.berkshirehathaway.com/letters/2024ltr.pdf");
OpenAIFileClient files = new(key);
OpenAIFile file = files.UploadFile(stream, "2024ltr.pdf", FileUploadPurpose.UserData);

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("Analyze the letter and provide a summary of the key points."),
ResponseContentPart.CreateInputFilePart(file.Id)
])
]);

Console.WriteLine(response.GetOutputText());
20 changes: 20 additions & 0 deletions docs/quickstart/responses/analyze_images_files_image_url.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SAMPLE: Analyzes image from an image URL through Responses API
// PAGE: https://platform.openai.com/docs/quickstart?input-type=image-url#analyze-images-and-files
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
OpenAIResponseClient client = new(model: "gpt-5", apiKey: key);
OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("What is in this image?"),
ResponseContentPart.CreateInputImagePart(new Uri("https://openai-documentation.vercel.app/images/cat_and_otter.png"))
])
]);

Console.WriteLine(response.GetOutputText());
25 changes: 25 additions & 0 deletions docs/quickstart/responses/analyze_images_files_upload_file.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SAMPLE: Analyzes file from a file upload through Responses API
// PAGE: https://platform.openai.com/docs/quickstart?input-type=file-upload#analyze-images-and-files
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Files;
using OpenAI.Responses;

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

OpenAIFileClient files = new(key);
OpenAIFile file = files.UploadFile("draconomicon.pdf", FileUploadPurpose.UserData);

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputFilePart(file.Id),
ResponseContentPart.CreateInputTextPart("What is the first dragon in the book?")
])
]);

Console.WriteLine(response.GetOutputText());
15 changes: 15 additions & 0 deletions docs/quickstart/responses/developer_quickstart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SAMPLE: Generate text from a simple prompt through Responses API
// PAGE: https://platform.openai.com/docs/quickstart
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
OpenAIResponseClient client = new(model: "gpt-5", apiKey: key);
OpenAIResponse response = client.CreateResponse("Write a one-sentence bedtime story about a unicorn.");

Console.WriteLine(response.GetOutputText());
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SAMPLE: Get information from file search through Responses API
// PAGE: https://platform.openai.com/docs/quickstart?tool-type=file-search#extend-the-model-with-tools
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

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

ResponseCreationOptions options = new();
options.Tools.Add(ResponseTool.CreateFileSearchTool([ "<vector_store_id>" ]));

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("What is deep research by OpenAI?")
])
], options);

Console.WriteLine(response.GetOutputText());
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SAMPLE: Generate response from function calling through Responses API
// PAGE: https://platform.openai.com/docs/quickstart?tool-type=function-calling#extend-the-model-with-tools
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using System.Text.Json;
using OpenAI.Responses;

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

ResponseCreationOptions options = new();
options.Tools.Add(ResponseTool.CreateFunctionTool(
functionName: "get_weather",
functionDescription: "Get current temperature for a given location.",
functionParameters: BinaryData.FromObjectAsJson(new
{
type = "object",
properties = new
{
location = new
{
type = "string",
description = "City and country e.g. Bogotá, Colombia",
}
},
required = new[] { "location" },
additionalProperties = false
}),
strictModeEnabled: true
)
);

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("What is the weather like in Paris today?")
])
], options);

Console.WriteLine(JsonSerializer.Serialize(response.OutputItems[0]));
27 changes: 27 additions & 0 deletions docs/quickstart/responses/extend_model_with_tools_remote_mcp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SAMPLE: Generate response from remote MCP through Responses API
// PAGE: https://platform.openai.com/docs/quickstart?tool-type=remote-mcp#extend-the-model-with-tools
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

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

ResponseCreationOptions options = new();
options.Tools.Add(ResponseTool.CreateMcpTool(
serverLabel: "dmcp",
serverUri: new Uri("https://dmcp-server.deno.dev/sse"),
toolCallApprovalPolicy: new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
));

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("Roll 2d4+1")
])
], options);

Console.WriteLine(response.GetOutputText());
23 changes: 23 additions & 0 deletions docs/quickstart/responses/extend_model_with_tools_web_search.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SAMPLE: Get information from web search through Responses API
// PAGE: https://platform.openai.com/docs/quickstart?tool-type=web-search#extend-the-model-with-tools
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

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

ResponseCreationOptions options = new();
options.Tools.Add(ResponseTool.CreateWebSearchTool());

OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("What was a positive news story from today?")
])
], options);

Console.WriteLine(response.GetOutputText());
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SAMPLE: Generate streaming response for realtime apps through Responses API
// PAGE: https://platform.openai.com/docs/quickstart#stream-responses-and-build-realtime-apps
// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
#pragma warning disable OPENAI001

#:package System.Linq.Async@6.*
#:package OpenAI@2.*
#:property PublishAot=false

using OpenAI.Responses;

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

var responses = client.CreateResponseStreamingAsync([
ResponseItem.CreateUserMessageItem([
ResponseContentPart.CreateInputTextPart("Say 'double bubble bath' ten times fast.")
])
]);

await foreach (var response in responses)
{
if (response is StreamingResponseOutputTextDeltaUpdate delta)
{
Console.Write(delta.Delta);
}
}