Enhanced api.js