01 - Preheat oven to 375°F. Grease a 9x13-inch baking dish with butter or cooking spray.
02 - Melt 2 tbsp butter in a large skillet over medium heat. Add sliced onions with a pinch of salt. Cook, stirring frequently, until deeply golden and caramelized, about 20-25 minutes. Add minced garlic during the last minute and remove from heat.
03 - In a small saucepan, combine heavy cream, whole milk, dried thyme, ground nutmeg, black pepper, and remaining 1 tbsp butter. Heat over medium-low until steaming but not boiling. If thickening is desired, whisk in flour until smooth.
04 - Arrange half of the sweet potato slices in the prepared baking dish. Season lightly with salt, then spread half of the caramelized onions over the potatoes. Sprinkle with half of the Gruyère and cheddar cheese.
05 - Repeat layering with remaining sweet potatoes, caramelized onions, and cheese blend.
06 - Pour the warm cream mixture evenly over the layered ingredients, ensuring coverage across the entire dish.
07 - Cover baking dish tightly with aluminum foil. Bake for 40 minutes to allow potatoes to cook through.
08 - Remove foil and continue baking uncovered for 20 minutes, until top is golden brown and potatoes are fork-tender.
09 - Allow gratin to rest for 10 minutes before serving. Garnish with fresh chives if desired.