
Slice the onions thinly. Melt butter in a large pot over medium heat. Add the onions and cook slowly, stirring occasionally, for about 30-40 minutes, until deeply caramelized and golden brown.
Add flour to the caramelized onions and cook for 1 minute, stirring constantly.
Pour in beef broth and dry red wine (if using). Bring to a simmer and add bay leaf, thyme, salt, and pepper. Simmer for 20 minutes to allow the flavors to meld.
Preheat broiler. Ladle soup into oven-safe bowls. Top each bowl with a slice of baguette and a generous amount of Gruyère cheese.
Place the bowls under the broiler until the cheese is melted and bubbly, about 2-3 minutes.
Remove from broiler and let cool slightly before serving. Garnish with fresh thyme, if desired.
Serve immediately and enjoy the rich and comforting flavors of your homemade French Onion Soup.