basically always apply. Some states have a minimum amount of info you must provide regardless, usually ones name.
You also have to follow any lawful requests, but the moment the cop talks to you, you can assume you are being "detained" and invoke your Miranda rights. If the cop indicates you are "not being detained." Then you should also say nothing and leave.
Of note, I am not a lawyer. This is just my amateur understanding.