Caramelize the onions. Heat the butter and olive oil in a large skillet over medium-low heat. Add the onions, salt, pepper, sugar, garlic powder and thyme and mix. Cook for 40–50 minutes, stirring occasionally, until deeply golden and soft. If the pan starts to dry out or the onions stick, add a splash of water.
Add the flavor. Pour in the beef broth, scraping up any browned bits. Simmer for 3–5 minutes, until most of the liquid has cooked off and the onions are jammy.
Prep the potatoes. Preheat the oven to 375°F. Grease a 9×13-inch baking dish with nonstick cooking spray. In a large bowl, toss the sliced potatoes with the heavy cream, salt, pepper, and fresh thyme.
Layer the casserole. Arrange half the potatoes in overlapping layers in the baking dish. Spread half the onions over them and sprinkle with half the Gruyère. Repeat with the remaining potatoes, onions, and cheese. Pour any cream left in the bowl evenly over the top.
Bake covered. Cover tightly with foil and bake for 50–60 minutes, until the potatoes are nearly tender when pierced with a knife. If they’re still firm, cover and continue baking before moving to the next step.
Brown the top. Remove the foil and bake for another 15–20 minutes, until the potatoes are fully tender and the top is golden and bubbly. For extra browning, broil for 1–2 minutes, watching closely.
Rest and serve. Let rest for 10–15 minutes so the cream can thicken slightly. Garnish with fresh thyme, if using, and serve warm.