-: Okay, so in this video we're gonna have a look
at the chat completions endpoint
versus the responses API endpoint.
What I want you to do is open
the chat_completions_vs_ responses_api notebook.
And we're just gonna run this
and have a look at the differences.
So the main thing is that you've got this .create method,
and it's happening on both
either the chat.completions part of OpenAI,
or it's happening on the responses part of OpenAI.
Now, if you go and have a look at the differences,
the state management for chat completions
is you have a messages array or a Python list.
And in every call it's completely stateless.
You have to manually add the previous messages.
In the responses API, by default,
it is a stateful back service.
So OpenAI will hold your messages
and you just have to use the previous response ID
inside of that.
But remember, we also overcame that
by setting the stories equal to false
to make the response's API endpoint stateless.
And then we manually optimize the message history
so we could do custom things like token counting.
The chat completions endpoint provides a messages array
and you have to extract that with this choices list,
with the responses API,
you don't have an input for the messages,
it's just the input parameter.
So the responses API is designed for building agents
and will replace the current assistance API,
and it offers a smoother development experience
by holding the chat context between turns.
If we're looking at a minimal example,
and I'm gonna basically just explain through this code
so you can see what's happening.
So you've got OpenAI, we've got that gpt-4.1-mini,
and then we're setting up a client,
in the client.chat.completions.create,
everything is saying from the model's perspective,
but we have this messages argument
and we paste our messages in here,
and then, you know, when we want to then add those
to extract the messages before we do responses.choices
and get this first one out, .message.content.
Then we can create a follow-up request
where we pass in the original conversation
plus our additional message as well.
Tell me another joke.
And then we can also get the messages from here
via that .choices[0].message.content.
If we look at the responses API like we have before,
you've got rid of the messages argument here
for the .create, and we've replaced it with input,
but the item is basically the same.
It can either be a textual string, like as a prompt,
or it can be a list of messages.
We also have the previous response ID
where basically we don't have to manually save the state
of the message history,
we're just using that previous response ID.
So just to summarize with the chat completions API endpoint,
you manually have to handle the conversation state,
and it uses the messages parameter
and returns an output under the choices messages.content.
With the responses API,
you don't have to manage message history
unless you want to,
and uses the input parameter
and returns the aggregated output
as the .output_text property.
Cool. All right, I'll see you in the next video.