Fix bug in api.py