When to add spices when cooking depends on the type of spice and the recipe you are making. Here are some general guidelines:
Dry spices: Dry spices, such as cumin, paprika, and chili powder, should be added early in the cooking process so that they have time to release their flavors. Add them to the hot oil in the pan or pot and cook for 30 seconds to a minute before adding other ingredients.
Fresh herbs: Fresh herbs, such as basil, thyme, and parsley, should be added towards the end of the cooking process so that they retain their freshness and flavor. Add them in the last few minutes of cooking or sprinkle them on top of the dish just before serving.
Ground spices: Ground spices, such as cinnamon and nutmeg, should be added sparingly and towards the end of the cooking process. They can quickly overpower a dish, so start with a small amount and add more as needed.
Whole spices: Whole spices, such as cloves, bay leaves, and peppercorns, should be added early in the cooking process so that they have time to release their flavors. They can be added to the pot or pan whole and removed before serving.
Remember that adding spices is a matter of personal taste, so feel free to experiment with when and how much to add. However, it's important to follow the recipe closely, especially if you are not familiar with the dish, to ensure that the flavors are balanced and the dish turns out as intended.