Chat API refactor and redesign