How do I get URL links to open in a new window when generated by Open AI API?

I have the API-generating links to relevant resources. How do I get these links to open in a new window when using the API?

Links generated in ChatGPT open in a new window by default. How get the same behavior for links using the API?


Are you referring to the API Playground? That behaviour isn’t related to the model or any prompt, it’s coded into the website itself.

You should be able to adjust your browser settings so it always open links in a new window though.


More specifically…

When I use ChatGPT or custom GPT and I get a link in the results it is formatted to open in a new window - a target=“_new”>

When I use the Open API in my production applicaion it is not set to open in a new window. The link HTML results are different and GPT -
a href=“Cluster Networking | Kubernetes”>Cluster Networking | Kubernetes

Is there some code or some prompt to get URL links generated from the API results to open in a new window?

When the link opens in the same window, it wipes out the results from the API, so the user can not use the back button, because everything is gone.

I think that depends on the code in your application a bit? How to you get from the API response to the HTML that shows up?
In that process you could make sure any href presented always has a target?

1 Like

It depends on how you’re getting the MD data from the API into HTML.
Usually adding on yout initial instructions that you’d like for links to open on a new tab will make GPT add {target="_blank"} at the end of the link, then it’s just a matter to use a parser that understands that.

1 Like

I second the same suggestions from @jlvanhulst and @yga

You can either adapt your instructions for creating links or run a postprocessing script to add the target=“_blank” which I would personally prefer.

The upside is that you can make sure the app always works as intended and you don’t have to spend extra model attention on this sub-task.