The API code must go into an event. It could go into page load, button click, a checkbox being checked.
could create a user control with a button that creates a page (using
the Sitefinity API), upload the user control to Sitefinity, and place
it on a page. Take a look at the User Manual
and the Uploading Controls
section for more info. You could also make a master page with a button,
for example, that executes making a page. Take a look at this article
on working with master pages
for more info. Furthermore, you could just create a .aspx page in
Visual Studio and link it to Sitefinity. Look at Adding External Pages
in that User Manual I mentioned before for more info.