Get startedGet started for free

Response Items: The Building Blocks

1. Response Items: The Building Blocks

Welcome back!

2. The Journey

In the last chapter, you mastered creating Responses API requests to

3. The Journey

prompt OpenAI models,

4. The Journey

experimented with different model parameters to optimize for quality, cost, and length, and even

5. The Journey

built a system to support a back-and-forth conversation with response IDs. In this chapter, we'll lay the groundwork for integrating tools with LLMs, which enable LLM-based systems to go beyond what the underlying models are trained to do. To enable this, we'll need to dive deeper into the response output items.

6. Your Item Toolbox

Recall that output items are found under the response's .output attribute. So far, we've only encountered two different item types. The first is a 'reasoning' item, returned for any reasoning-enabled models. If a reasoning summary was requested, it will be available through the item's summary attribute. The other item type is 'message', which contains the final output from the model under the .content attribute. As well as the text, there are useful metadata found here, including the status, which tells us whether the message was cut-off due to the model hitting a token limit. Because the status is incomplete, that happened in this case.

7. Items as Building Blocks

The beauty of using these items is that we have a predictable way of processing different item types. For example, we can loop over the items, add conditions for particular item types, dig into item attributes to create custom logic, and add extra logging based on this information.

8. Items as Building Blocks

If we want to return the reasoning summaries alongside the output text, we can loop of the items, check for reasoning items, validate that the summary is not empty, and if not, return a nicely formatted string. Then, we can check for regular messages and return the .output_text attribute, so the reasoning summary always precedes it.

9. Coming up...

In the coming lessons, we'll encounter new item types returned by tools. The web search tool will return a particular item type, and the function-calling tools we'll create will use others. In both cases, the process is the same with the items we've just looked at: looping over the items, checking their types, and occasionally extracting particular attributes to add custom logic.

10. Let's practice!

Time to try this out to get familiar with this key building block!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.