Update api.py

Get rid of redundant code.