Skip to content

Commit fe3319c

Browse files
committed
update
1 parent 5adf15a commit fe3319c

File tree

1 file changed

+90
-17
lines changed

1 file changed

+90
-17
lines changed

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

Lines changed: 90 additions & 17 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
@@ -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 ouput 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 is not 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:
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.

0 commit comments

Comments
 (0)