Working with the OpenAI Responses API
James Chapman
AI Curriculum Manager, DataCamp


| Event Type | Description |
|---|---|
response.created |
The model has started generating |
response.output_text.delta |
Partial text update |
response.output_text.done |
Text block complete |
response.function_call.arguments.delta |
Streaming tool arguments |
response.completed |
The entire response is finished |
prompt = "Explain the seasons of the year concisely to a child."with client.responses.create(model="gpt-5-mini", input=prompt, stream=True) as stream:current_text = ""for event in stream: if event.type == "response.output_text.delta":current_text += event.delta print(current_text)

prompt = "Explain how a neural network learns concisely for a child." with client.responses.create(model="gpt-5-mini", input=prompt, stream=True) as stream:for event in stream: if event.type == "response.created":print("Response started...\n")elif event.type == "response.output_text.done":print("\n\n--- Text block finished ---\n")elif event.type == "response.completed":print(f"\nFull response:\n{current_text}")

convert_currency() -> str:
date_time: strfrom_timezone: strto_timezone: strtools = [
{
"type": "function",
"name": "convert_currency",
...
}
]

prompt = "How much is 120 euros in British pounds using the current exchange rate?"with client.responses.create(model="gpt-5-mini", input=prompt, tools=tools, stream=True) as stream:current_args = ""for event in stream: if event.type == "response.function_call_arguments.delta":current_args += event.delta print("Streaming args:", current_args)elif event.type == "response.function_call_arguments.done":print("\nFinal arguments:", event.arguments)elif event.type == "response.completed":print("\n--- Completed ---")


Working with the OpenAI Responses API