Caramelize the onions: In a large heavy pot over medium heat, melt the butter with the olive oil. Add onions, salt, pepper, and sugar (if using).
Cook, stirring every few minutes, until deeply golden and jammy, 35–45 minutes. Adjust heat to prevent burning; a little fond on the bottom is good—scrape it up as you go.
Add aromatics: Stir in the garlic and cook 30 seconds until fragrant. Sprinkle in the flour and cook 1 minute, stirring, to remove the raw taste.
Deglaze: Pour in the wine or sherry.
Scrape up browned bits and simmer until mostly evaporated, 2–3 minutes.
Simmer the soup: Add stock, soy sauce or Worcestershire, thyme, and bay leaf. Bring to a gentle simmer and cook 15–20 minutes. Taste and adjust seasoning with salt and pepper.
Remove the bay leaf.
Prep the air fryer: Preheat your air fryer to 375°F (190°C) for 3 minutes.
Toast the bread: Arrange baguette slices in the air fryer basket in a single layer. Air fry 3–4 minutes per side until crisp and lightly golden. Set aside.
Ladle and top: Divide hot soup among oven-safe ramekins or small soup crocks that fit your air fryer.
Place 1–2 toasted baguette slices on each. Top generously with Gruyère and a sprinkle of Parmesan if using. Press cheese to the edges to create a seal.
Air-fry the gratin: Carefully set the filled crocks in the air fryer basket.
Air fry at 375°F (190°C) for 4–6 minutes until the cheese is melted, bubbling, and browned in spots. Work in batches if needed.
Rest and serve: Let the crocks sit 2–3 minutes (they’re molten hot). Serve with extra toast on the side.