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?
The OpenAI SDK itself does not provide per-field streaming. If you are using Python, LangDiff (globalaiplatform/langdiff at GitHub) will be helpful. It parses a streaming structured output and then triggers per-field change handlers token by token.
That informs that even if you are buffering any ol’ arbitrary stream, you’d need a clever parser meant to deliver just key/value, which for nested JSON, likely means delivering complete root objects.
(this forum btw fails by translating that emoji into multiple shortcodes.)