When using the OpenAI API, the official recommendation
in the official OpenAI documentation is to use its
Responses API. So when using the OpenAI
package, you wanna use this Responses object on the
client to create responses with the AI.
You can see that throughout the entire OpenAI documentation.
It's this more modern way of using the API you wanna
use. Now, since this is a bit more modern, chances are that
when you're following along, this method might not be used.
And for me here, it did use the older approach using the
which will also work, but which does not follow the recommendations
official documentation and which does not support all the features
OpenAI's API has to offer. So I wanna switch.
And of course, we could make those tweaks manually,
would probably be faster in this case, because it simply means that
we say
client.responses.create and we replace messages
with input and just pass our prompt as the text for
that. But for demo purposes, I'll not do it manually and I'll
instead use AI, because I wanna dive
into providing context to Cursor.
And for that, I'll open a new chat so that we have a
brand new context window. So all the information from
the other chat is lost now in this new chat.
And I now want to instruct Cursor to convert
this code to use the new Responses API.
And for that, we'll do some more advanced context
And I'll say instead of using the Completions API,
I mean, which we're currently using, we should use the more modern Responses
API. However, this is an instruction that can
be improved. First of all, when specifying a
file name like this, chances are very high that Cursor will find
it. Nonetheless, to be sure that it knows what you're talking
about, a better way of referencing a file in this
chat is to type @ and then this window for adding
context will open. Another way of getting there
this add button here. Now,
when you click that, though the advantage of
using the add key is that you can control where it will be
when you use that, you'll have different kinds of context
added. First, you will typically see some files here,
type, this also gets filtered. But besides
files, you can also reference documentation
Cursor or terminal sessions, different code from
other branches, or you could tell it to use the web
Here, I wanna use the main.py file and therefore I'll click on it,
will do is it will load the content of that file into this
chat session and also add a clear reference to this
file, so that in cases where you would have
main.py files in the same project, for example, you could make it very
clear to which exact file you're referring.
So whenever you're adding some file reference in your
chat, you wanna do it like this instead of just
This will make sure that the right context
and Cursor knows what you're talking about.
Another problem is that this instruction down here
is not very clear. Since Cursor, or to be more
precise, the AI it's using, does not know about
this Responses API, otherwise it probably would have used it
already, this instruction won't be very helpful.
So what we could do here is we could write something
like, "Search the web to learn how to use the
Responses API," because Cursor has built-in
web search. You can see that in the Cursor settings under
Agents. There, if you scroll down,
under Context, you see the web search tool is enabled,
and it must be enabled in order to unlock web search.
You can then also turn on auto accept to make sure you're not getting asked
before Cursor plans to search. If that is turned off, Cursor will
ask you if it is allowed to proceed.
If you turn it on, it will automatically proceed.
So by adding this instruction, you could increase the chances of
Cursor doing the right thing, of searching the web for how to use
it. But since I already know how that usage should look
like, it's much better to just provide
So here I'll say, "Here's some example from the official
to use the Responses API." And then what I like to do is
I like adding some XML tags here, which is not strictly
required, but which can help with structuring your
very clear where an example starts and ends, for example.
So here I'll have OpenAI docs opening and closing XML
tags. And between those tags, I'll just paste
some text from the official documentation.
And actually here, I'll just click Copy page, which
see on some pages, which gives me that page content in Markdown.
If such a feature does not exist, we can also just copy and
paste. But here I'll click Copy page.
That gives me the Markdown, and if I paste it in there, that was now added
here. So now my message is a lot longer because now it includes
that complete extra example, which should be some
useful context. Again, we could now switch to plan mode, but I'll
actually run this in agent mode right away because my instruction should be pretty
clear here. And that is how we can add very specific
context, which AI usage in the end, as mentioned,
is all about. You wanna provide all the required
context and have very clear, specific instructions with
just the right context. You definitely also wanna avoid
providing too much context though.
Instead, it's really about picking and adding just the right
context, which is a skill you have to build over
But that is what will allow you to get great results out of tools
like Cursor. So here, of course, it was a very simple
edit and therefore it's already done.
Now, here it added some instructions and then further down below the
input, which is the content of the post, and
it did that because I shared the overall document where I don't just
have this simple example here, but also more
advanced examples where we have a split between some general
instructions, which would apply to the overall chat
building a chat, and then the specific input of the actual
currently needs to be processed. But for a utility tool like ours,
this is not really important. So I will actually keep this, but also
change the code a little bit and just use
input here
and remove this input key here and then edit this post
here and say, "Here's the article content," and
then just insert that content like this into
this string. That's not something you have to do,
do, of course. And then I'll add F here to
make sure this gets properly injected.
This is looking good and therefore we can now test
this.