openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/modify-responsesclient-default-model

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/quickstart/responses/analyze_images_files_file_url.cs

26lines · modecode

1// SAMPLE: Analyzes file from a file URL through Responses API
2// PAGE: https://platform.openai.com/docs/quickstart?input-type=file-url#analyze-images-and-files
3// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4#pragma warning disable OPENAI001
5
6#:package OpenAI@2.*
7
8using OpenAI.Files;
9using OpenAI.Responses;
10
11string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
12ResponsesClient client = new(apiKey: key);
13
14using HttpClient http = new();
15using Stream stream = await http.GetStreamAsync("https://www.berkshirehathaway.com/letters/2024ltr.pdf");
16OpenAIFileClient files = new(key);
17OpenAIFile file = files.UploadFile(stream, "2024ltr.pdf", FileUploadPurpose.UserData);
18
19ResponseResult response = client.CreateResponse("gpt-5.2", [
20 ResponseItem.CreateUserMessageItem([
21 ResponseContentPart.CreateInputTextPart("Analyze the letter and provide a summary of the key points."),
22 ResponseContentPart.CreateInputFilePart(file.Id)
23 ])
24]);
25
26Console.WriteLine(response.GetOutputText());