The API counts tokens if you’re using one of the models like text-davinci-003 or gpt-3.5-turbo. I believe ChatGPT does the same.
[Edit] Now I’m sure it counts tokens.