Fork API types.

All tests pass (for now...)  Rebasing this PR is a _pain_
On a scale from 1-10, my preference for using api.Encode and not duplicating any of its logic rates about a 6.5. I'll leave it up to you whether that means you change it or not. :)