I recently published an article about generating initial avatars in PHP. In extension of that, I created a public and free API that does this for you.
It has most of the settings, fast response and is open source.
In the coming weeks, I will be tweaking and optimizing the API, as well as setting up load-balancing and servers across the world.
You can check it out at https://ui-avatars.com.