@@ -77,6 +77,7 @@ client = AzureOpenAI(
77
77
response = client.responses.create(
78
78
model = " gpt-4o" , # replace with your model deployment name
79
79
input = " This is a test."
80
+ # truncation="auto" required when using computer-use-preview model.
80
81
81
82
)
82
83
```
@@ -98,6 +99,7 @@ client = AzureOpenAI(
98
99
response = client.responses.create(
99
100
model = " gpt-4o" , # replace with your model deployment name
100
101
input = " This is a test."
102
+ # truncation="auto" required when using computer-use-preview model.
101
103
102
104
)
103
105
```
@@ -119,7 +121,7 @@ curl -X POST "https://YOUR-RESOURCE-NAME.openai.azure.com/openai/responses?api-v
119
121
### API Key
120
122
121
123
``` bash
122
- curl -X https://YOUR-RESOURCE-NAME.openai.azure.com/openai/responses? api-version=2025-03-01-preview \
124
+ curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/responses? api-version=2025-03-01-preview \
123
125
-H " Content-Type: application/json" \
124
126
-H " api-key: $AZURE_OPENAI_API_KEY " \
125
127
-d ' {
@@ -315,9 +317,9 @@ client = AzureOpenAI(
315
317
api_version = " 2025-03-01-preview"
316
318
)
317
319
318
- response = client.responses.del (" resp_67cb61fa3a448190bcf2c42d96f0d1a8" )
320
+ response = client.responses.delete (" resp_67cb61fa3a448190bcf2c42d96f0d1a8" )
319
321
320
- print (response.model_dump_json( indent = 2 ) )
322
+ print (response)
321
323
```
322
324
323
325
## Chaining responses together
@@ -509,3 +511,134 @@ second_response = client.responses.create(
509
511
print (second_response.model_dump_json(indent = 2 ))
510
512
511
513
```
514
+
515
+ ## List input items
516
+
517
+ ``` python
518
+ from openai import AzureOpenAI
519
+ from azure.identity import DefaultAzureCredential, get_bearer_token_provider
520
+
521
+ token_provider = get_bearer_token_provider(
522
+ DefaultAzureCredential(), " https://cognitiveservices.azure.com/.default"
523
+ )
524
+
525
+ client = AzureOpenAI(
526
+ azure_endpoint = os.getenv(" AZURE_OPENAI_ENDPOINT" ),
527
+ azure_ad_token_provider = token_provider,
528
+ api_version = " 2025-03-01-preview"
529
+ )
530
+
531
+ response = client.responses.input_items.list(" resp_67d856fcfba0819081fd3cffee2aa1c0" )
532
+
533
+ print (response.model_dump_json(indent = 2 ))
534
+ ```
535
+
536
+ ** Output:**
537
+
538
+ ``` json
539
+ {
540
+ "data" : [
541
+ {
542
+ "id" : " msg_67d856fcfc1c8190ad3102fc01994c5f" ,
543
+ "content" : [
544
+ {
545
+ "text" : " This is a test." ,
546
+ "type" : " input_text"
547
+ }
548
+ ],
549
+ "role" : " user" ,
550
+ "status" : " completed" ,
551
+ "type" : " message"
552
+ }
553
+ ],
554
+ "has_more" : false ,
555
+ "object" : " list" ,
556
+ "first_id" : " msg_67d856fcfc1c8190ad3102fc01994c5f" ,
557
+ "last_id" : " msg_67d856fcfc1c8190ad3102fc01994c5f"
558
+ }
559
+ ```
560
+
561
+ ## Image input
562
+
563
+ ### Image url
564
+
565
+ ``` python
566
+ from openai import AzureOpenAI
567
+ from azure.identity import DefaultAzureCredential, get_bearer_token_provider
568
+
569
+ token_provider = get_bearer_token_provider(
570
+ DefaultAzureCredential(), " https://cognitiveservices.azure.com/.default"
571
+ )
572
+
573
+ client = AzureOpenAI(
574
+ azure_endpoint = os.getenv(" AZURE_OPENAI_ENDPOINT" ),
575
+ azure_ad_token_provider = token_provider,
576
+ api_version = " 2025-03-01-preview"
577
+ )
578
+
579
+ response = client.responses.create(
580
+ model = " gpt-4o" ,
581
+ input = [
582
+ {
583
+ " role" : " user" ,
584
+ " content" : [
585
+ { " type" : " input_text" , " text" : " what is in this image?" },
586
+ {
587
+ " type" : " input_image" ,
588
+ " image_url" : " <image_URL>"
589
+ }
590
+ ]
591
+ }
592
+ ]
593
+ )
594
+
595
+ print (response)
596
+
597
+ ```
598
+
599
+ ### Base64 encoded image
600
+
601
+ ``` python
602
+ import base64
603
+ from openai import AzureOpenAI
604
+ from azure.identity import DefaultAzureCredential, get_bearer_token_provider
605
+
606
+ token_provider = get_bearer_token_provider(
607
+ DefaultAzureCredential(), " https://cognitiveservices.azure.com/.default"
608
+ )
609
+
610
+ client = AzureOpenAI(
611
+ azure_endpoint = os.getenv(" AZURE_OPENAI_ENDPOINT" ),
612
+ azure_ad_token_provider = token_provider,
613
+ api_version = " 2025-03-01-preview"
614
+ )
615
+
616
+ def encode_image (image_path ):
617
+ with open (image_path, " rb" ) as image_file:
618
+ return base64.b64encode(image_file.read()).decode(" utf-8" )
619
+
620
+ # Path to your image
621
+ image_path = " path_to_your_image.jpg"
622
+
623
+ # Getting the Base64 string
624
+ base64_image = encode_image(image_path)
625
+
626
+ response = client.responses.create(
627
+ model = " gpt-4o" ,
628
+ input = [
629
+ {
630
+ " role" : " user" ,
631
+ " content" : [
632
+ { " type" : " input_text" , " text" : " what is in this image?" },
633
+ {
634
+ " type" : " input_image" ,
635
+ " image_url" : f " data:image/jpeg;base64, { base64_image} "
636
+ }
637
+ ]
638
+ }
639
+ ]
640
+ )
641
+
642
+ print (response)
643
+ ```
644
+
0 commit comments