Trying to migrate from assistants to responses API - i understand that you grab the current response.id and pass it over to the next call as previous_response_id.
But how does it work if i am streaming? Shall i take the (first) chunk.id? Or still the response.id? Or anything else?
Struggling with getting that conversation memory running in streaming responses at the moment…
There is a ResponseCreatedEvent that gives the response_id
Perhaps this may help you visualize it:
stream = client.responses.create(
model="gpt-4.1-mini",
input=[
{
"role": "user",
"content": "How many s's are in the word 'mississippi'? Give me other words with the same amount of s's.",
},
],
stream=True,
)
events=[]
for event in stream:
events.append(event)
print(event.type, event)
if event.type=='response.completed':
print(f"usage: {event.response.usage}")
print(event.response.output_text)
It will output something like this:
response.created ResponseCreatedEvent(response=Response(id='resp_6820f0ecf2......, created_at=1746989292.0, ...
1 Like
More specifically and transparently, if you are using the RESTful API and receiving back your http subscription of server-sent events, this is what your data is going to look like after a library concatenates the underlying packet chunks.
event: response.created
data: {"type":"response.created","response":{"id":"resp_680147fafa","object":"response","created_at":1744914427,"status":"in_progress"...
event: response.in_progress
data: {"type":"response.in_progress","response":{"id":"resp_680147fafa","object":"response","created_at":1744914427,"status":"in_progress",...
event: response.output_item.added
data: {"type":"response.output_item.added","output_index":0,"item":{"id":"msg_680147fcabdifferent","type":"message",...
...
event: response.completed
data: {"type":"response.completed","response":{"id":"resp_680147fafa","object":"response","created_at":1744914427,"status":"completed","error":null,..
You get the response ID within 100 bytes, and then get it over and over, just like the other repetitive data, such as five copies of the assistant response by the time you’re done.