It has been pointed out that a public API is public, however there are some steps that could take to make it more difficult for consumers other than your UI to access it.  
The problem is akin (though not the same as) Cross Site Request Forgery, and you can use a variation of any of the prevention techniques listed to mitigate unauthorized access to your API.
The simplest implementation might be something like this:
index.html
<?php 
    $mytoken = uniqid();
    $_SESSION['token'] = $mytoken;
?>
<input type='hidden' name='apitoken' value='<?= $mytoken;?>' >
some-api-endpoint.php
<?php
    if($_GET['apitoken'] !== $_SESSION['token']) {
        header("HTTP/1.0 403 Forbidden", true, 403);
    }
If someone wants to access your public API, they will be able to, but they will have to put forth at least a little bit of effort to do so.