difference between library and API :

A library is a collection of functions / objects that serves one particular purpose. 
you could use a library in a variety of projects. (Various specialized services in our case).

An API is an interface for other programs to interact with your program or library  without having direct access.
( giving specifications for our need to various vendors in our case).

Example:

lib :JQuery library, is a library of prewritten, cross-browser Javascript animations and functions which you will need while making a website. 

Api:Google Map APIs you can show maps for different places without writing/hosting the whole code on your server, and just use it, usually this
 data transfer is in form of JSON i.e JavaScript Object Notation.