File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
docs/guides/images-vision/responses Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ // SAMPLE: Generate images with Responses API
2+ // PAGE: https://platform.openai.com/docs/guides/images-vision?api-mode=responses#generate-or-edit-images
3+ // GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4+ #pragma warning disable OPENAI001
5+
6+ #: package OpenAI @2 . *
7+ #: property PublishAot = false
8+
9+ using System. ClientModel ;
10+ using System . Text . Json ;
11+ using OpenAI . Responses ;
12+
13+ string key = Environment . GetEnvironmentVariable ( "OPENAI_API_KEY" ) ! ;
14+ OpenAIResponseClient client = new ( model : "gpt-image-1" , apiKey : key ) ;
15+
16+ OpenAIResponse response = ( OpenAIResponse ) client . CreateResponse (
17+ BinaryContent . Create ( BinaryData . FromObjectAsJson ( new
18+ {
19+ model = "gpt-4.1" ,
20+ input = "Generate an image of gray tabby cat hugging an otter with an orange scarf" ,
21+ tools = new [ ]
22+ {
23+ new
24+ {
25+ type = "image_generation"
26+ }
27+ }
28+ }
29+ ) )
30+ ) ;
31+
32+ var serialised = JsonSerializer . Serialize ( response . OutputItems ) ;
33+
34+ Console . WriteLine ( serialised ) ;
You can’t perform that action at this time.
0 commit comments