More work on the API

The basic API is (slowly) coming together.  It's complex enough that
this will unfortunately just take a while to get completed.