An application programming interface (API) is a collection of commands and protocols that programmers use to build software, allowing them to leverage predefined functions. An API key serves as a unique identifier and secret token for authentication, controlling access and usage of the API. Examples include the Google Maps API, which allows web developers to embed interactive maps without building them from scratch.