Update api.py

lots of changes