Melt the butter in a large, heavy-based saucepan over a medium heat. Add the onions, thyme leaves, star anise and some black pepper stirring well to coat in the butter. Reduce the heat and cook gently over a low heat for 15-20 minutes until the onions start to caramelize and darken, stirring occasionally. Add the stock and bring to the boil. Reduce to a simmer and cook gently for 10-15 minutes.
Meanwhile, pre-heat the grill to hot and lightly toast the baguette slices. Adjust the seasoning of the soup if necessary, then ladle into soup bowls. Top with the lightly toasted slices of baguette, then sprinkle the cheese and ground spices on top. Glaze under the grill for a couple of minutes until the cheese has melted.
Remove carefully from the grill using oven gloves. Serve immediately on side plates.