01 - Preheat oven to 375°F. Generously grease a 9x13-inch baking dish with butter or cooking spray.
02 - Melt 2 tablespoons butter in a large skillet over medium heat. Add sliced onions with a pinch of salt. Cook, stirring frequently, for 20-25 minutes until deeply golden and caramelized. Add minced garlic during the final minute.
03 - In a small saucepan, combine heavy cream, whole milk, thyme, nutmeg, black pepper, and remaining 1 tablespoon butter. Heat over medium-low until steaming, not boiling. If using flour, whisk until smooth and slightly thickened.
04 - Arrange half the sweet potato slices in the prepared dish. Season lightly with salt. Spread half the caramelized onions over potatoes, then sprinkle with half the Gruyère and cheddar.
05 - Repeat with remaining sweet potatoes, caramelized onions, and cheese blend. Pour the warm cream mixture evenly over all layers.
06 - Cover dish tightly with aluminum foil. Bake for 40 minutes to steam and soften potatoes.
07 - Remove foil and continue baking uncovered for 20 minutes until top is golden brown and potatoes are fork-tender.
08 - Let gratin rest for 10 minutes before serving to set. Garnish with fresh chives if desired.