Move api package

Include #3800 commit.

Tests are all green.

WIP, please don't merge, but feel free to comment.