This is the relevant documentation: https://platform.openai.com/docs/guides/structured-outputs#streaming
You can use streaming to process model responses or function call arguments as they are being generated, and parse them as structured data.
That way, you don’t have to wait for the entire response to complete before handling it. This is particularly useful if you would like to display JSON fields one by one, or handle function call arguments as soon as they are available.
We recommend relying on the SDKs to handle streaming with Structured Outputs.
Using the Agents SDK you can set output_type
of an Agent. So when you stream by token and print the deltas, you’ll see something like:
{“
field_1
“:”
value
“,”
field_2
“:”
value
…etc.
Can the SDK help stream token by token per field? Or you have to handle the parsing logic on the receiving end yourself?