From 44f95080793ce7ca38fadec6161524dce1f922aa Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Thu, 18 Sep 2025 18:29:32 +0900 Subject: [PATCH 1/3] Add code samples for web search --- .../tools-web-search/responses/quickstart.cs | 25 +++++++++++++++ .../responses/user-location.cs | 31 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 docs/guides/tools-web-search/responses/quickstart.cs create mode 100644 docs/guides/tools-web-search/responses/user-location.cs diff --git a/docs/guides/tools-web-search/responses/quickstart.cs b/docs/guides/tools-web-search/responses/quickstart.cs new file mode 100644 index 000000000..4eb075d2f --- /dev/null +++ b/docs/guides/tools-web-search/responses/quickstart.cs @@ -0,0 +1,25 @@ +// SAMPLE: Get information from web search through Responses API +// PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses +// 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()); \ No newline at end of file diff --git a/docs/guides/tools-web-search/responses/user-location.cs b/docs/guides/tools-web-search/responses/user-location.cs new file mode 100644 index 000000000..c3cabd82f --- /dev/null +++ b/docs/guides/tools-web-search/responses/user-location.cs @@ -0,0 +1,31 @@ +// SAMPLE: Get information from web search by specifying user location through Responses API +// PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses#sources +// 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( + userLocation: WebSearchToolLocation.CreateApproximateLocation( + country: "GB", + city: "London", + region: "London" + ) +)); + +OpenAIResponse response = (OpenAIResponse)client.CreateResponse([ + ResponseItem.CreateUserMessageItem([ + ResponseContentPart.CreateInputTextPart( + "What are the best restaurants around Granary Square?" + ) + ]) +], options); + +Console.WriteLine(response.GetOutputText()); \ No newline at end of file From b18b9a826b5547c70c59f69ec1e91494a1907e54 Mon Sep 17 00:00:00 2001 From: Justin Yoo Date: Fri, 19 Sep 2025 14:18:36 +0900 Subject: [PATCH 2/3] Update document link --- docs/guides/tools-web-search/responses/user-location.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/tools-web-search/responses/user-location.cs b/docs/guides/tools-web-search/responses/user-location.cs index c3cabd82f..f191b08ff 100644 --- a/docs/guides/tools-web-search/responses/user-location.cs +++ b/docs/guides/tools-web-search/responses/user-location.cs @@ -1,5 +1,5 @@ // SAMPLE: Get information from web search by specifying user location through Responses API -// PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses#sources +// PAGE: https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses#user-location // GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start #pragma warning disable OPENAI001 From 6b65a2527756eb53e26d327aef44081e7989de48 Mon Sep 17 00:00:00 2001 From: Christopher Scott Date: Wed, 1 Oct 2025 11:34:29 -0500 Subject: [PATCH 3/3] Update docs/guides/tools-web-search/responses/user-location.cs --- docs/guides/tools-web-search/responses/user-location.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/tools-web-search/responses/user-location.cs b/docs/guides/tools-web-search/responses/user-location.cs index f191b08ff..b087e00f6 100644 --- a/docs/guides/tools-web-search/responses/user-location.cs +++ b/docs/guides/tools-web-search/responses/user-location.cs @@ -16,14 +16,14 @@ userLocation: WebSearchToolLocation.CreateApproximateLocation( country: "GB", city: "London", - region: "London" + region: "Granary Square" ) )); OpenAIResponse response = (OpenAIResponse)client.CreateResponse([ ResponseItem.CreateUserMessageItem([ ResponseContentPart.CreateInputTextPart( - "What are the best restaurants around Granary Square?" + "What are the best restaurants near me?" ) ]) ], options);