What does an API do?
MDN describes an API as a set of features and rules inside an application that lets other software interact with it, as opposed to a human user interface [1]. You can think of it as a simple contract between the application offering it and whatever uses it [1]. On the web, that contract is usually made of methods, properties, events and URLs [1].
MDN's introductory guide compares an API to a plug socket. To use an appliance you plug it in; you don't wire it straight into the mains [2]. An API works the same way, hiding complex code behind a simpler syntax [2].
What kinds of API are there?
Browser APIs are built into the browser and expose data from the browser and the surrounding computer. The Web Audio API, for instance, lets code take an audio track, change its volume or apply effects to it [2]. Third-party APIs don't ship with the browser; you fetch their code and information from somewhere on the web [2].
The two kinds often work together. The Geolocation API reads the user's position from services on the device, such as GPS, and that position can be passed to the Google Maps APIs to plot the user on a custom map alongside nearby attractions [1].
How is an API different from a user interface?
A person uses a user interface; a program uses an API [1]. The same application can offer both. What an API gives a developer is the ability to add complex functionality to their own app without writing it from scratch [2].