We measure the role of firm heterogeneity in counterfactual predictions of monopolistic competition trade models without parametric restrictions on the distribution of firm fundamentals. We show that two bilateral elasticity functions are sufficient to nonparametrically compute the counterfactual aggregate impact of trade shocks, and recover changes in economic fundamentals from observed data. These functions are identified from two semiparametric gravity equations governing the impact of bilateral trade costs on the extensive and intensive margins of firm-level exports. Applying our methodology, we estimate elasticity functions that imply an impact of trade costs on trade flows that falls when more firms serve a market because of smaller extensive margin responses. Compared to a baseline where elasticities are constant, firm heterogeneity amplifies both the gains from trade in countries with more exporter firms, and the welfare gains of European market integration in 2003-2012.