[api] refactor to use serialize instead of as_dict