Melt the butter. Lay out 1 sheet of phyllo and brush with clarified butter. Lay another phyllo sheet on top and repeat until you have 6 layers of buttered phyllo sheets.
Cut 4 of the 6 tomatoes into 1/4-inch thick slices and remove seeds. Place tomatoes in a single layer on paper towels. Sprinkle with 1 tsp salt. Let stand 30 minutes.
Preheat oven to 425F (220C). Stir together cheddar, gruyere, mayonnaise, eggs, sugar, salt and black pepper in a large bowl until combined.
Pat tomato slices dry with a paper towel. Sprinkle tapioca over the bottom of the crust. Lightly spread 1/2 cup of the cheese mixture onto the crust. Layer with half of the tomato slices in slightly overlapping rows.
Spread paper-thin red onions and basil leaves evenly. Then spread on another 1/2 cup of the cheese mixture.
Repeat layers, using the remaining tomato slices, red onions, basil leaves and cheese mixture. Cut the remaining 2 tomatoes into 1/4-inch thick slices and arrange on top of the pie.
Bake at 425F (220C) for 30-35 minutes, shielding the edges with foil during the last 20 minutes to prevent excessive browning. Let stand 1-2 hours before serving.
Serve pie with herb salad dressed in apple cider vinegar and olive oil.