Initial split of internal and external api types.

Not sure, this isn't new code, it's just a fork of existing code that @lavalamp wrote.