You use API routes when you want to expose the data via the /API route. This might be useful when there are other apps outside of your current project that want to interact with the server.
If not, you should use server actions.