I tried to create a page via the API without a name and it displayed an error saying the name had to be set. This is my solution based off of the the code Wanze posted.
/*
* Clean URL
*/
function clean_string($string)
{
return trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-');
}
/*
* Check for duplicate name
*/
function check_name ($title, $path) {
$parent_page = wire("pages")->get($path);
$n = 0;
$pageName = strtolower(clean_string($title));
do {
$name = $pageName . ($n ? "-$n" : '');
$child = $parent_page->child("name=$name"); // see if another page already has the same name
$n++;
} while($child->id);
return $name;
}