Preheat the oven to 350 degrees F. Spray 2 baking sheets with non-stick cooking spray or line with parchment or a silpat.
Sift together the flour, cocoa, tapioca starch, xanthan gum (if using), baking soda and salt. Cream the butter and sugar, add the eggs and vanilla in slowly until smooth. On a low speed, add the flour mixture, until incorporated - the batter will be quite thick. Scrape the side of the mixing bowl then pour the buttermilk in slowly down the side of the mixing bowl. Increase speed to medium to incorporate.
For larger whoopie pies, as pictured, divide the batter into 24 equal portions. (The batter is extremely sticky and elastic, I recommend using an ice cream or portion control scoop with a release grip). Smaller scoops may be used for smaller pies. Wet your fingers and flatten the mounds of dough ever so slightly, to help the batter spread while baking.
Bake the larger size for about 15 to 18 minutes, the smaller size for about 11 minutes. They should be set but still somewhat soft when pressed with a finger. Allow to cool on a rack before filling.
While the cakes are cooling, make the filing. Cream the butter, half the powdered sugar and vanilla until smooth, then add the remaining powdered sugar - it will be quite thick. Add the milk, a tablespoon at a time, until you have a smooth, spreadable consistency. You may need more or less milk, and if the filling becomes to liquid to spread, add in more powdered sugar to firm it up. (This recipe makes a little more than you will need but is the smallest amount that blends well.)
Use a pastry bag, ice cream scoop or simply spoon the filling between half of the cakes and then top with the remaining cakes. Keep covered at room temperature for up to 5 days.