PIP has no public API and in fact a lot of effort was invested into explaining why it does not, even if again and again people are asking about, some brave one even using it and paying the cost.
Over the years I had few cases where I ended up doing a hacking ad-hoc module installation when I got an ImportError, very similar to the py2/py3 import approach. I am fully aware that this may and will not work for any case but it does still resolve a real life issue.
we generally won’t fix issues that are a result of using pip in an unsupported way.
Considering that the current maintainers even documented I see no chance of being able to do anything towards creating an API because that is not desired.
I kinda find the documentation on the subject bit contradictory because it starts reasoning why this is not good while saying that pip developers are not against the idea but few paragraphs later it does say that they close tickets as wont fix: mainly confirming that they are against. And that is what is really happening – at least I cannot complain that documentation is out of sync with real practices.
Adding a minimal API with tests on it should be quite easy but this could happen only if there
PS. CLI is not API, lets not try to fool ourselves. If we go this way, we can consider a web application an API as you can use selenium to automate it.