Ruby Gems and APIs are both useful for expanding capabilities of a given program.
A Ruby Gem is a piece of code or files that a user has packaged for distribution and use for all other Ruby users. It serves a specific purpose (or related group of purposes) and is written by Ruby users. It can be continually updated and collaborated on. Gems are available on a public hub (Ruby Gems) for all Ruby users.
APIs are raw code output. They're the pure data without any wrapping/formatting of any kind. Programs build user interfaces on the APIs to make them user-friendly. This can be done using a gem, if someone has created a gem for this purpose. Gems don't require authentication or access, while APIs do, because APIs are often producing large amounts of data that's being used to run/build a program.