Skip to content

Commit 146f359

Browse files
Merge pull request #4275 from mrbullwinkle/mrb_04_22_2025_responses_api
[Azure OpenAI] Responses API updates
2 parents 5adf15a + 8056fac commit 146f359

File tree

1 file changed

+94
-21
lines changed

1 file changed

+94
-21
lines changed

articles/ai-services/openai/how-to/responses.md

Lines changed: 94 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to use Azure OpenAI's new stateful Responses API.
55
manager: nitinme
66
ms.service: azure-ai-openai
77
ms.topic: include
8-
ms.date: 03/21/2025
8+
ms.date: 04/23/2025
99
author: mrbullwinkle
1010
ms.author: mbullwin
1111
ms.custom: references_regions
@@ -56,9 +56,9 @@ Not every model is available in the regions supported by the responses API. Chec
5656
> - Structured outputs
5757
> - tool_choice
5858
> - image_url pointing to an internet address
59-
> - The web search tool is also not supported, and is not part of the `2025-03-01-preview` API.
59+
> - The web search tool is also not supported, and isn't part of the `2025-03-01-preview` API.
6060
>
61-
> There is also a known issue with vision performance when using the Responses API, particularly with OCR tasks. As a temporary workaround set image detail to `high`. This article will be updated once this issue is resolved and as any additional feature support is added.
61+
> There's also a known issue with vision performance when using the Responses API, particularly with OCR tasks. As a temporary workaround set image detail to `high`. This article will be updated once this issue is resolved and as any additional feature support is added.
6262
6363

6464
### Reference documentation
@@ -96,6 +96,16 @@ response = client.responses.create(
9696
input="This is a test."
9797
#truncation="auto" required when using computer-use-preview model.
9898

99+
response_id = response.id
100+
response_status = response.status
101+
102+
103+
print(f"\n Response ID: {response_id}")
104+
print(f"\n Response Status: {response_status}\n")
105+
106+
print(response.model_dump_json(indent=2))
107+
108+
99109
)
100110
```
101111

@@ -118,6 +128,15 @@ response = client.responses.create(
118128
input="This is a test."
119129
#truncation="auto" required when using computer-use-preview model.
120130

131+
response_id = response.id
132+
response_status = response.status
133+
134+
135+
print(f"\n Response ID: {response_id}")
136+
print(f"\n Response Status: {response_status}\n")
137+
138+
print(response.model_dump_json(indent=2))
139+
121140
)
122141
```
123142

@@ -152,57 +171,111 @@ curl -X POST https://YOUR-RESOURCE-NAME.openai.azure.com/openai/responses?api-ve
152171
**Output:**
153172

154173
```json
174+
Response ID: resp_680915b58140819085f4c55454402f3600400b1e6ec996fc
175+
176+
Response Status: completed
177+
155178
{
156-
"id": "resp_67cb32528d6881909eb2859a55e18a85",
157-
"created_at": 1741369938.0,
179+
"id": "resp_680915b58140819085f4c55454402f3600400b1e6ec996fc",
180+
"created_at": 1745425845.0,
158181
"error": null,
159182
"incomplete_details": null,
160183
"instructions": null,
161184
"metadata": {},
162-
"model": "gpt-4o-2024-08-06",
185+
"model": "gpt-4o",
163186
"object": "response",
164187
"output": [
165188
{
166-
"id": "msg_67cb3252cfac8190865744873aada798",
189+
"id": "msg_680915b5c8dc8190b21a72a55830fea900400b1e6ec996fc",
167190
"content": [
168191
{
169192
"annotations": [],
170-
"text": "Great! How can I help you today?",
193+
"text": "It looks like you're testing out how this works! How can I assist you today?",
171194
"type": "output_text"
172195
}
173196
],
174197
"role": "assistant",
175-
"status": null,
198+
"status": "completed",
176199
"type": "message"
177200
}
178201
],
179-
"output_text": "Great! How can I help you today?",
180-
"parallel_tool_calls": null,
202+
"parallel_tool_calls": true,
181203
"temperature": 1.0,
182-
"tool_choice": null,
204+
"tool_choice": "auto",
183205
"tools": [],
184206
"top_p": 1.0,
185207
"max_output_tokens": null,
186208
"previous_response_id": null,
187-
"reasoning": null,
209+
"reasoning": {
210+
"effort": null,
211+
"generate_summary": null,
212+
"summary": null
213+
},
214+
"service_tier": null,
188215
"status": "completed",
189-
"text": null,
190-
"truncation": null,
216+
"text": {
217+
"format": {
218+
"type": "text"
219+
}
220+
},
221+
"truncation": "disabled",
191222
"usage": {
192-
"input_tokens": 20,
193-
"output_tokens": 11,
223+
"input_tokens": 12,
224+
"input_tokens_details": {
225+
"cached_tokens": 0
226+
},
227+
"output_tokens": 18,
194228
"output_tokens_details": {
195229
"reasoning_tokens": 0
196230
},
197-
"total_tokens": 31
231+
"total_tokens": 30
198232
},
199233
"user": null,
200-
"reasoning_effort": null
234+
"store": true
201235
}
202236
```
203237

204238
---
205239

240+
Unlike the chat completions API, the responses API is asynchronous. More complex requests may not be completed by the time that an initial response is returned by the API. This is similar to how the Assistants API handles [thread/run status](/azure/ai-services/openai/how-to/assistant#retrieve-thread-status).
241+
242+
Note in the response output that the response object contains a `status` which can be monitored to determine when the response is finally complete. `status` can contain a value of `completed`, `failed`, `in_progress`, or `incomplete`.
243+
244+
### Retrieve an individual response status
245+
246+
In the previous Python examples we created a variable `response_id` and set it equal to the `response.id` of our `client.response.create()` call. We can then pass client.response.retrieve() to pull the current status of our response.
247+
248+
```python
249+
250+
retrieve_response = client.responses.retrieve(response_id)
251+
print(retrieve_response.status)
252+
```
253+
254+
### Monitor response status
255+
256+
Depending on the complexity of your request it isn't uncommon to have an initial response with a status of `in_progress` with message output not yet generated. In that case you can create a loop to monitor the status of the response with code. The example below is for demonstration purposes only and is intended to be run in a Jupyter notebook. This code assumes you have already run the two previous Python examples and the Azure OpenAI client as well as `retrieve_response` have already been defined:
257+
258+
```python
259+
import time
260+
from IPython.display import clear_output
261+
262+
start_time = time.time()
263+
264+
status = retrieve_response.status
265+
266+
while status not in ["completed", "failed", "incomplete"]:
267+
time.sleep(5)
268+
retrieve_response = client.responses.retrieve(response_id)
269+
print("Elapsed time: {} minutes {} seconds".format(int((time.time() - start_time) // 60), int((time.time() - start_time) % 60)))
270+
status = retrieve_response.status
271+
print(f'Status: {status}')
272+
clear_output(wait=True)
273+
274+
print(f'Status: {status}')
275+
print("Elapsed time: {} minutes {} seconds".format(int((time.time() - start_time) // 60), int((time.time() - start_time) % 60)))
276+
print(retrieve_response.model_dump_json(indent=2))
277+
```
278+
206279
## Retrieve a response
207280

208281
To retrieve a response from a previous call to the responses API.
@@ -605,7 +678,7 @@ print(response.model_dump_json(indent=2))
605678

606679
## Image input
607680

608-
There is a known issue with image url based image input. Currently only base64 encoded images are supported.
681+
There's a known issue with image url based image input. Currently only base64 encoded images are supported.
609682

610683
### Image url
611684

@@ -885,7 +958,7 @@ async def take_screenshot(page):
885958
return last_successful_screenshot
886959
```
887960

888-
This function captures the current browser state as an image and returns it as a base64-encoded string, ready to be sent to the model. We'll constantly do this in a loop after each step allowing the model to see if the command it tried to execute was successful or not, which then allows it to adjust based on the contents of the screenshot. We could let the model decide if it needs to take a screenshot, but for simplicity we will force a screenshot to be taken for each iteration.
961+
This function captures the current browser state as an image and returns it as a base64-encoded string, ready to be sent to the model. We'll constantly do this in a loop after each step allowing the model to see if the command it tried to execute was successful or not, which then allows it to adjust based on the contents of the screenshot. We could let the model decide if it needs to take a screenshot, but for simplicity we'll force a screenshot to be taken for each iteration.
889962

890963
### Model response processing
891964

0 commit comments

Comments
 (0)